工具接口標準(TIS)可執行鏈接格式(ELF)規範-卷III-操作系統特性-程序加載和動態鏈接(一)

本文是對Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2的翻譯
工具接口標準(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.
可加載的分段的p_vaddr和p_offset對分頁大小取模必須是一致的值


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.
此分段類型被保留,但有未指明的語義。包含此類型的數組成員的程序不符合UNIX System V下ELF標準。

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更大。

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