工具接口标准(TIS)可执行链接格式(ELF)规范版本 1.2
翻译以中英对照方式,英语水平有限,如有翻译不当的地方,请谅解。
Introduction
介绍
This section describes the operating system specific information, including the object file
information and system actions used to create running programs on systems running the UNIX
System V Release 4 operating system.
此章节描述操作系统特定信息,包含对象文件信息和UNIX System V Release 4系统在创建运行程序时的动作。
Program Header
程序头
The following program header information is specific to UNIX System V Release 4.
以下程序头信息是指定给UNIX System V Release 4使用的。
p_paddr | On systems for which physical addressing is relevant, this member is reserved for the segment's physical address. Because System V ignores physical addressing for application programs, this member has unspecified contents for executable files and shared objects. 在物理地址相关的系统,此成员保留给分段物理地址。因为System V忽略应用程序的物理地址,所以这个成员在可执行文件和共享对象中是未指定的内容。 |
p_align | Loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size. |
Some entries describe process segments; others give supplementary information and do not contribute to the process image. Segment entries may appear in any order, except as explicitly noted below. Defined type values follow; other values are reserved for future use.
一些入口描述进程分段;其它给出不会加载到进程映像的补充信息。除了以下清晰定义的分段外,其它分段入口可能以任何顺序出现。类型值定义如下;其它值保留给将来使用。
Figure 2-1. Segment Types, p_type
图2-1.分段类型,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_LOAD | The array element specifies a loadable segment, described by p_filesz and p_memsz. 此数组成员指定一个可加载的分段,由p_filesz和p_memsz描述。 |
PT_DYNAMIC | The array element specifies dynamic linking information. See "Dynamic Section'' below for more information. 此数据成员指定动态链接信息。后面的“动态分节”有更多相关信息。 |
PT_INTERP | The array element specifies the location and size of a null-terminated path name to invoke as an interpreter. This segment type is meaningful only for executable files (though it may occur for shared objects); it may not occur more than once in a file. If it is present, it must precede any loadable segment entry. See "Program Interpreter'' below for further information. 此数组成员指定一个含终结符的路径名的定位和大小,用于作为解释器调用。 这个分段类型仅对可执行文件有意义(尽管它可能出现在共享对象中);它不会在一个文件中出现多次。 如果它出现,那它必须在所有的可加载分段入口前。看后面的“程序解释器”以获取更多信息。 |
PT_SHLIB | This segment type is reserved but has unspecified semantics. Programs that contain an array element of this type do not conform to the ELF specification for UNIX System V. |
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. 这个数组元素如果存在,指定了程序头表自身在文件和内存映像中的定位和大小。 |
Base Address
基地址
The virtual addresses in the program headers might not represent the actual virtual addresses of the program's memory image. Executable files typically contain absolute code. To let the process execute correctly, the segments must reside at the virtual addresses used to build the executable file. On the other hand, shared object segments typically contain position-independent code. This lets a segment's virtual address change from one process to another, without invalidating execution behavior. Though the system chooses virtual addresses for individual processes, it maintains the segments’ relative positions. Because position-independent code uses relative addressing between segments, the difference between virtual addresses in memory must match the difference between virtual addresses in the file. The difference between the virtual address of any segment in memory and the corresponding virtual address in the file is thus a single constant value for any one executable or shared object in a given process. This difference is the base address. One use of the base address is to relocate the memory image of the program during dynamic linking.
程序头中的虚拟地址可能与程序内存映像中的实际虚拟地址不同。可执行文件通常包含绝对代码。为了使进程正确执行,分段必须位于用于构建可执行文件的虚拟地址。另一方面,共享对象分段通常包含位置无关代码。这使得一个分段虚拟地址在不同的进程中是变化的,但又不会使执行行为无效。虽然系统为每个进程选择虚拟地址,但它会维持分段相对位置。因为位置无关的代码在分段间使用相对地址,所以虚拟地址在内存中的不同必须和虚拟地址在文件中的不同相匹配。,内存中分段虚拟地址和对应的文件中的虚拟地址间的不同是一个单独的常量值,在一个给定的进程中可执行和共享对象都是这样。这个不同时基地址。基地址的一个用途是在动态链接过程中重定位程序的内存映像。
An executable or shared object file's base address is calculated during execution from three values: the virtual memory load address, the maximum page size, and the lowest virtual address of a program's loadable segment. To compute the base address, one determines the memory address associated with the lowest p_vaddr value for a PT_LOAD segment. This address is truncated to the nearest multiple of the maximum page size. The corresponding p_vaddr value itself is also truncated to the nearest multiple of the maximum page size. The base address is the difference between the truncated memory address and the truncated p_vaddr value.
一个可执行和共享对象文件的基地址是在执行过程中被计算的,从以下三个值:虚拟内存加载地址、最大页面大小、最低进程可加载分段的虚拟地址。计算基地址时,一方面由PT_LOAD分段最低p_vaddr值相关的内存地址决定。这个地址被截断到离最大页面大小的整数倍的位置。基地址是截断的内存地址和截断的p_vaddr值之间的差值。
Segment Permissions
分段权限
A program to be loaded by the system must have at least one loadable segment (although this is not required by the file format). When the system creates loadable segments' memory images, it gives access permissions as specified in the p_flags member.
一个被系统加载的程序必须有至少一个可加载分段(虽然这不是文件格式中要求的)。当系统创建可加载分段内存映像时,它给该分段的访问权限是p_flags成员指定的。
Figure 2-2. Segment Flag Bits, p_flags
图2-2.分段标志位,p_flags
名字(Name) | 值(Value) | 意思(Meaning) |
PF_X | 0x1 | Execute |
PF_W | 0x2 | Write |
PF_R | 0x4 | Read |
PF_MASKPROC | 0xf0000000 | Unspecified |
All bits included in the PF_MASKPROC mask are reserved for processor-specific semantics. If meanings are specified, the processor supplement explains them.
所有的包含在PF_MASKPROC掩盖的位都是为处理器特定语义保留的。假如意思被指定,处理器补充部分会进行描述。
If a permission bit is 0, that type of access is denied. Actual memory permissions depend on the memory management unit, which may vary from one system to another. Although all flag combinations are valid, the system may grant more access than requested. In no case, however, will a segment have write permission unless it is specified explicitly. The following table shows both the exact flag interpretation and the allowable flag interpretation. TIS-conforming systems may provide either.
假如一个权限位为0,表示访问类型是拒绝。实际的内存权限依赖于内存管理单元,内存管理单元在不同的系统不相同。然而,在任何情况向,除非显示指定,否则分段都将有写权限。以下表展示了精确标志解释和容许标志解释。遵守TIS的系统可以提供任意一种。
Figure2-3. Segment Permissions
标识(Flag) | 值(Value) | 精确(Exact) | 容许(Allowable) |
none | 0 | All access denied | All access denied |
PF_X | 1 | Execute only | Read, execute |
PF_W | 2 | Write only | Read, write, execute |
PF_W + PF_X | 3 | Write, execute | Read, write, execute |
PF_R | 4 | Read only | Read, execute |
PF_R + PF_X | 5 | Read, execute | Read, execute |
PF_R + PF_W | 6 | Read, write | Read, write, execute |
PF_R + PF_W + PF_X | 7 | Read, write, execute | Read, write, execute |
For example, typical text segments have read and execute —but not write —permissions. Data
segments normally have read, write, and execute permissions.
举例来说,典型的文本分段有读和执行-但没有写-权限。数据分段一般有读、写和执行权限。
Segment Contents
分段内容
An object file segment comprises one or more sections, though this fact is transparent to the program header. Whether the file segment holds one or many sections also is immaterial to program loading. Nonetheless, various data must be present for program execution, dynamic linking, and so on. The diagrams below illustrate segment contents in general terms. The order and membership of sections within a segment may vary; moreover, processor-specific constraints may alter the examples below.
一个对象文件分段包含一个或者多个分节,尽管这个事实对程序头来说是透明的。不管文件分段包含一个或多个分节对程序加载也是不重要的。尽管如此,不同的数据还是必须在程序执行和动态链接等时候出现。以下的图标概括的举例说明了分段内容。在一个分段中的分节顺序和成员可能是多样化的;而且,处理器相关约束可能改变以下的例子。
Text segments contain read-only instructions and data, typically including the following sections. Other sections may also reside in loadable segments; these examples are not meant to give complete and exclusive segment contents.
文本分段包含只读指令和数据,典型的包含以下分节。其它分节也可能位于可加载分段;这些例子不意味着给出了完整及排他的分段内同。
Figure2-4. Text Segment
图2-4.文本分段
.text |
.rodata |
.hash |
.dynsym |
.dynstr |
.plt |
.rel.got |
Data segments contain writable data and instructions, typically including the following sections.
数据分段包含可写数据和指令,典型的包含了以下分节。
Figure 2-5. Data Segment
图2-5.数据分段
.data |
.dynamic |
.got |
.bss |
A PT_DYNAMIC program header element points at the .dynamic section, explained in "Dynamic Section" below. The .got and .plt sections also hold information related to position-independent code and dynamic linking. Although the .plt appears in a text segment above, it may reside in a text or a data segment, depending on the processor.
一个PT_DYNAMIC程序头元素指向一个.dynamic分节,在以下的“动态分节”解释。.got和.plt分节也包含与位置无关指令和动态链接相关的信息。虽然.plt出现在上面的文本段,它也可能位于数据段,具体依赖于处理器。
As "Sections" describes, the .bss section has the type SHT_NOBITS. Although it occupies no space in the file, it contributes to the segment's memory image. Normally, these uninitialized data reside at the end of the segment, thereby making p_memsz larger than p_filesz.
像“分节”描述,.bss分节有SHT_NOBITS类型。虽然它在文件中不占据空间,但它在分段内存映像会被建立。一般情况下,这些未初始化的数据位于分段的末尾,因此使p_memsz比p_filesz更大。