工具接口標準(TIS)可執行鏈接格式(ELF)規範-卷I-ELF頭

本文是對Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2的翻譯
工具接口標準(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.''
初始字節標識,作爲對象文件並提供機器無關的數據,解碼和解釋文件內容。在下面的“ELF標識”部分有完整的描述

e_type

This member identifies the object file type.
標識對象文件類型的成員

名字(Name)

值(Value)

意思(Meaning)

ET_NONE

0

沒有文件類型

ET_REL

1

重定位文件

ET_EXEC

2

可執行文件

ET_DYN

3

共享文件

ET_CORE

4

核心文件

ET_LOPROC

0xff00

處理器特定

ET_HIPROC

0xffff

處理器特定

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.
雖然核心文件內容未被指定,但ET_CORE被保留下來。從ET_LOPROC到ET_HIPROC(inclusive)被保留給特定處理器。

其它值被保留並在必須的時候指定給新對象類型。 

e_machine

This member's value specifies the required architecture for an individual file.

此成員的值指定需求的架構。

名字(Name)

值(Value)

意思(Meaning)

EM_NONE

0

無機器架構

EM_M32

1

AT&T WE 32100

EM_SPARC

2

SPARC

EM_386

3

Intel Architecture

EM_68K

4

Motorola 68000

EM_88K

5

Motorola 88000

EM_860

7

Intel 80860

EM_MIPS

8

MIPS RS3000 Big-Endian

EM_MIPS_RS4_BE

10

MIPS RS4000 Big-Endian

RESERVED

11-16

保留

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.
其它值被保留,在必要時分配給新機器。處理器特定的ELF名使用機器名進行區分。

比如,下面提到的標記使用EF_前綴,一個名爲WIDGET的標記在EM_XYZ的機器架構下被標識EF_XYZ_WIDGET

e_version

This member identifies the object file version.
標識對象文件版本的成員

名字(Name)

值(Value)

意思(Meaning)

EV_NONE

0

無效版本號

EV_CURRENT

1

當前版本

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_phentsize和e_phnum的乘積就是程序頭表的大小。

假如一個文件沒有程序頭表,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.
文件前4個字節包含“魔數”,標識文件是一個ELF對象文件

名字(Name)

值(Value)

意思(Meaning)

ELFMAG0

0x7f

e_ident[EI_MAG0]

ELFMAG1

’E’

e_ident[EI_MAG1]

ELFMAG2

’L’

e_ident[EI_MAG2]

ELFMAG3

’F’

e_ident[EI_MAG3]

EI_CLASS

The next byte, e_ident[EI_CLASS], identifies the file's class, or capacity.
緊接着的字節e_ident[EI_CLASS],標識文件分類或者能力

名字(Name)

值(Value)

意思(Meaning)

ELFCLASSNONE

0

無效分類

ELFCLASS32

1

32位對象

ELFCLASS32

2

64位對象

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
currently defined.
e_ident[EI_DATA]指定了對象文件中處理器相關的數據編碼方式,以下是當期已經定義的編碼方式

名字(Name)

值(Value)

意思(Meaning)

ELFDATANONE

0

無效數據編碼

ELFDATANONE

1

請看後面定義

ELFDATA2MSB

2

請看後面定義

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.
e_ident[EI_VERSION]指定ELF頭版本號。當前,必須按照上面的要求定義爲EV_CURRENT。

EI_PAD

This value marks the beginning of the unused bytes in e_ident. These
bytes are reserved and set to zero; programs that read object files should ignore them. 

The value of EI_PAD will change in the future if currently unused bytes are given meanings.
此值標記了e_ident中未使用部分的開始。這些字節被保留並且設置爲0;讀取對象文件的程序必須忽略這些字節。

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數據編碼格式


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章