ELF specification

ELF specification for MOS-compatible processors
This is version 0.1.2 of this specification. This specification uses semantic numbering to track changes.

Overview
This is a specification to extend the Executable and Linking Format (ELF) to encompass MOS family of processors and their relatives. These include, but are not limited to, the MOS 6502, the MOS 65816, and similar processors.

This draft considers the Tool Interface Standard (TIS), Executable and Linking Format (ELF) Specification, Version 1.2 to be normative.

Comments and improvements are solicited at johnwbyrd at gmail dot com.

Machine type field
The e_machine field shall have a constant name of EM_MOS. The constant of EM_MOS shall be set to 6502 (hexadecimal, 0x1966).

The e_flags field bits shall have the following meanings. These values may be logically OR'ed to indicate that multiple features are present.

Section flags
Each ELF section header contains a 32-bit word named sh_flags. For MOS-format ELF files, these flags have special meanings.

Relocation types
Relocations generally work as specified in the Relocations section of the ELF specification as described earlier. Each relocation entry in a MOS ELF file describes a particular MOS relocation. The lowest byte in the r_info field in an Elf32_Rel or Elf32_Rela relocation entry, is treated as a MOS-specific relocation type. (The ELF specification refers to this as the ELF32_R_TYPE macro.)

The exact types of MOS-specific relocations for ELF can be viewed in MOS.def as part of the llvm-mos distribution.

Although the ELF format encompasses 32-bit address types, it does not require them. MOS processors can access 16 bits by default and 24 bits at most. When an 8-bit, 16-bit, or 24-bit address is stored in a 32-bit ELF address type, the unused high bits should be zeroed.