您的位置:首页 > 其它

工具接口标准(TIS)可执行链接格式(ELF)规范-卷I-程序加载和动态链接(Program Loading and Dynamic Linking)

2014-01-07 16:16 721 查看
本文是对Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2的翻译

工具接口标准(TIS)可执行链接格式(ELF)规范版本 1.2

翻译以中英对照方式,英语水品有限,如有翻译不当的地方,请谅解。

Introduction

介绍


This chapter describes the object file information and system actions that create running programs. Executable and shared object files statically represent programs. To execute such programs, the system uses the files to create dynamic program representations,
or process images. A process image has segments that hold its text, data, stack, and so on. This section describes the program header and complements Chapter 1, by describing object file structures that relate directly to program execution. The primary data
structure, a program header table, locates segment images within the file and contains other information necessary to create the memory image for the program.

Given an object file, the system must load it into memory for the program to run. After the system loads the program, it must complete the process image by resolving symbolic references among the object files that compose the process

本章节描述对象文件信息以及系统创建运行程序时的动作。可执行和共享对象文件静态表示程序。执行程序时系统使用文件来创建动态程序表示,或者进程映像。一个进程映像包含文本分段、数据分段、堆栈分段等。此节描述程序头并补充章节1,通过描述程序执行直接相关的对象文件结构。主要的数据结构,程序头表,在文件中定位分段信息并包含其它的创建程序内存映像必须的信息。

对于给定的对象文件,系统必须将程序加载到内存运行。在系统加载程序后,系统必须在组成进程的对象文件中完成进程映像的符号引用解析。

Program Header

程序头


An executable or shared object file's program header table is an array of structures, each describing a segment or other information the system needs to prepare the program for execution. An object file segment contains one or more sections. Program headers
are meaningful only for executable and shared object files. A file specifies its own program header size with the ELF header's e_phentsize and e_phnum members [see "ELF Header'' in Chapter 1].

一个可执行或共享对象文件的程序头表示一个结构数组,数组中每条描述了一个分段或其它系统需要为程序执行准备的信息。一个对象文件分段包含一个或多个分节。程序头值对可执行和共享对象文件有意义。一个文件通过ELF头中成员e_phentsize和e_phnum指定了它的程序头大小[章节1中的“ELF头”]。

Figure2-1. Program Header

图2-1.程序头

typedef struct {

Elf32_Word p_type;

Elf32_Off p_offset;

Elf32_Addr p_vaddr;

Elf32_Addr p_paddr;

Elf32_Word p_filesz;

Elf32_Word p_memsz;

Elf32_Word p_flags;

Elf32_Word p_align;

} Elf32_Phdr;

p_type

This member tells what kind of segment this array element describes or how to interpret the array element's information.

Type values and their meanings appear below.

此成员告诉了此数据元素描述的分段类型或如何解释数组成员的信息。类型值和它们的含义在后面描述。

p_offset

This member gives the offset from the beginning of the file at which the first byte of the segment resides.

此成员给出了这个分段第一个字节在文件中的偏移。

p_vaddr

This member gives the virtual address at which the first byte of the segment resides in memory.

此成员给出了这个分段第一个字节在内存中的虚拟地址。

p_paddr

On systems for which physical addressing is relevant, this member is reserved for the segment's physical address.

This member requires operating system specific information, which is described in the appendix at the end of Book III.

在物理地址相关的系统中,此成员保留给分段物理地址使用。此成员需要操作系统特定信息,这部分信息将在卷三的附录中描述。

p_filesz

This member gives the number of bytes in the file image of the segment; it may be zero.

此成员给出了这个分段在文件映像中的字节数;可能为0。

p_memsz

This member gives the number of bytes in the memory image of the segment; it may be zero.

此成员给出了这个分段在内存映像中的字节数;可能为0。

p_flags

This member gives flags relevant to the segment. Defined flag values appear below.

此成员给出了分段相关标记。定义的值在后面描述。

p_align

Loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size.

This member gives the value to which the segments are aligned in memory and in the file.

Values 0 and 1 mean that no alignment is required. Otherwise, p_align should be a positive, integral power of 2,

and p_addr should equal p_offset, modulo p_align.

克加载的进程分段的p_vaddr和p_offset必须包含合适的值,必须是页面大小的模数。

此成员给出了这个分段在内存和文件中对齐的值。值0和1表示没有对齐的需求。

其它方面,p_align应该是一个正值,2的整数幂,并且p_addr应该等于p_offset对p_align取模。

Some entries describe process segments; others give supplementary information and do not

contribute to the process image.

一些入口描述进程分段;其它给出了不会对进程映像有用的补充信息。

Figure2-2. Segment Types, p_type

图2-2.分段类型,p_type

名字(Name)
值(Value)
PT_NULL
0
PT_LOAD
1
PT_DYNAMIC
2
PT_INTERP
3
PT_NOTE
4
PT_SHLIB
5
PT_PHDR
6
PT_LOPROC
0x70000000
PT_HIPROC
0x7fffffff
PT_NULLThe array element is unused; other members' values are undefined. This type lets the program header table have ignored entries.

这个数组成员是未使用的;其它成员值是未定义的。这个类型使程序头表忽略入口。

PT_LOAD

The array element specifies a loadable segment, described by p_filesz and p_memsz. The bytes from the file are

mapped to the beginning of the memory segment. If the segment's memory size (p_memsz) is larger than

the file size (p_filesz), the "extra'' bytes are defined to hold the value 0 and to follow the segment's initialized area.

The file size may not be larger than the memory size. Loadable segment entries in the program header table appear

in ascending order, sorted on the p_vaddr member.

此数组成员指定一个可加载的分段,由p_filesz和p_memsz描述。文件中的字节被映射到内存分段的开始。

假如分段内存大小(p_memsz)比文件大小(p_filesz)更大,这些“额外”的字节被定义为0并紧跟着分段初始区域。

在程序头表中的可加载分段入口根据成员p_vaddr升序排序。

PT_DYNAMIC

The array element specifies dynamic linking information. See Book III.

此数据成员指定动态链接信息。看卷三描述。

PT_INTERP

The array element specifies the location and size of a null-terminated path name to invoke as an interpreter. See Book III.

此数组成员指定一个含终结符的路径名的定位和大小,用于作为解释器调用。看卷三描述。

PT_NOTE

The array element specifies the location and size of auxiliary information.

此数组成员指定辅助信息的定位和大小。

PT_SHLIB

This segment type is reserved but has unspecified semantics. See Book III.

此分段类型被保留,但有未指定的语义,看卷三。

PT_PHDR

The array element, if present, specifies the location and size of the program header table itself, both in the file and in the

memory image of the program. This segment type may not occur more than once in a file. Moreover, it may occur only if the

program header table is part of the memory image of the program. If it is present, it must precede any loadable segment entry.

See "Program Interpreter" in the appendix at the end of Book III for further information.

此数组成员,假如存在,指定了程序头表自身在文件和内存映像的定位和大小,这个分段类型在文件中只会出现一次。

此外,它只会出现在程序头表是程序内存映像的一部分这种情况下。假如出现,它必须在所有可加载分段入口之前。

看卷三末尾的附录“程序解释器”获取更多信息。

PT_LOPROC

through

PT_HIPROC

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

在此范围内的值是保留给处理器特定语义使用的。

NOTE. Unless specifically required elsewhere, all program header segment types are optional.That is, a file's program header table may contain only those elements relevant to its contents.

注意:除非特殊的别处需求,所有的程序头分段类型是可选的。就是说,一个文件的程序头表可能值包含那些与其上下文相关的成员。

Note Section

注释分节


Sometimes a vendor or system builder needs to mark an object file with special information that other programs will check for conformance, compatibility, etc. Sections of type SHT_NOTE and program header elements of type PT_NOTE can be used for this purpose.
The note information in sections and program header elements holds any number of entries, each of which is an array of 4-byte words in the format of the target processor. Labels appear below to help explain note information organization, but they are not part
of the specification.

有时供应商和系统构建者需要通过特殊信息标记对象文件,以便其它程序检查一致性和兼容性等。分节类型为SHT_NOTE和程序头元素的PT_NOTE类型能够满足这个目的。分节和程序头元素注释信息包含任意入口号,每个入口好是一个目标处理器格式的4字节数组。出现在下面的标签帮助解释了注释信息的组织,但它们不是标注的一部分。

Figure2-3. Note Information

图2-3.注释信息

namesz
descsz
type
name
. . .
desc
. . .
namesz and name

The first namesz bytes in name contain a null-terminated character representation of the entry's owner or originator.

There is no formal mechanism for avoiding name conflicts. By convention, vendors use their own name, such as "XYZ Computer Company,''

as the identifier. If no name is present, namesz contains 0. Padding is present, if necessary, to ensure 4-byte alignment for the descriptor.

Such padding is not included in namesz.

name中的前namesz个字节包含一个含终结符的字符串表示入口的拥有者或发起人。没有正式的机制来防止名字冲突。

按照惯例,供应商使用它们自己名字,比如“XYZ计算机公司”作为标识。假如没有指定的名字,namesz为0。为了确保4字节描述符对齐,

必要的情况下进行填充。这样的填充不会包含在namesz中。

descsz and desc

The first descsz bytes in desc hold the note descriptor. ELF places no constraints on a descriptor's contents. If no descriptor is present,

descsz contains 0. Padding is present, if necessary, to ensure 4-byte alignment for the next note entry. Such padding is not included in descsz.

desc中的前descsz字节包含注释描述符。ELF没有对描述符上下文放置任何约束。假如没有描述符出现,descsz为0。

为了确保下一个注释入口4字节对齐,必要的情况下进行填充。这样的填充不会包含在descsz中。

type

This word gives the interpretation of the descriptor. Each originator controls its own types;

multiple interpretations of a single type value may exist. Thus, a program must recognize both the name and the type to "understand" a descriptor.

Types currently must be non-negative. ELF does not define what descriptors mean.

这个word大小的字段给出描述符解释。每个发起人控制自己的类型;一个单一类型值可能存在多个解释。

从而,一个程序必须同时组织名字和类型来“理解”一个描述符。当前类型必须是非负数。ELF没有定义描述符的意思。

To illustrate, the following note segment holds two entries.

举例说明,以下的注释分段包含2个入口。

Figure2-4. Example Note Segment

图2-4.注释分段举例

+0 +1 +2 +3

namesz
7
descsz
0
No descriptor

type
1
name
X
Y
Z
C
o
\0
pad
namesz
7
descsz
8
type
3
name
X
Y
Z
C
o
\0
pad
desc
word 0
word 1
NOTE. The system reserves note information with no name (namesz==0) and with a zero-length name (name[0]=='\0') but currently defines no types. All other names must have at least one non-null character.

注意:系统使用没有名字(namesz==0)保留注释信息并携带一个当前没有定义类型的0长度名字(name[0]=='\0')。所有其他的名字必须包含一个非空字符。

NOTE. Note information is optional. The presence of note information does not affect a program's TIS conformance, provided the information does not affect the program's execution behavior. Otherwise, the program does not conform to the TIS ELF specification
and has undefined behavior.

注意:注释信息是可选的。注释字段的出现不会影响一个程序的TIS一致性,提供注释信息不会影响程序的执行行为。另外,程序不会不符合TIS的ELF标准,也不会有未定义的行为。

Program Loading

程序加载


Program loading is the process by which the operating system creates or augments a process image. The manner in which this process is accomplished and how the page management functions for the process are handled are dictated by the operating system and processor.
See the appendix at the end of Book III for more details.

程序加载是操作系统创建或添加进程映像的处理。处理完成的方式和处理的页面管理功能是被操作系统和处理器负责的。看卷三末尾的附录以获取更多细节。

Dynamic Linking

动态链接


The dynamic linking process resolves references either at process initialization time and/or at execution time. Some basic mechanisms need to be set up for a particular linkage model to work, and there are ELF sections and header elements reserved for this
purpose. The actual definition of the linkage model is determined by the operating system and implementation. Therefore, the contents of these sections are both operating system and processor specific. (See the appendix at the end of Book III.)

在进程初始化和执行时,动态链接处理解析引用。一些基本的机制需要为特殊的链接模型建立,并且ELF分节和头元素也为此目的做了保留。链接模型的定义被操作系统和实现决定。因此,这些分节的内容是操作系统和处理器特定的。(看卷三末尾的附录。)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐