您的位置:首页 > 其它

工具接口标准(TIS)可执行链接格式(ELF)规范-卷I-ELF头

2014-01-03 16:37 465 查看
本文是对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_identThe 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数据编码格式

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐