Kuva ELF-tiedoston rakenteesta. Program headerista osoittavat nuolet osoittavat segmenttejä ja section headerista ohjelman osioita.
Executable and Linkable Format lyhyesti ELF on yleinen tiedostomuoto suoritettaville ohjelmille , objektitiedostoille , jaetuille kirjastoille ja coredump -tiedostoille.[ 1] Rakenteeltaan ELF on joustava, laajennettavissa oleva ja alustariippumaton tiedostomuoto.
ELF on määritelty System V ABI -määrittelyssä[ 2] ja Tool Interface Standards (TIS) määrittelyssä: alkuperäisen ELF-muodon kehitti ja julkaisi Unix System Laboratories (USL).[ 3]
Tiedoston rakenne
ELF-tiedosto sisältää ELF-ylätunnisteen (engl. header ), joka muun muassa määrittää onko ohjelma 32 vai 64-bittinen . ELF-ylätunnisteen jälkeen tiedostossa on ohjelman ylätunnistetaulukko (engl. Program header table ), itse ohjelma ja viimeiseksi ohjelman osuuksien ylätunnistetaulukko (engl. Section header table ).[ 1]
00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 | .ELF............ |
00000010 02 00 3e 00 01 00 00 00 c5 48 40 00 00 00 00 00 | ..>......H@..... |
Esimerkki ELF-ylätunnisteen hexdumpista
[ 4]
ELF-ylätunniste
ELF-ylätunniste määrittää onko ohjelma 32- vai 64-bittinen. Bittisyys vaikuttaa tietueiden offsettiin .
ELF header[ 5]
Offset
Koko (tavuja)
Nimi
Kuvaus
32-bittinen
64-bittinen
32-bittinen
64-bittinen
0x00
4
e_ident[EI_MAG0] e_ident[EI_MAG3]
0x7F
ja 45 4c 46
(ELF) muodostavat maagisen numeron .
0x04
1
e_ident[EI_CLASS]
Tämä tavu on 1 jos kyseessä on 32-bittinen ohjelma tai jos 2 niin ohjelma on 64-bittinen.
0x05
1
e_ident[EI_DATA]
Määrittää ohjelman tavujärjestyksen .
0x06
1
e_ident[EI_VERSION]
Määrittää ELF-version. 1 tarkoittaa alkuperäistä.
0x07
1
e_ident[EI_OSABI]
Määrittää ohjelman ABI :n.
Usein määritetty nollaan riippumatta alustasta.
0x08
1
e_ident[EI_ABIVERSION]
Tarkempi määritys ABI:n versiosta.
0x09
7
e_ident[EI_PAD]
Toistaiseksi ei käytössä.
0x10
2
e_type
Määrittää objektin tyypin.
0x12
2
e_machine
Määrittää prosessoriarkkitehtuurin
0x14
4
e_version
Määrittää ELF-version. 1 tarkoittaa alkuperäistä.
0x18
4
8
e_entry
Määrittää osoitteen muistista, mistä ohjelman suoritus alkaa. Voi olla 32- tai 64-bittinen.
0x1C
0x20
4
8
e_phoff
Osoittaa ohjelman ylätunnistetaulukon alkuun.
0x20
0x28
4
8
e_shoff
Osoittaa osuuksien ylätunnistetaulukon alkuun.
0x24
0x30
4
e_flags
Kentän tulkinta riippuu kohdearkkitehtuurista.
0x28
0x34
2
e_ehsize
Sisältää ELF-ylätunnisteen koon.
0x2A
0x36
2
e_phentsize
Contains the size of a program header table entry.
0x2C
0x38
2
e_phnum
Sisältää osuuksien määrän ohjelman ylätunnistetaulukosta.
0x2E
0x3A
2
e_shentsize
Contains the size of a section header table entry.
0x30
0x3C
2
e_shnum
Sisältää osuuksen määrän osuuksien ylätunnistetaulukosta.
0x32
0x3E
2
e_shstrndx
Contains index of the section header table entry that contains the section names.
Ohjelman ylätunniste
Ohjelman ylätunnistetaulukko kertoo, kuinka ohjelma tulee ladata muistiin.
Program header[ 6]
Offset
Koko (tavuja)
Nimi
Kuvaus
32-bittinen
64-bittinen
32-bittinen
64-bittinen
0x00
4
p_type
Määrittää segmentin tyypin.
Value
Name
0x00000000
PT_NULL
0x00000001
PT_LOAD
0x00000002
PT_DYNAMIC
0x00000003
PT_INTERP
0x00000004
PT_NOTE
0x00000005
PT_SHLIB
0x00000006
PT_PHDR
0x60000000
PT_LOOS
0x6FFFFFFF
PT_HIOS
0x70000000
PT_LOPROC
0x7FFFFFFF
PT_HIPROC
PT_LOOS to PT_HIOS (PT_LOPROC to PT_HIPROC ) is an inclusive reserved ranges for operating system (processor) specific semantics.
0x04
4
p_flags
Segmentti kohtainen tietue.
0x04
0x08
4
8
p_offset
Segmentin offsetti.
0x08
0x10
4
8
p_vaddr
Segmentin virtuaalinen muistiosoite.
0x0C
0x18
4
8
p_paddr
Fyysinen muistiosoite
0x10
0x20
4
8
p_filesz
Segmentin koko.
0x14
0x28
4
8
p_memsz
Segmentin koko muistissa.
0x18
4
p_flags
Segmentti kohtainen tietue.
0x1C
0x30
4
8
p_align
0
and 1
specify no alignment. Otherwise should be a positive, integral power of 2, with p_vaddr equating p_offset modulus p_align .
0x20
0x38
Ohjelman ylätunnisteen loppu (koko).
Osion ylätunniste
Offset
Koko (Tavuja)
Nimi
Kuvaus
32-bittinen
64-bittinen
32-bittinen
64-bittinen
0x00
4
sh_name
An offset to a string in the .shstrtab section that represents the name of this section
0x04
4
sh_type
Identifies the type of this header.
Value
Name
Meaning
0x0
SHT_NULL
Section header table entry unused
0x1
SHT_PROGBITS
Program data
0x2
SHT_SYMTAB
Symbol table
0x3
SHT_STRTAB
String table
0x4
SHT_RELA
Relocation entries with addends
0x5
SHT_HASH
Symbol hash table
0x6
SHT_DYNAMIC
Dynamic linking information
0x7
SHT_NOTE
Notes
0x8
SHT_NOBITS
Program space with no data (bss)
0x9
SHT_REL
Relocation entries, no addends
0x0A
SHT_SHLIB
Reserved
0x0B
SHT_DYNSYM
Dynamic linker symbol table
0x0E
SHT_INIT_ARRAY
Array of constructors
0x0F
SHT_FINI_ARRAY
Array of destructors
0x10
SHT_PREINIT_ARRAY
Array of pre-constructors
0x11
SHT_GROUP
Section group
0x12
SHT_SYMTAB_SHNDX
Extended section indeces
0x13
SHT_NUM
Number of defined types.
0x60000000
SHT_LOOS
Start OS-specific.
...
...
...
0x08
4
8
sh_flags
Identifies the attributes of the section.
Value
Name
Meaning
0x1
SHF_WRITE
Writable
0x2
SHF_ALLOC
Occupies memory during execution
0x4
SHF_EXECINSTR
Executable
0x10
SHF_MERGE
Might be merged
0x20
SHF_STRINGS
Contains nul-terminated strings
0x40
SHF_INFO_LINK
'sh_info' contains SHT index
0x80
SHF_LINK_ORDER
Preserve order after combining
0x100
SHF_OS_NONCONFORMING
Non-standard OS specific handling required
0x200
SHF_GROUP
Section is member of a group
0x400
SHF_TLS
Section hold thread-local data
0x0ff00000
SHF_MASKOS
OS-specific
0xf0000000
SHF_MASKPROC
Processor-specific
0x4000000
SHF_ORDERED
Special ordering requirement (Solaris)
0x8000000
SHF_EXCLUDE
Section is excluded unless referenced or allocated (Solaris)
0x0C
0x10
4
8
sh_addr
Virtual address of the section in memory, for sections that are loaded.
0x10
0x18
4
8
sh_offset
Offset of the section in the file image.
0x14
0x20
4
8
sh_size
Size in bytes of the section in the file image. May be 0.
0x18
0x28
4
sh_link
Contains the section index of an associated section. This field is used for several purposes, depending on the type of section.
0x1C
0x2C
4
sh_info
Contains extra information about the section. This field is used for several purposes, depending on the type of section.
0x20
0x30
4
8
sh_addralign
Contains the required alignment of the section. This field must be a power of two.
0x24
0x38
4
8
sh_entsize
Contains the size, in bytes, of each entry, for sections that contain fixed-size entries. Otherwise, this field contains zero.
0x28
0x40
End of Section Header (size)
Käyttökohteet
Unixin kaltaiset alustat
ELF-muoto on korvannut vanhempia muotoja useilla alustoilla kuten a.out ja COFF -muodot Unixin kaltaisissa käyttöjärjestelmissä:
Ei-Unix -alustat
ELF on myös käytössä eräillä ei-Unix alustoilla kuten:
Pelikonsolit
Eräät pelikonsolit käyttävät ELF-muotoa:
PowerPC
Muut alustat PowerPC -suorittimilla jotka käyttävät ELF-muotoa:
Mobiililaitteet
Eräät käyttöjärjestelmät matkapuhelimille ja muille mobiililaitteille käyttävät ELF-muotoa:
Käännös suomeksi
Ohjelmia
readelf
ohjelma joka näyttää tietoa elf-tiedostoista.
elfutils
vaihtoehtoinen ohjelmapaketti GNU Binutilsin tilalle, joka on tehty erityisesti Linuxia varten.[ 18]
elfdump
ohjelma joka näyttää tietoa elf-tiedostosta.
objdump
ohjelma jolla voidaan tarkastella monipuolisesti eri tietoja elf-tiedostoista ja muista binääriformaateista.
file
ohjelma joka näyttää tietoa elf-tiedostoista.
Lähteet
Aiheesta muualla