工具接口標準(TIS)可執行鏈接格式(ELF)規範版本 1.2
翻譯以中英對照方式,英語水平有限,如有翻譯不當的地方,請諒解。
ELF Header
ELF頭
Some object file control structures can grow, because the ELF header contains their actual sizes. If the object file format changes, a program may encounter control structures that are larger or smaller than expected. Programs might therefore ignore "extra"
information. The treatment of "missing" information depends on context and will be specified when and if extensions are defined.
一些對象文件控制結構能夠增長,因爲ELF頭包含了它們的實際大小。加入對象文件格式變換,程序會遇到比預期更大或更小的控制結構。程序可能會忽略這些額外信息。 “missing”信息的處理應該基於上下文,當定義了擴展信息的時候將被指定。
Figure1-3. ELF Header
圖1-3.ELF頭
#define EI_NIDENT 16
typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
} Elf32_Ehdr;
e_ident |
The initial bytes mark the file as an object file and provide machine-independent data with which to decode and interpret the file's contents. Complete descriptions appear below, in "ELF Identification.'' |
|||||||||||||||||||||||||||||||||
e_type |
This member identifies the object file type.
Although the core file contents are unspecified, type ET_CORE is reserved to mark the file type. Values from ET_LOPROC through ET_HIPROC(inclusive) are reserved for processor-specific semantics. Other values are reserved and will be assigned to new object file types as necessary. 其它值被保留並在必須的時候指定給新對象類型。 |
|||||||||||||||||||||||||||||||||
e_machine |
This member's value specifies the required architecture for an individual file. 此成員的值指定需求的架構。
Other values are reserved and will be assigned to new machines as necessary. Processor-specific ELF names use the machine name to distinguish them. For example, the flags mentioned below use the prefix EF_;a flag named WIDGET for the EM_XYZ machine would be called EF_XYZ_WIDGET. 比如,下面提到的標記使用EF_前綴,一個名爲WIDGET的標記在EM_XYZ的機器架構下被標識EF_XYZ_WIDGET |
|||||||||||||||||||||||||||||||||
e_version |
This member identifies the object file version.
The value 1 signifies the original file format; extensions will create new versions with higher numbers. The value of EV_CURRENT, though given as 1 above, will change as necessary to reflect the current version number. 值1表示初始文件格式的版本;擴展將創建新的版本號。在上面的表中EV_CURRENT雖然指定爲1, 但爲了反映當前版本號,在必要時將被修改。 |
|||||||||||||||||||||||||||||||||
e_entry |
This member gives the virtual address to which the system first transfers control, thus starting the process. If the file has no associated entry point, this member holds zero. 系統啓動進程時,轉換控制使用的虛擬地址。如果文件沒有關聯的入口點,此成員置零 |
|||||||||||||||||||||||||||||||||
e_phoff |
This member holds the program header table's file offset in bytes. If the file has no program header table, this member holds zero. 此成員包含程序頭表在文件中的偏移(字節)。如果文件沒有程序頭表,此成員置零 |
|||||||||||||||||||||||||||||||||
e_shoff |
This member holds the section header table's file offset in bytes. If the file has no section header table, this member holds zero. 此成員包含分節頭表在文件中的偏移(字節)。如果文件沒有分節頭表,此成員置零 |
|||||||||||||||||||||||||||||||||
e_flags |
This member holds processor-specific flags associated with the file. Flag names take the form EF_machine_flag. 此成員包含與文件關聯的處理器特定標識。標記名來自於EF_machine_flag |
|||||||||||||||||||||||||||||||||
e_ehsize |
This member holds the ELF header's size in bytes. 此成員包含ELF頭的大小(字節) |
|||||||||||||||||||||||||||||||||
e_phentsize |
This member holds the size in bytes of one entry in the file's program header table; all entries are the same size. 此成員包含文件程序頭表中一個程序頭的大小(字節);所有的程序頭大小相同。 |
|||||||||||||||||||||||||||||||||
e_phnum |
This member holds the number of entries in the program header table. Thus the product of e_phentsize and e_phnum gives the table's size in bytes. If a file has no program header table, e_phnum holds the value zero. 假如一個文件沒有程序頭表,e_phnum的值爲零 |
e_shentsize
This member holds a section header's size in bytes.
A section header is one entry in the section header table; all entries are the same size.
此成員包含分節頭表中一個分節頭的大小(字節);所有的分節頭大小相同。
e_shnum
This member holds the number of entries in the section header table.
Thus the product of e_shentsize and e_shnum gives the section header table's size in bytes.
If a file has no section header table, e_shnum holds the value zero.
此成員包含分節頭表中分節頭的數量。因此,e_shentsize和e_shnum的乘積就是分節頭表的大小。
假如一個文件沒有分節頭表,e_shnum的值爲零
e_shstrndx
This member holds the section header table index of the entry associated with the section name string table.
If the file has no section name string table, this member holds the value SHN_UNDEF.
See "Sections" and "String Table" below for more information.
此成員包含分節頭表索引是分節名符號表的入口, 假如文件沒有分節名符號表,此成員置SHN_UNDEF。
下面的“分節”和“字符串表”含更過描述信息。
ELF Identification
ELF標識
As mentioned above, ELF provides an object file framework to support multiple processors, multiple data encodings, and multiple classes of machines. To support this object file family, the initial bytes of the file specify how to interpret the file, independent of the processor on which the inquiry is made and independent of the file's remaining contents.就像上面提到的一樣,ELF提供一個對象文件框架來支持多種處理器、多種數據編碼以及多種機器分類。爲了支持這樣的對象文件家族,文件的初始字節指定如何解釋文件,不依賴於對文件進行查詢的處理器以及不依賴於文件剩下的內容。
The initial bytes of an ELF header (and an object file) correspond to the e_ident member.
ELF頭(和一個對象文件)初始字節相當於e_ident成員。
Figure 1-4. e_ident[] Identification Indexes
圖1-4. e_ident[]標識索引
名字(Name) |
大小(Size) |
目的(Purpose) |
EI_MAG0 |
0 |
文件標識 |
EI_MAG1 |
1 |
文件標識 |
EI_MAG2 |
2 |
文件標識 |
EI_MAG3 |
3 |
文件標識 |
EI_CLASS |
4 |
文件分類 |
EI_DATA |
5 |
數據編碼 |
EI_VERSION |
6 |
文件版本 |
EI_PAD |
7 |
填充數據開始位置 |
EI_NIDENT |
16 |
e_ident大小 |
These indexes access bytes that hold the following values.
通過這些索引訪問e_ident中的內容,這些內容定義如下:
EI_MAG0 to EI_MAG3 |
A file's first 4 bytes hold a "magic number," identifying the file as an ELF object file.
|
|||||||||||||||
EI_CLASS |
The next byte, e_ident[EI_CLASS], identifies the file's class, or capacity.
The file format is designed to be portable among machines of various sizes, without imposing the sizes of the largest machine on the smallest. Class ELFCLASS32 supports machines with files and virtual address spaces up to 4 gigabytes; it uses the basic types defined above. Class ELFCLASS64 is incomplete and refers to the 64-bit architectures. Its appearance here shows how the object file may change. Other classes will be defined as necessary, with different basic types and sizes for object file data. 類型ELFCLASS32支持文件和虛擬地址空間到4G;其使用上面定義的基本數據類型。 類型ELFCLASS64未完成,其引用了64位架構。它的出現展示了對象文件可能會如何改變。 其它類型在必要時會被定義,同時會爲對象文件數據定義不同的基本類型和大小 |
|||||||||||||||
EI_DATA |
Byte e_ident[EI_DATA] specifies the data encoding of the processor-specific data in the object file. The following encodings are
More information on these encodings appears below. Other values are reserved and will be assigned to new encodings as necessary. |
|||||||||||||||
EI_VERSION |
Byte e_ident[EI_VERSION] specifies the ELF header version number. Currently, this value must be EV_CURRENT, as explained above for e_version. |
|||||||||||||||
EI_PAD |
This value marks the beginning of the unused bytes in e_ident. These The value of EI_PAD will change in the future if currently unused bytes are given meanings. EI_PAD的值在將來修改了當前未使用的字節後會被改變 |
A file's data encoding specifies how to interpret the basic objects in a file. As described above, class ELFCLASS32 files use objects that occupy 1, 2, and 4 bytes. Under the defined encodings, objects are represented as shown below. Byte numbers appear in the upper left corners.Encoding ELFDATA2LSB specifies 2's complement values, with the least significant byte occupying the lowest address.
文件的數據編碼指定了如何解釋文件的基本對象。就像上面描述的一樣,分類爲ELFCLASS32的文件使用的對象中包含的成員一般佔據1、2和4字節。在這種編碼定義下,對象中的存儲方式如下圖。字節順序在方框左上角。編碼方式ELFDATA2LSB指定了2的補數值,最低有效字節佔據最低的地址。
Figure 1-5. Data Encoding ELFDATA2LSB
圖1-5. ELFDATA2LSB數據編碼格式
Encoding ELFDATA2MSB specifies 2's complement values, with the most significant byte occupying the lowest address.
編碼方式ELFDATA2MSB指定了2的補數值,最高有效字節佔據最低的地址。
Figure 1-6. Data Encoding ELFDATA2MSB
圖1-6. ELFDATA2MSB數據編碼格式