工具接口標準(TIS)可執行鏈接格式(ELF)規範-卷I-程序加載和動態鏈接(Program Loading and Dynamic Linking)

本文是對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_NULL

The 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分節和頭元素也爲此目的做了保留。鏈接模型的定義被操作系統和實現決定。因此,這些分節的內容是操作系統和處理器特定的。(看卷三末尾的附錄。)

發佈了14 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章