SELF File Format

From Vita Developer wiki
Jump to navigation Jump to search


File Format

ELF Header

Struct

  typedef struct {
    uint8_t e_ident[16];              /* ELF identification */
    uint16_t e_type;                  /* object file type */
    uint16_t e_machine;               /* machine type */
    uint32_t e_version;               /* object file version */
    uint32_t e_entry;                 /* entry point address */
    uint32_t e_phoff;                 /* program header offset */
    uint32_t e_shoff;                 /* section header offset */
    uint32_t e_flags;                 /* processor-specific flags */
    uint16_t e_ehsize;                /* ELF header size */
    uint16_t e_phentsize;             /* size of program header entry */
    uint16_t e_phnum;                 /* number of program header entries */
    uint16_t e_shentsize;             /* size of section header entry */
    uint16_t e_shnum;                 /* number of section header entries */
    uint16_t e_shstrndx;              /* section name string table index */
  } __attribute__((packed)) ELF;

Table

Name of the variable Offset Size Notes
e_ident[0..3] elf_offset+(0,1,2,3) 4 Magic
e_ident[4] elf_offset+4 1 Class Type must be [ELFCLASS32 = 0x01]
e_ident[5] elf_offset+5 1 Data Type must be [ELFDATA2LSB (i.e. le) = 0x01]
e_ident[6] elf_offset+6 1 File version (must be 0x1)
e_ident[7..15] elf_offset+(6->15) 1 unused
e_type elf_offset+0x10 2 SCE-specific e_type
e_machine elf_offset+0x12 2 Machine type must be [EM_ARM = 0x0028]
e_version elf_offset+0x14 4 elf version (must be 0x00000001)
e_entry elf_offset+0x18 4 Address to jump to in order to start program
e_phoff elf_offset+0x1c 4 boundary checked, but unused (already given by SELF header)
e_shoff elf_offset+0x20 4 unused
e_flags elf_offset+0x24 4 unused
e_ehsize elf_offset+0x28 2 Must be sizeof(Elf32_Ehdr) = 0x0034
e_phentsize elf_offset+0x2a 2 Must be sizeof(Elf32_Phdr) = 0x0020
e_phnum elf_offset+0x2c 2 Count of Program Header in this elf
e_shentsize elf_offset+0x2e 2 unused
e_shnum elf_offset+0x30 2 unused
e_shstrndx elf_offset+0x32 2  unused

ELF Program Headers

Struct

  typedef struct {
    uint32_t p_type;                  /* type of segment */
    uint32_t p_flags;                 /* segment attributes */
    uint64_t p_offset;                /* offset in file */
    uint64_t p_vaddr;                 /* virtual address in memory */
    uint64_t p_paddr;                 /* reserved */
    uint64_t p_filesz;                /* size of segment in file */
    uint64_t p_memsz;                 /* size of segment in memory */
    uint64_t p_align;                 /* alignment of segment */
  } __attribute__((packed)) ELF_PHDR;

Table

Comments

See Spec here: ELF Program Headers

ELF Section Headers

Struct

  typedef struct {
    uint32_t sh_name;                 /* section name */
    uint32_t sh_type;                 /* section type */
    uint64_t sh_flags;                /* section attributes */
    uint64_t sh_addr;                 /* virtual address in memory */
    uint64_t sh_offset;               /* offset in file */
    uint64_t sh_size;                 /* size of section */
    uint32_t sh_link;                 /* link to other section */
    uint32_t sh_info;                 /* miscellaneous information */
    uint64_t sh_addralign;            /* address alignment boundary */
    uint64_t sh_entsize;              /* size of entries, if section has table */
  } __attribute__((packed)) ELF_SHDR;

Table

Comments