会员注册
会员登陆
取回密码
欢迎您回来
实易文章 || 发表文章 || 管理文章

ELF可执行联接规范(英汉对照版)

分类:: Unix/Linux / 发表时间 :: 2005-07-13 19:12:34
作者 :: 16hot | 人气 ::  |  评论数目 (0) | 发送 | 来源 ::


By xiaoxin


Executable and Linkable Format (ELF)

Contents

Preface

1 OBJECT FILES

Introduction 1-1

ELF Header 1-3

Sections 1-8

String Table 1-16

Symbol Table 1-17

Relocation 1-21

2 PROGRAM LOADING AND DYNAMIC LINKING

Introduction 2-1

Program Header 2-2

Program Loading 2-7

Dynamic Linking 2-10

3 C LIBRARY

C Library 3-1

I Index

Index I-1





Figures and Tables

Figure 1-1: Object File Format 1-1

Figure 1-2: 32-Bit Data Types 1-2

Figure 1-3: ELF Header 1-3

Figure 1-4: e_ident[ ] Identification Indexes 1-5

Figure 1-5: Data Encoding ELFDATA2LSB 1-6

Figure 1-6: Data Encoding ELFDATA2MSB 1-6

Figure 1-7: 32-bit Intel Architecture Identification, e_ident 1-7

Figure 1-8: Special Section Indexes 1-8

Figure 1-9: Section Header 1-9

Figure 1-10: Section Types, sh_type 1-10

Figure 1-11: Section Header Table Entry: Index 0 1-11

Figure 1-12: Section Attribute Flags, sh_flags 1-12

Figure 1-13: sh_link and sh_info Interpretation 1-13

Figure 1-14: Special Sections 1-13

Figure 1-15: String Table Indexes 1-16

Figure 1-16: Symbol Table Entry 1-17

Figure 1-17: Symbol Binding, ELF32_ST_BIND 1-18

Figure 1-18: Symbol Types, ELF32_ST_TYPE 1-19

Figure 1-19: Symbol Table Entry: Index 0 1-20

Figure 1-20: Relocation Entries 1-21

Figure 1-21: Relocatable Fields 1-22

Figure 1-22: Relocation Types 1-23

Figure 2-1: Program Header 2-2

Figure 2-2: Segment Types, p_type 2-3

Figure 2-3: Note Information 2-4

Figure 2-4: Example Note Segment 2-5

Figure 2-5: Executable File 2-7

Figure 2-6: Program Header Segments 2-7

Figure 2-7: Process Image Segments 2-8

Figure 2-8: Example Shared Object Segment Addresses 2-9

Figure 2-9: Dynamic Structure 2-12

Figure 2-10: Dynamic Array Tags, d_tag 2-12

Figure 2-11: Global Offset Table 2-17

Figure 2-12: Absolute Procedure Linkage Table 2-17

Figure 2-13: Position-Independent Procedure Linkage Table 2-18

Figure 2-14: Symbol Hash Table 2-19

Figure 2-15: Hashing Function 2-20

Figure 3-1: libc Contents, Names without Synonyms 3-1

Figure 3-2: libc Contents, Names with Synonyms 3-1

Figure 3-3: libc Contents, Global External Data Symbols 3-2





Preface

ELF: Executable and Linking Format

The Executable and Linking Format was originally developed and published by UNIX
System Laboratories (USL) as part of the Application Binary Interface (ABI). The
Tool Interface Standards committee (TIS) has selected the evolving(使进化发展) ELF
standard as a portable object file format that works on 32-bit Intel
Architecture environments for a variety of operating systems.

(可执行连接格式起初是作为UNIX系统实验室(USL)作为应用程序二进制接口(ABI)的一部分而开发和发布的。工具接口标准委员会(TIS)选择了正在发展中的ELF标准作为
可运行在32位INTEL体系的各种操作系统上的可移植的二进制文件格式。)

The ELF standard is intended to streamline software development by providing
developers with a set of binary interface definitions that extend across
multiple operating environments. This should reduce the number of different
interface implementations, thereby reducing the need for recoding and
recompiling code.

(ELF标准的目的是通过为开发者提供一个可扩展到多种操作系统环境的二进制接口规范,来简化软件的开发工作。减少了不同种类的接口实现的数量,代码的重新编码重新编译的需求也随之而减化。)

About This Document

This document is intended for developers who are creating object or executable
files on various 32-bit environment operating systems. It is divided into the
following three parts:

Part 1, ‘‘Object Files’’ describes the ELF object file format for the three main
types of object files.

Part 2, ‘‘Program Loading and Dynamic Linking’’ describes the object file
information and system actions that create running programs.

Part 3, ‘‘C Library’’ lists the symbols contained in libsys, the standard ANSI C
and libc routines, and the global data symbols required by the libc routines.

(这篇文档是为那些想在各种32位操作系统环境上创建目标文件、可执行文件的开发者们准备的。文档分为以下三个部分:

* 第一部分, “目标文件Object Files”描述了三种主要类型目标文件的ELF目标文件格式。

* 第二部分, “程序加载和动态连接”描述了目标文件的相关信息和在创建运行程序时的系统行为。

* 第三部分, “C 语言库”列出了 libsys中包含的符号, 标准ANSI C 和libc的例程函数,还有libc例程函数所必需的全局数据符号。)



NOTE

References to X86 architecture have been changed to Intel Architecture.

(注意: 参考的X86体系已经被改成了Intel体系。)



String 字符串,一组字符------一组连续的字符在计算机中被作为单一物体

Symbol 符号, 记号, 标号, 象征, 符号用来代表某一操作、要素、数量、质量或某种联系,如在数学或音乐中

1 OBJECT FILES

Introduction 1-1

File Format 1-1

Data Representation 1-2

ELF Header 1-3

ELF Identification 1-5

Machine Information 1-7

Sections 1-8

Special Sections 1-13

String Table 1-16

Symbol Table 1-17

Symbol Values 1-20

Relocation 1-21

Relocation Types 1-22



Introduction

Part 1 describes the iABI object file format, called ELF (Executable and Linking
Format). There are three main types of object files.

(第一部分描述iABI目标文件格式,称为ELF(Executable and Linking Format). 目标文件主要有3种类型。)

A relocatable file holds code and data suitable for linking with other object
files to create an executable or a shared object file.

(* 可重定位文件:保存着代码和数据,适合于和其他的目标文件连接到一起,用来创建一个可执行目标文件或者是一个可共享目标文件。)

An executable file holds a program suitable for execution; the file specifies
how exec(BA_OS) creates a program’s process image.

(* 可执行文件:保存着一个用来执行的程序(program);该文件指定exec(BA_OS)如何创建程序的进程映象。)

A shared object file holds code and data suitable for linking in two
contexts(上下文环境). First, the link editor [see ld(SD_CMD)] may process it with
other relocatable and shared object files to create another object file. Second,
the dynamic linker combines it with an executable file and other shared objects
to create a process image.

(* 可共享目标文件:保存着的代码和数据,适合于在两种上下文环境里进行连接。第一种情况:是连接编辑器[请参看ld(SD_CMD)],可以把它和其它的可重定位目标文件们和共享目标文件们一起进行处理,来创建另一目标文件(是静态的东西)。第二种情况:是动态链接器,可以把它和一个可执行文件文件和其他共享目标文件们结合(combine)起来,创建一个进程映象(是动态的东西)。)

Created by the assembler and link editor, object files are binary
representations of programs intended to execute directly on a processor.
Programs that require other abstract machines, such as shell scripts, are
excluded.

(用汇编器和联接编辑器创建出来的目标文件,都是以程序的二进制格式来存放的,以便能在在处理器上直接运行。那些需要其他抽象机器的程序,比如象shell脚本,除外。)

After the introductory material, Part 1 focures on the file format and how it
pertains(适合于) to building programs.

Part 2 also describes parts of the object file, concentrating on the information
necessary to execute a program.

(在介绍性的材料过后,第一部分重点描述着文件的格式和文件格式怎样适于建立(building)程序(program)。

第二部分也描述了object文件的几个组成部分,重点介绍执行一个程序所必须的信息。)



File Format

Object files participate in program linking (building a program) and program
execution (running a program). For convenience and efficiency, the object file
format provides parallel views(视图) of a file’s contents, reflecting the
differing needs of these activities(即:program linking 和 program execution).
Figure 1-1 shows an object file’s organization.

(目标文件参与程序联接 (building a program)和程序执行 (running a program)。为了方便和有效率,目标文件格式
为一个文件的内容 提供2种并行的视图,2种组织方法反映出linking和execution 两种活动(activity)的不同需要。例
1-1图显示了一个object文件的组织结构图。)

Figure 1-1: Object File Format

Linking View Execution View

ELF header

Program header table

程序段1(Segment 1)

程序段2(Segment 2)

……

Section header table (optional)

ELF header

Program header table (optional)

(Section 1)

……

(Section n)

……

……

Section header table



























一个ELF头位于文件的最开头部分,保存着一张描述文件组织结构的“地图”(road map)。



An ELF header resides at the beginning and holds a ‘‘road map’’(地图) describing
the file’s organization. Sections hold the bulk of object file information for
the program linking view: instructions(指令), data, symbol table, relocation
information, and so on. Descriptions of special(特殊的) sections appear later in
Part 1. Part 2 discusses segments and the program execution view of the
file.(也即:sections是和程序连接相关;segments是和程序执行相关)

(ELF头位于文件的最开头部分,保存着一张描述文件组织结构的“地图”。sections
保存目标文件的有关连接视图的信息:包括指令,数据,符号表,重定位信息等等。在第一部分当中有
特殊sections的描述。第二部分讨论segments和object文件的程序执行视图。)

A program header table, if present, tells the system how to create a process
image. Files used to build a process image (execute a program) must have a
program header table; relocatable files do not need one.

(一个程序头表(program header
table)(如果存在的话),告诉系统如何来创建一个进程映象。参与建立进程映象(即执行一个程序)的文件们必须要有一个程序头表(program header
table);重定位文件们不需要程序头表。)

A section header table contains information describing the file’s sections.
Every section has an entry in the table; each entry gives information such as
the section name, the section size, etc. Files used during linking must have a
section header table; other object files may or may not have one.

(一个section头表(section header
table)包含了文件sections的相关信息。每个section在这个表中有一个表项;每个表项内容包括:section名字,section大小,等信息。参与联接过程的文件们都必须有一个section头表;其他目标文件们的section头表可有可无。)

NOTE

Although the figure shows the program header table immediately after the ELF
header, and the section header table following the sections, actual files may
differ. Moreover, sections and segments have no specified order. Only the ELF
header has a fixed position(固定位置) in the file.

(注意:
虽然上面图示的情形是程序头表的位置紧跟在ELF头的后面,section头表跟在sections的后面,但在实际的文件中位置是可变的。此外,sections和segments也没有特别的顺序。只有ELF
header在文件中的位置必须是固定的。)

Data Representation (数据表示)

As described here, the object file format supports various processors with 8-bit
bytes and 32-bit architectures.Nevertheless, it is intended to be extensible to
larger (or smaller) architectures. Object files therefore represent some control
data with a machine-independent format, making it possible to identify object
files and interpret their(object files) contents in a common way. Remaining data
in an object file use the encoding of the target processor, regardless of the
machine on which the file was created.

(object文件格式支持8位、32位架构不同的处理器。不过,它试图努力扩展到更大或更小的体系上运行。因此,object文件采用与机器无关的格式表示一些控制数据,使得可用一种通用的方法识别object文件和描述他们的内容。在object文件中其余的数据使用目标处理器的编码,不管文件是在哪台机器上创建的。)
(即:只需要把目标文件中的控制数据表示成机器无关格式就可以广泛移植了,而文件其余的数据按照目标处理器编码即可)



Figure 1-2: 32-Bit Data Types

名称 大小 对齐字节 作用

Elf32_Addr 4 4 无符号程序地址(Unsigned program address)

Elf32_Half 2 2 无符号中整型(Unsigned medium integer)

Elf32_Off 4 4 无符号文件偏移量(Unsigned file offset)

Elf32_Sword 4 4 带符号长整型(Signed large integer)

Elf32_Word 4 4 无符号长整型(Unsigned large integer)

Unsigned char 1 1 无符号小整型(Unsigned small integer)



All data structures that the object file format defines (目标文件格式定义的所有数据结构)follow
the ‘‘natural’’ size and alignment guidelines for the relevant class(相关类型的对齐准则).
If necessary, data structures contain explicit padding(明确的填充字节) to ensure 4-byte
alignment for 4-byte objects(4字节对象,例如:4字节大小的数据结构), to force data structure sizes
to a multiple of 4(4的倍数), etc. Data also have suitable alignment from the
beginning of the file. Thus, for example, a data structure containing an
Elf32_Addr member will be aligned on a 4-byte boundary within the file.

For portability reasons, ELF uses no bit-fields.

(目标文件格式定义的所有数据结构都是依照“自然”大小和相关类型的对齐准则。如果需要的话,数据结构中包含了明确的填充字节,强制使数据结构的大小是4的倍数,
以保证4-byte
object是4字节对齐的。在文件开头的数据也有适当的对齐。例如,一个包含了一个Elf32_Addr成员的数据结构将会在文件中对齐到4字节的边界上。

因为移植性的原因,ELF不使用位字段(bit-fields)。)

ELF Header

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??.


(一些object文件的控制数据结构能够增长,因为ELF头包含了他们实际的尺寸。假如object文件格式改变,程序可能会遇到或大或小他们不能预期的控制数据结构尺寸。程序可能因此忽略额外多余的信息。对于缺少的信息的处理要依赖于上下文,如果扩展名(extensions)被定义,缺少的信息将会被指定。)

Figure 1-3: ELF Header

#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_ident标明文件为一个object文件,e_ident[]数组里面也提供了机器无关的数据用来解码和解释目标文件的内容。这些在下面的ELF
Identification部分有详尽的描述。)

e_type This member identifies the object file type.

Name Value Meaning

==== ===== =======

ET_NONE 0 No file type

ET_REL 1 Relocatable file

ET_EXEC 2 Executable file

ET_DYN 3 Shared object file

ET_CORE 4 Core file

ET_LOPROC 0xff00 Processor-specific

ET_HIPROC 0xffff Processor-specific



Although the core file contents are unspecified, type ET_CORE is reserved to
mark the core file. 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.

(虽然CORE的文件内容未被指定详细说明,ET_CORE类型是保留用于core 文件的。从 ET_LOPROC 到 ET_HIPROC(包括ET_HIPROC)是为处理器特定相关的语义保留的。其他的保留值需要的话将来可用于新的object文件类型。)

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

(e_machine成员的值指定一个单独文件必需的体系结构。)

Name Value Meaning

==== ===== =======

EM_NONE 0 No machine

EM_M32 1 AT&T WE 32100

EM_SPARC 2 SPARC

EM_386 3 Intel 80386

EM_68K 4 Motorola 68000

EM_88K 5 Motorola 88000

EM_860 7 Intel 80860

EM_MIPS 8 MIPS RS3000



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(即:e_flags) mentioned below use the prefix EF_; a flag named
WIDGET for the EM_XYZ machine would be called EF_XYZ_WIDGET.

(如有需要,其他保留的值将可用于新的机器类型上。机器名字可区分处理器特定相关的ELF名字。例如,下面将要被提到的成员flags使用前缀EF_;名字为WIDGET的flag用于一台EM_XYZ机器上,就叫做EF_XYZ_WIDGET。)

e_version This member identifies the object file version.

(e_version 成员识别object文件的版本)



Name Value Meaning

==== ===== =======

EV_NONE 0 Invalid version

EV_CURRENT 1 Current 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表示最初的文件格式(版本);extensions(未来扩展?)将会创建更高的(>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_entry成员是系统第一次将控制传递到的虚拟地址,从而启动进程。假如文件没有任何相关联的入口点,该成员的值为0。)

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_phoff成员保持着程序头表(program header
table)在文件中的偏移量(以字节为单位计数)。假如该文件没有程序头表的的话,该成员就保持为0。)

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_shoff成员保持着section头表(section header
table)在文件中的偏移量(以字节为单位计数)。假如该文件没有section头表的的话,该成员就保持为0。)

e_flags This member holds processor-specific flags associated with the file.
Flag names take form the EF_machine_flag. See ‘‘Machine Information’’ for flag
definitions(定义).

(e_flags成员保存着相关文件的处理器特定相关标志。flag的名字取自于EF_machine_flag。参看“Machine
Information”部分的flag的定义。)

e_ehsize This member holds the ELF header’s size in bytes.

(e_ehsize成员保存着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_phentsize成员保存着 文件的程序头表中每一个表项的大小(以字节计数)。所有的表项大小相同。)

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_phentsize和e_phnum的乘积就是表的大小(以字节计数)。如果程序头表不存在,e_phnum的值为0。)

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_shentsize成员保存着section头的大小(以字节计数)。一个section头就是section头表的一个表项;所有的表项大小相同。)

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_shnum成员保存着section header table中的全部表项的个数。因此,e_shentsize和e_shnum的乘积就是section头表的大小(以字节计数)。如果文件没有section头表,e_shnum值为0。)

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.

(该成员保存着section name string table相关表项(对应)的section头表索引。假如文件中没有section name string
table,该变量值为SHN_UNDEF。)

ELF Identification

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(e_ident[] =16
bytes) specify how to interpret the file, (initial bytes in e_ident[]
is)independent of the processor on which the inquiry is made and (is also)
independent of the file’s remaining contents.

The initial bytes of an ELF header (and an object file) correspond to the
e_ident member.

(在上面提到的,ELF提供了一个目标文件架构来支持多种处理机,多种数据编码方式,及多种机器类型。为了支持这个目标文件家族(family),文件最初的几个字节是不依赖于处理器构架的,而且和文件剩下的内容无关,它们用来说明如何解释该文件。

ELF头(以及object文件头)最初的几个字节就是e_ident成员。)

Figure 1-4: e_ident[ ] Identification Indexes

Name Value Purpose

==== ===== =======

EI_MAG0 0 File identification

EI_MAG1 1 File identification

EI_MAG2 2 File identification

EI_MAG3 3 File identification

EI_CLASS 4 File class

EI_DATA 5 Data encoding

EI_VERSION 6 File version

EI_PAD 7 Start of padding bytes

EI_NIDENT 16 Size of e_ident[]



These indexes access bytes that hold the following values.

EI_MAG0 to EI_MAG3

A file’s first 4 bytes hold a ‘‘magic number,’’ identifying the file as an ELF
object file.

( 文件的前4个字符保存着一个魔术数(magic number),用来标识该文件是否为一个ELF目标文件。)

Name Value Position

==== ===== ========

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],用来标识文件的类型或者相容性(capacity)。)

Name Value Meaning

==== ===== =======

ELFCLASSNONE 0 Invalid class

ELFCLASS32 1 32-bit objects

ELFCLASS64 2 64-bit objects



The file format is designed to be portable among machines of various sizes,
without imposing(强加于 impossible) the sizes of the largest machine on the
smallest. EI_CLASS value ELFCLASS32 supports machines with files and virtual
address spaces up to 4 gigabytes; it uses the basic types defined above. Class
value ELFCLASS64 is reserved for 64-bit architectures. Its appearance here shows
how the object file may change, but the 64-bit format is otherwise unspecified.
Other classes will be defined as necessary, with different basic types and sizes
for object file data.

(文件格式被设计成在不同size的机器中可伸缩移植的,而不至于在小型机上勉强用大型机上的尺寸(size)。类型ELFCLASS32支持虚拟地址空间最大可达4GB的机器;它使用上面定义过的基本类型。类型ELFCLASS64为64位体系的机器保留。它表明了object文件可能演变的趋势,但是64位的格式目前还没有被定义。需要的话,也将会为目标文件数据定义其他classes(具有不同的basic
types和不同的大小尺寸。))

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]指定了object文件中与特定处理器相关的数据的编码方式。当前定义了以下编码方式。)

Name Value Meaning

==== ===== =======

ELFDATANONE 0 Invalid data encoding

ELFDATA2LSB 1 See below

ELFDATA2MSB 2 See below



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,EV_CURRENT的解释在前面的e_version部分。)

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.

(EI_PAD标明了在e_ident[]中未使用字节的开始(位置)。这些未使用字节被保留并被设置为0;从object
文件程序时读取应该忽略他们。假如当前未被使用的字节将来被赋予了新的涵义,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.

(一个文件的数据编码(EI_DATA)指出了如何来解释一个文件中基本的数据对象。在上述的描述中,class
ELFCLAS32的文件使用的数据结构对象占用1,2或4字节。在这种编码方式的定义下,数据对象表示如下。Byte numbers出现在左上角。)

Encoding ELFDATA2LSB specifies 2’s complement values, with the least significant
byte occupying the lowest address.

(ELFDATA2LSB编码指定了2的补数值,最小有意义的字节占有最低的地址。)

Figure 1-5: Data Encoding ELFDATA2LSB

0x01 01

0x0102 02 01

0x01020304 04 03 02 01



Encoding ELFDATA2MSB specifies 2’s complement values, with the most significant
byte occupying the lowest address.

(ELFDATA2MSB编码指定了2的补数值,最大有意义的字节占有最低的地址。)

Figure 1-6: Data Encoding ELFDATA2MSB

0x01 01

0x0102 01 02

0x01020304 01 02 03 04



32-bit Intel Machine Information

For file identification in e_ident[], the 32-bit Intel Architecture requires the
following values.

(为了在e_ident中标识文件,32位Intel体系结构的需要以下的值。)

Figure 1-7: 32-bit Intel Architecture Identification, e_ident

Position Value

======== =====

e_ident[EI_CLASS] ELFCLASS32

e_ident[EI_DATA] ELFDATA2LSB



Processor identification resides in the ELF header’s e_machine member and must
have the value EM_386.

The ELF header’s e_flags member holds bit flags associated with the file. The
32-bit Intel Architecture defines no flags; so this member contains zero.

(ELF头里的e_machine成员用来标识处理器,其值必须为EM_386。ELF头里的e_flags成员保存了与文件相关的位标记。32位Intel体系上未定义位标记;所以这个成员的值为0。)



Sections

An object file’s section header table lets one locate all the file’s sections.
The section header table is an array of Elf32_Shdr structures as described
below. A section header table index is a subscript(下标) into this array.

The ELF header’s(Elf32_Ehdr) e_shoff member gives the byte offset from the
beginning of the file to the section header table; e_shnum tells how many
entries the section header table contains; e_shentsize gives the size in bytes
of each entry.

Some section header table indexes are reserved; an object file will not have
sections for these special indexes.

(一个object文件的section头表可以让我们定位文件中所有的sections。section头表是个Elf32_Shdr结构的数组(在后面描述)。一个section
头表索引是这个数组的一个下标。

ELF header (Elf32_Ehdr)中:e_shoff成员给出了section头表的偏移量(从文件开始计算的字节数);e_shnum成员给出section头表中包含了多少个表项;e_shentsize
成员给出了每个表项的大小。

某些section报头表索引是保留的;这些特殊的索引在一个object文件中没有与之对应sections。)



Figure 1-8: Special Section Indexes

Name Value

==== =====

SHN_UNDEF 0

SHN_LORESERVE 0xff00

SHN_LOPROC 0xff00

SHN_HIPROC 0xff1f

SHN_ABS 0xfff1

SHN_COMMON 0xfff2

SHN_HIRESERVE 0xffff



SHN_UNDEF This value marks an undefined, missing, irrelevant(无关的), or otherwise
meaningless section reference. For example, a symbol ‘‘defined’’ relative to
section number SHN_UNDEF(定义的与sention头表索引号SHN_UNDEF相关的标号们) is an undefined
symbol.

(该值标明一个 未定义,缺失,无关的或者无意义的section引用。例如,一个 被定义的 与sention头表索引号SHN_UNDEF有关的
符号是一个未定义符号。)



NOTE

Although index 0(即:SHN_UNDEF) is reserved as the undefined value, the section
header table (still) contains an entry for index 0. That is, if the e_shnum
member of the ELF header says a file has 6 entries in the section header table,
they have the indexes 0 through 5. The contents of the initial entry are
specified later in this section.

(注意: 虽然索引0保留作为未定义的值,section报头表仍会为索引0保留一个表项。因此,假如ELF报头中的e_shnum成员说一个文件的section报头表中有6个section表项的话,6个section表项的索引值应该是从0到5。初始表项的内容以后在这个section中被指定。)



SHN_LORESERVE This value specifies the lower bound of the range of reserved
indexes.

(该值指定 被保留索引范围的最小边界值。)

SHN_LOPROC through SHN_HIPROC Values in this inclusive range are reserved for
processor-specific semantics.

(该范围值为特定处理器相关的语意保留。)

SHN_ABS This value specifies absolute values for the corresponding reference.
For example, symbols defined relative to section number SHN_ABS have absolute
values and are not affected by relocation.

(该值指定对应引用的绝对值。例如,被定义的与sention头表索引号SHN_ABS相关的符号们拥有绝对数值,不被重定位影响。)



SHN_COMMON Symbols defined relative to this section number SHN_COMMON are common
symbols, such as FORTRAN COMMON or unallocated C external variables(外部变量).

(被定义的与sention头表索引号SHN_COMMON相关的符号们是一般符号,例如:FORTRAN COMMON或者未分配的C外部变量。)

SHN_HIRESERVE This value specifies the upper bound of the range of reserved
indexes. The system reserves indexes between SHN_LORESERVE and SHN_HIRESERVE,
inclusive(包括再内的); and these values do not reference the section header
table.That is, the section header table does not contain entries for the
reserved indexes.

(该值指定被保留索引范围的上限值。系统保留从SHN_LORESERVE到SHN_HIRESERVE之间的索引值;这些索引值不引用到section头表(的表项)。也就是说,section头表不含被保留索引值们的表项。)



Sections contain all information in an object file, except the ELF header, the
program header table, and the section header table. Moreover, object files’
sections satisfy several conditions.

(1) Every section in an object file has exactly one section header describing
it. Section headers may exist that do not have a section.

(2) Each section occupies one contiguous (possibly empty) sequence of bytes
within a file.

(3) Sections in a file may not overlap. No byte in a file resides in more than
one section.

(4) An object file may have inactive space. The various headers and the sections
might not ‘‘cover’’(笼罩普及) every byte in an object file. The contents of the
inactive data are unspecified.

除了ELF header,program header table和section header table,sections包含了一个object文件中其它所有信息(注意是指信息而非数据,即控制管理object文件的相关信息,而不是指object文件中的所有字节数据)。此外,object文件的sections满足几个条件:

* 每个在object文件中的section都有一个确切的section的头来描述它。

可能会有section头存在但section不存在的情况。

* 每个section在文件中都占有一段相临连续的字节(但可能是空的)。

* 文件中的Sections不能重叠。文件中任何一个字节不能同时在多个section中。

* object文件可以有"非活动的"空间。所有的报头和sections未必能覆盖遍及

object文件中的每个字节。"非活动"数据的内容是未指定的。



A section header has the following structure.

Figure 1-9: Section Header

typedef struct {

Elf32_Word sh_name;

Elf32_Word sh_type;

Elf32_Word sh_flags;

Elf32_Addr sh_addr;

Elf32_Off sh_offset;

Elf32_Word sh_size;

Elf32_Word sh_link;

Elf32_Word sh_info;

Elf32_Word sh_addralign;

Elf32_Word sh_entsize;

} Elf32_Shdr;



sh_name This member specifies the name of the section. Its value is an index
into the section header string table section [see ‘‘String Table’’ below],
giving the location of a null-terminated string.

(sh_name指定section的名字。 Sh_name的值(例如:.dynsym) 是section头字符表中的一个索引值。[参看后面的“String
Table”,section header string table 存放在 .shstrtab section里面],
通过section头字符表可以查找出以NULL空字符结尾的字符串的位置。)

sh_type This member categorizes the section’s contents and semantics(按内容和意义分类).
Section types and their descriptions appear below.

sh_flags Sections support 1-bit flags that describe miscellaneous(各种各样的)
attributes. Flag definitions appear below.

sh_addr If the section will appear in the memory image of a process, this member
gives the address(内存地址) at which the section’s first byte should reside.
Otherwise, the member contains 0.

(如果一个section将参与出现在进程的内存映象里,sh_addr成员给出了该section的第一字节在内存中的驻留的地址。否则,sh_addr值为0。)
(section是和程序连接相关的,所以sh_addr很重要)

sh_offset This member’s value gives the byte offset from the beginning of the
file to the first byte in the section. One section type, SHT_NOBITS described
below, occupies no space in the file, and its sh_offset member locates the
conceptual placement?? in the file.

( sh_offset给出了section的在文件中的字节偏移量(从文件开头到
section的第1个字节)。SHT_NOBITS类型的section(在后面讨论)在文件中不占空间,它的sh_offset成员定位在文件中的概念上的位置。)

sh_size This member gives the section’s size in bytes. Unless the section type
is SHT_NOBITS, the section occupies sh_size bytes in the file. A section of
SHT_NOBITS type may have a non-zero size, but it occupies no space in the file.

(sh_size成员给出了section的大小(字节为单位)。除非这个section的类型为SHT_NOBITS,否则该section将在文件中将占有sh_size个字节。SHT_NOBITS类型的section的大小可能是非0的,但是在文件中不占空间。)

sh_link This member holds a section header table index link??, whose
interpretation depends on the section type. A table below describes the values.

sh_info This member holds extra information(额外的信息), whose interpretation depends
on the section type. A table below describes the values.

sh_addralign Some sections have address alignment constraints. For example, if a
section holds a double word, the system must ensure doubleword alignment for the
entire section. That is, the value of sh_addr must be congruent to 0, modulo the
value of sh_addralign. Currently, only 0 and positive integral powers of two are
allowed. Values 0 and 1 mean the section has no alignment constraints.

(一些sections有地址对齐的约束。例如,假如一个section保存着一个双字,系统就必须确保整个section是双字对齐的。也就是说sh_addr的值以sh_addralign的值取模结果为0。目前,sh_addralign允许取值0和2的正整数次幂,值为0和1表示该section没有对齐约束。)

sh_entsize Some sections hold a table of fixed-size entries, such as a symbol
table. For such a section, this member gives the size in bytes of each entry.
The member contains 0 if the section does not hold a table of fixed-size
entries.

(一些sections中(例如:.hash .dynsym .symtab .plt
.got等secion)保存着一张表,该表的表项是大小固定的,比如符号表。对于这样的section来说,该成员给出了这张表每个表项的大小(字节为单位)。如果该section没有保存着一张固定大小entry的表,sh_entsize成员就为0。(注意:字符串表的每个表项大小是不固定的,所以
.dynstr .shstrtab .strtab等section 的sh_entsize的值也为0))





A section header’s sh_type member specifies the section’s semantics(语意).

Figure 1-10: Section Types, sh_type

Name Value

==== =====

SHT_NULL 0

SHT_PROGBITS 1

SHT_SYMTAB 2

SHT_STRTAB 3

SHT_RELA 4

SHT_HASH 5

SHT_DYNAMIC 6

SHT_NOTE 7

SHT_NOBITS 8

SHT_REL 9

SHT_SHLIB 10

SHT_DYNSYM 11

SHT_LOPROC 0x70000000

SHT_HIPROC 0x7fffffff

SHT_LOUSER 0x80000000

SHT_HIUSER 0xffffffff



SHT_NULL This value marks the section header as inactive; it does not have an
associated section. Other members of the section header have undefined values.

( sh_type=SHT_NULL 表明该section头是非活动的;它没有相关联的section。该section头的其他成员的值都是未定义的。)

SHT_PROGBITS The section holds information defined by the program, whose format
and meaning are determined(决定) solely(唯一地) by the program.

(sh_type=SHT_PROGBITS 表明该section保存着 被程序所定义信息,这些信息的格式和意义唯一取决于这个程序。)

SHT_SYMTAB and SHT_DYNSYM

These sections hold a symbol table. Currently, an object file may have only one
section of each type(每种类型的section), but this restriction may be relaxed in the
future.

Typically, SHT_SYMTAB section provides symbols for link editing, though it may
also be used for dynamic linking. As a complete symbol table, it may contain
many symbols unnecessary for dynamic linking. Consequently, an object file may
also contain a SHT_DYNSYM section, which holds a minimal set of dynamic linking
symbols, to save space. See ‘‘Symbol Table’’ below for details.
(这些类型的sections中保存着一个符号表(symbol
table)。目前,一个object文件中SHT_SYMTAB和SHT_DYNSYM类型的section各只有一个,但是,在将来这个约束可能被放宽。

典型的,SHT_SYMTAB为连接器提供标号,当然它也可被动态连接时使用。SHT_SYMTAB包含了一个完整的符号表,可能包含的一些符号,在动态连接时根本用不着。

因此,一个object文件也包含了一个SHT_DYNSYM类型的section,它保存着动态连接时所需最小的符号集合,以便节省空间。参看下面符号表“Symbol
Table”的详细说明。)

SHT_STRTAB The section holds a string table. An object file may have multiple
string table sections. See ‘‘String Table’’ below for details.

(sh_type=SHT_STRTAB
表明该section保存着一个字符串表。一个object文件可以有多个SHT_STRTAB类型的section以包含多个字符串表。详情看下面字符串表“String
Table”的详细说明。)

SHT_RELA The section holds relocation entries with explicit addends, such as
type Elf32_Rela for the 32-bit class of object files. An object file may have
multiple relocation sections. See ‘‘Relocation’’ below for details.

(sh_type=SHT_RELA
表明该section保存着带有明确加数的重定位表项,比如object文件的32位类型重定位表项:Elf32_Rela。一个object文件可能有多个重定位的sections。具体细节参看重定位“Relocation”部分。)

SHT_HASH The section holds a symbol hash table. All objects file participating
in dynamic linking must contain a symbol hash table. Currently, an object file
may have only one hash table, but this restriction may be relaxed in the future.
See ‘‘Hash Table’’ in Part 2 for details.

(sh_type=SHT_HASH 表明该section保存着一个
符号哈希表。所有参与动态连接的object必须包含一个符号哈希表。当前,一个object文件只有一个哈希表。但是,在将来这个约束可能被放宽。详细细节看第二部分的哈希表"Hash
Table"。)

SHT_DYNAMIC The section holds information for dynamic linking. Currently, an
object file may have only one dynamic section, but this restriction may be
relaxed in the future. See ‘‘Dynamic Section’’ in Part 2 for details.

(sh_type=SHT_DYNAMIC
表明该section保存着用于动态连接的信息。当前,一个object可能只有一个动态的section,但是,将来这个限制可能被取消。详细细节看第二部分的“Dynamic
Section”。)

SHT_NOTE The section holds information that marks the file in some way. See
‘‘Note Section’’ in Part 2 for details.

(sh_type=SHT_NOTE 表明该section保存着其他的一些标志文件的信息。)

SHT_NOBITS A section of this type occupies no space in the file but otherwise
resembles SHT_PROGBITS. Although this section contains no bytes, this type
section’s sh_offset member contains the conceptual file offset.

(sh_type=SHT_NOBITS 表明该section在文件中不占空间,但是类似于SHT_PROGBITS类型section。
尽管该类型section不包含字节,但是section头的sh_offset成员包含了概念上的文件偏移量。)

SHT_REL The section holds relocation entries without explicit addends, such as
type Elf32_Rel for the 32-bit class of object files. An object file may have
multiple relocation sections. See ‘‘Relocation’’ below for details.( SHT_RELA
The section holds relocation entries with explicit addends)

(sh_type=SHT_REL
表明该section保存着不带有明确加数的重定位表项,比如object文件的32位类型重定位表项:Elf32_Rel。一个object文件可能有多个重定位的sections。具体细节参看重定位“Relocation”部分。)

SHT_SHLIB This section type is reserved but has unspecified semantics. Programs
that contain a section of this type do not conform to the ABI.

(sh_type=SHT_SHLIB 表明该section为保留但语意没有指明。包含这个类型的section的程序是不符合ABI的。)

SHT_LOPROC through SHT_HIPROC

Values in this inclusive range are reserved for processor-specific semantics.

(sh_type在SHT_LOPROC-SH_HIPROC范围之间的值为特定处理器语意保留的。)

SHT_LOUSER This value specifies the lower bound of the range of indexes reserved
for application programs(用户应用程序).

(SHT_LOUSER是为应用程序保留的索引范围的最小边界。)

SHT_HIUSER This value specifies the upper bound of the range of indexes reserved
for application programs. Section types between SHT_LOUSER and SHT_HIUSER may be
used by the application, without conflicting with current or future
system-defined section types.

(SHT_HIUSER是为应用程序保留的索引范围的最大边界。在SHT_LOUSER和HIUSER之间的section类型可能被应用程序使用,这和当前或者将来系统定义的section类型是不冲突的。)



Other section type values are reserved. As mentioned before, the section header
for index 0 (SHN_UNDEF) exists, even though the index marks undefined section
references. This entry holds the following.

(其他section类型值是保留的。前面提到过,section头表的index 0(SHN_UNDEF)对应的section头是存在的,尽管index
0标记的是未定义的section引用。Index 0对应的section header table 表项保存着以下的信息。)

Figure 1-11: Section Header Table Entry: Index 0

Name Value Note

==== ===== ====

sh_name 0 No name

sh_type SHT_NULL Inactive

sh_flags 0 No flags

sh_addr 0 No address

sh_offset 0 No file offset

sh_size 0 No size

sh_link SHN_UNDEF No link information

sh_info 0 No auxiliary information

sh_addralign 0 No alignment

sh_entsize 0 No entries





A section header’s sh_flags member holds 1-bit flags that describe the section’s
attributes. Defined values appear below; other values are reserved.

(section头的sh_flags成员保存着1位标记,用来描述section的属性。以下是定义的值;其他的值保留。)

Figure 1-12: Section Attribute Flags, sh_flags

Name Value

==== =====

SHF_WRITE 0x1

SHF_ALLOC 0x2

SHF_EXECINSTR 0x4

SHF_MASKPROC 0xf0000000



If a flag bit is set in sh_flags, the attribute is ‘‘on’’ for the section.
Otherwise, the attribute is ‘‘off’’ or does not apply. Undefined attributes are
set to zero.

(假如设置了在sh_flags中的某个标志位,该section相应的属性就被打开了。否则,该属性就是关闭的。未定义的属性设为0。)

SHF_WRITE The section contains data that should be writable during process
execution.

(sh_flags=SHF_WRITE 表明该section包含的数据在进程执行过程中应该可写。)

SHF_ALLOC The section occupies memory during process execution. Some control
sections do not reside in the memory image of an object file; this attribute is
off for those sections.

(sh_flags=SHF_ALLOC
表明该section在进程执行过程中占据着内存。但有一些控制section没有驻留在目标文件的内存映象中;这些sections的SHF_ALLOC属性是关闭的。)

SHF_EXECINSTR The section contains executable machine instructions(可执行的机器指令).

(sh_flags=SHF_EXECINSTR 表明该section包含了可执行的机器指令。)

SHF_MASKPROC All bits included in this mask are reserved for processor-specific
semantics.

(sh_flags=SHF_MASKPROC这个掩码中包括的所有的位是为特定处理器语意保留的。)



Two members in the section header, sh_link and sh_info, hold special
information, depending on section type.

(对section头中的成员sh_link和sh_info的解释要依赖于该section的类型:sh_type。)

Figure 1-13: sh_link and sh_info Interpretation

sh_type sh_link sh_info

======= ======= =======

SHT_DYNAMIC The section header index of 0

the string table used by

entries in the section.

SHT_HASH The section header index of 0

the symbol table to which the

hash table applies.(apply to应用)

SHT_REL, The section header index of The section header index of

SHT_RELA the associated symbol table. the section to which the

relocation applies.

SHT_SYMTAB, The section header index of One greater than?? the symbol

SHT_DYNSYM the associated string table. table index of the last local

symbol (binding STB_LOCAL).

other SHN_UNDEF 0

(The section header index of the symbol table to which the hash table applies??.
大意是:hash table应用到的symble table section所对应的section头表中的索引值) ( section header
table是section header结构的数组,section 头表索引是section头数组的下标值,section
header数组是从0开始计数,例如:.dynsym section所对应的section header在section header
table中是第6项,那么.dynsym 的section header index =5;可以用readelf -a test 实际查看一下.dynsym
section 所对应的sh_link sh_info的值)



Special Sections

Various sections hold program and control information. Sections in the list
below are used by the system and have the indicated(表明的) types and attributes.

Figure 1-14: Special Sections

Name Type Attributes

==== ==== ==========

.bss SHT_NOBITS SHF_ALLOC+SHF_WRITE

.comment SHT_PROGBITS none

.data SHT_PROGBITS SHF_ALLOC+SHF_WRITE

.data1 SHT_PROGBITS SHF_ALLOC+SHF_WRITE

.debug SHT_PROGBITS none

.dynamic SHT_DYNAMIC see below

.dynstr SHT_STRTAB SHF_ALLOC

.dynsym SHT_DYNSYM SHF_ALLOC

.fini SHT_PROGBITS SHF_ALLOC+SHF_EXECINSTR

.got SHT_PROGBITS see below

.hash SHT_HASH SHF_ALLOC

.init SHT_PROGBITS SHF_ALLOC+SHF_EXECINSTR

.interp SHT_PROGBITS see below

.line SHT_PROGBITS none

.note SHT_NOTE none

.plt SHT_PROGBITS see below

.relname SHT_REL see below

.relaname SHT_RELA see below

.rodata SHT_PROGBITS SHF_ALLOC

.rodata1 SHT_PROGBITS SHF_ALLOC

.shstrtab SHT_STRTAB none

.strtab SHT_STRTAB see below

.symtab SHT_SYMTAB see below

.text SHT_PROGBITS SHF_ALLOC+SHF_EXECINSTR



.bss This section holds uninitialized data(未初始化数据) that contribute to the
program’s memory image. By definition(根据定义), the system initializes the data
with zeros when the program begins to run. The section occupies no (object) file
space, as(因为) indicated by the section type, SHT_NOBITS.

(该section保存着 创建程序内存映象时
未初始化的数据。定义bss后,当程序开始运行时,系统初始化bss数据为0。该section不占文件空间,正如它的section类型sh_type=SHT_NOBITS指示的一样。)

.comment This section holds version control information.

(该section保存着版本控制信息。)

.data and .data1

These sections hold initialized data(初始化数据) that contribute to the program’s
memory image.

(该section保存着 创建程序内存映象时 已经初始化的数据。)

.debug This section holds information for symbolic debugging. The contents are
unspecified.

(该section保存着用于符号调试的信息。其内容是未指明的。)

.dynamic This section holds dynamic linking information. The section’s
attributes will include the SHF_ALLOC bit. (Whether the SHF_WRITE bit is set) is
processor specific. See Part 2 for more information.

(该section保存着动态连接的信息。该section的属性(sh_flags)将包括SHF_ALLOC位。是否需要设置SHF_WRITE属性位跟特定处理器有关。第二部分有更详细的说明。)

.dynstr This section holds strings needed for dynamic linking, most commonly the
strings that represent the names associated with symbol table entries. See Part
2 for more information.

( 该section保存着动态连接时需要的字符串,一般情况下,表示名字的“字符串”关联着符号表表项。第二部分有更详细的说明。)

.dynsym This section holds the dynamic linking symbol table, as ‘‘Symbol Table’’
describes. See Part 2 for more information.

(该section保存着动态符号表,如“Symbol Table”的描述。第二部分有更详细的说明。)

.fini (fini -> finish)

This section holds executable instructions that contribute to the process
termination code(该section保存着可执行指令,它构成了进程中的终止代码部分。从程序连接角度讲,进程地址空间是由相关object
files的若干sections拼装起来的). That is, when a program exits normally, the system
arranges to execute the code in this section.

(该section保存着可执行指令,它构成了进程的终止代码。也就是说,当一个程序正常退出时,系统安排执行这个section的中的代码。)

.got (got -> global offset table)

This section holds the global offset table. See ‘‘Special Sections’’ in Part 1
and ‘‘Global Offset Table’’ in Part 2 for more information.

(该section保存着1张全局偏移量表。看第一部分的“Special Sections”(图1-8)和第二部分的“Global Offset
Table”获得更多的信息。)

.hash This section holds a symbol hash table. See ‘‘Hash Table’’ in Part 2 for
more information.

(该section保存着1张符号哈希表。看第二部分的“Hash Table”获得更多的信息。)

.init This section holds executable instructions that contribute to the process
initialization code(该section保存着可执行指令,它构成了进程中的初始化代码部分。从程序连接角度讲,进程地址空间是由相关object
files的若干sections拼装起来的). That is, when a program starts to run, the system
arranges to execute the code in this section before calling the main program
entry point (called main for C programs).

(该section保存着可执行指令,它构成了进程的初始化代码。因此,当一个程序开始运行时,在主程序entry
point被调用之前(c语言称为main),系统安排执行这个section的中的代码。)

.interp (interp -> interpreter)

This section holds the path name of a program interpreter(程序解释器). If the object
file has a loadable segment that includes the section, the section’s attributes
will include the SHF_ALLOC bit; otherwise, that bit will be off. See Part 2 for
more information.

(该section保存了程序的解释程序的路径。假如文件中有一个可装载段包含了.interp
section,那么该section的sh_flags的SHF_ALLOC位将被设置;否则,SHF_ALLOC位被关闭。看第二部分获得更多的信息。)

.line This section holds line number(行号) information for symbolic debugging,
which describes the correspondence between the source program and the machine
code. The contents are unspecified.

(该section包含用于符号调试的行号信息, 行号信息描述源程序与机器代码之间的对应关系。该section内容未指明。)

.note This section holds information in the format that ‘‘Note Section’’ in Part
2 describes.

(该section保存一些信息,使用“Note Section”(在第二部分说明)中提到的格式。)

.plt (plt -> procedure linkage table)

This section holds the procedure linkage table. See ‘‘Special Sections’’ in Part
1 and ‘‘Procedure Linkage Table’’ in Part 2 for more information.

(该section保存着过程连接表(Procedure Linkage Table)。看第一部分的“Special
Sections”和第二部分的“Procedure Linkage Table”。)

.relname and .relaname (rel -> relocation)

These sections hold relocation information, as ‘‘Relocation’’ below describes.
If the file has a loadable segment that includes relocation section, the
sections’ attributes will include the SHF_ALLOC bit; otherwise, that bit will be
off. Conventionally, (.relname’s) name is supplied by the section to which the
relocations apply. Thus a relocation section for .text normally would have the
name .rel.text or .rela.text.

(这些section保存着重定位的信息,看下面的“Relocation”描述。假如文件有一个可加载段包括了重定位section(例如:.rel.plt),那么该section的sh_flags的SHF_ALLOC属性位将被设置;否则,SHF_ALLOC位被关闭。按照惯例,.relname
中的name部分由应用重定位的section来提供。因此,假设应用重定位的section是:.plt,如果一个relocation section是为.plt
section保留重定位信息,那么这个relocation section的名字就是.rel.plt或者是.rela.plt。(可以用 readelf -a
test 实际查看))

.rodata and .rodata1 (ro -> read only)

These sections hold read-only data that typically contribute to a non-writable
segment in the process image. See ‘‘Program Header’’ in Part 2 for more
information.

(这些section保存着只读数据,在进程映象中构造不可写的段。看第二部分的“Program Header”获得更多的资料。)

.shstrtab This section holds section names.

(该section保存着section名字。)

.strtab This section holds strings, most commonly the strings that represent the
names associated with symbol table entries. If the file has a loadable segment
that includes the string table, the section’s attributes will include the
SHF_ALLOC bit; otherwise, that bit will be off.

(该section保存着字符串表,一般地,表示名字的字符串和符号表表项相关联。假如文件有一个可装载的段包括.strtab
section,那么该section的sh_flags成员的SHF_ALLOC属性位将被设置;否则SHF_ALLOC属性位是关闭的。

)

.symtab This section holds a symbol table, as ‘‘Symbol Table’’ in this section
describes. If the file has a loadable segment that includes the symbol table,
the section’s attributes will include the SHF_ALLOC bit; otherwise, that bit
will be off.

(该section保存着一张符号表。假如文件有一个可装载的段包括.symtab
section,那么section的sh_flags成员的SHF_ALLOC属性位将被设置;否则SHF_ALLOC属性位是关闭的。)

.text This section holds the ‘‘text,’’ or executable instructions, of a program.

(该section保存着程序的正文或者说是可执行指令。)



Section names with a dot (.) prefix are reserved for the system, although
applications may use these sections if their existing meanings are satisfactory.
Applications may use names without the prefix to avoid conflicts with system
sections. The object file format lets one define sections not in the list above.
An object file may have more than one section with the same name.

(前缀是.的section名字是为系统保留的,虽然应用程序在当前语意满足(即不产生语意冲突)的情况下可以用这些保留的section名。应用程序尽量使用不带dot前缀的section名字以避免和系统的sections名字冲突。object文件格式允许自定义上述列表以外的section。一个object文件可以有多个相同名字的section。)

Section names reserved for a processor architecture are formed by placing an
abbreviation of the architecture name ahead of the section name. The name should
be taken from the architecture names used for e_machine. For instance .FOO.psect
is the psect section defined by the FOO architecture. Existing extensions are
called by their historical names.

(通过把体系结构名字的缩写放在section名字的前面形成了为处理器体系结构保留的“section名”。
该缩写名字应该取自于ELF头的e_machine成员所使用的体系名。例如,.Foo.psect就是在spect section
在FOO体系结构上定义的名字。现存的(处理器体系)扩展名是历史遗留下来的。)

Pre-existing Extensions

========= =====

.sdata .tdesc

.sbss .lit4

.lit8 .reginfo

.gptab .liblist

.conflict



String Table (字符串表)

string:字符串,一组字符------一组连续的字符在计算机中被作为单一物体

symbol:符号, 记号, 标号, 象征, 符号用来代表某一操作、要素、数量、质量或某种联系,如在数学或音乐中

String table sections hold null-terminated character sequences(以NULL终止的字符序列),
commonly called strings. The object file uses these strings to represent symbol
and section names. One references a string as an index into the string table
section??. The first byte, which is index zero, is defined to hold a null
character. Likewise(同样的), a string table’s last byte is defined to hold a null
character, ensuring null-termination for all strings. A string whose index is
zero specifies either no name or a null name, depending on the context. An empty
string table section is permitted; its section header’s sh_size member would
contain zero. Non-zero indexes are invalid for an empty string table.

(String table sections
保存着NULL结尾的字符序列,一般我们称为字符串。object文件使用这些字符串来表示“符号”和“section名字”
(所有sh_type=SHT_STRTAB的sections 都包含了一个string table,都是string table
section)。一个string table
section的索引值可以用来引用字符串??。第一个字节,即索引0,被定义保存着一个NULL字符。同样的,string
table的最后一个字节也保存着一个NULL字符,以确保string table中间所有的字符串都是以NULL结尾的。index 为0 的字符串 可以指示 no
name或者 null name,如何解释取决于上下文。string table
section允许是空的,这样它的section头结构的sh_size成员值为0。对空的string table来说,非0的索引值是无效的。)

A section header’s sh_name member holds an index into the section header string
table section(即:.shstrtab section), as designated by the e_shstrndx member of
the ELF header. The following figures show a string table with 25 bytes and the
strings associated with various indexes.

(section 头的 sh_name 成员的值是setion 头字符串表的索引,就象ELF头的 e_shstrndx
成员所指出的那样(e_shstrndx=27 对应着section header table中的.shstrtab 的索引号;可以用readelf -a
test 实际看一下)。下表列出了一个有 25 字节的字符串表,这些字符串和不同的索引值相关联)

Index +0 +1 +2 +3 +4 +5 +6 +7 +8 +9

===== == == == == == == == == == ==

0 n a m e . V a r

10 i a b l e a b l e

20 x x

+20 +21 +22 +23 +24



Figure 1-15: String Table Indexes

Index String

===== ======

0 none

1 "name."

7 "Variable"

11 "able" (这个"able"是"Variable"的子串)

16 "able"

24 null string



As the example shows, a string table index may refer to any byte in the section.
A string may appear more than once; references to substrings may exist; and a
single string may be referenced multiple times??.Unreferenced strings also are
allowed.

(如上例所示,一个字符串表索引值可能指向.strtab section 中的任意字节。一个字符串可能被引用不止一次(例如:11 "able" ;16
"able");引用(字符串的)子串(例如:11 "able")的情况是可能存在的;一个单一字符串可以被引用多次??;而不被引用的字符串也是允许存在的(例如:
"xx")。)



Symbol Table (符号表)

An object file’s symbol table holds information needed to locate and relocate a
program’s symbolic definitions and references. A symbol table index is a
subscript into this array. Index 0 both designates the first entry in the table
and serves as the undefined symbol index. The contents of the initial
entry(index 0) are specified later in this section.??

(一个object文件的符号表保存了在定位和重定位一个程序的符号定义和引用时需要的信息。符号表索引值是数组的下标。0表项特指该表的第一个表项,是一个未定义的符号索引。初始表项的内容(index
0)在这个section中会在以后指定。??)

Name Value

==== =====

STN_UNDEF 0

A symbol table entry has the following format.

Figure 1-16: Symbol Table Entry

typedef struct {

Elf32_Word st_name;

Elf32_Addr st_value;

Elf32_Word st_size;

unsigned char st_info;

unsigned char st_other;

Elf32_Half st_shndx;

} Elf32_Sym;



st_name This member holds an index into the object file’s symbol string table??,
which holds the character representations of the symbol names. If the value is
non-zero, it represents a string table index that gives the symbol name.
Otherwise, the symbol table entry has no name.

(st_name成员的值是字符串表的索引,该字符串表保存着object文件中各符号的名字的字符表示串。 如果st_name值不为 0
,则它表示了字符串表索引,该索引给出符号名字。否则,表示该符号表项没有名字。

NOTE

External C symbols have the same names in C and object files’ symbol tables.

(外部C符号在C中和在目标文件的symbol table中拥有相同的名字)

st_value This member gives the value of the associated symbol. Depending on the
context, this may be an absolute value, an address, etc.; details appear below.

(该成员给出了相应的符号值,它可能是绝对值或地址等等,取决于上下文;细节如下所述。)

st_size Many symbols have associated sizes. For example, a data object’s size is
the number of bytes contained in the object. This member holds 0 if the symbol
has no size or an unknown size.

(许多符号都有相关的尺寸。比如,一个数据对象的大小是该对象所包含的字节数目。如果该符号没有大小或大小未知则st_size成员值为 0 。)

st_info This member specifies the symbol’s type and binding attributes. A list
of the values and meanings appears below. The following code shows how to
manipulate(操作) the values.

(st_info成员指出了符号的类型和约束属性。相应的列表如下所示。下面的代码说明了如何操作该值。)

#define ELF32_ST_BIND(i) ((i)>>4)

#define ELF32_ST_TYPE(i) ((i)&0xf)

#define ELF32_ST_INFO(b, t) (((b)8)

#define ELF32_R_TYPE(i) ((unsigned char)(i))

#define ELF32_R_INFO(s, t) ((s)

[ 返回 ]


■ 相关文章
· 让firefox自动调用下载器 (2005-09-07)
· 浅谈linux优化及安全配置 (2005-09-07)
· python入门1 (2005-09-07)
· 以非超级用户身份安装 mod_perl (2005-09-07)
· FC3中的JAVA安装及配置 (2005-09-07)
· Perl与MandrakeLinux (2005-09-07)
· Apache服务器实现用户验证 (2005-09-07)
· 受限制环境安装Perl模块方法 (2005-09-07)
· Linux内核研究系列之可执行文件格式 (2005-07-13)
· 如何阅读源代码--工具篇 (2005-07-13)
· 如何阅读源代码 (2005-07-13)
· Linux内核编程风格 (2005-07-13)
· Linux网络代码导读v0.2 (2005-07-13)
· Linuxinodecache分析 (2005-07-13)
· 目录项缓存dcache (2005-07-13)
· Linux对I/O端口资源的管理 (2005-07-13)
· Linux对ISA总线DMA的实现 (2005-07-13)
· 基于i386的Linux实现特点剖析——基础的基础 (2005-07-13)
· 基于i386的Linux实现特点剖析——关于中断 (2005-07-13)
· 基于i386体系结构的Linux实现特点剖析——内存与进程 (2005-07-13)
· ELF可执行联接规范(英汉对照版) (2005-07-13)
· Linux内核0.11(0.95)详细注释 (2005-07-13)
· ar和nm命令的使用 (2005-07-13)
· JIDEv1.7 (2005-07-13)
· Rhide-1.4.7 (2005-07-13)
· KDevelop1.3 (2005-07-13)
· Xwpe1.5.26a (2005-07-13)
· XwpeFAQ (2005-07-13)
· C-Forge1.6-4 (2005-07-13)
· cvs客户端大全 (2005-07-13)

■ 发表评论
友情提示: 本站不允许匿名发表评论。如果您是会员,请先登陆;否则,请先注册
如下内容仅代表作者个人观点,本站概不负责!
评论标题:
评论内容:
  

■ 相关评论 更多评论...
http://www.isyi.com
Copyright © 2002-2005 实易数码. All rights Reserved 
版权声明:实易数码是本Blog托管服务提供商。实易数码不承担任何责任,请与Blog使用者联系解决。
粤ICP备05023051号