工具接口標準(TIS)可執行鏈接格式(ELF)規範-卷III-操作系統特性(Operating System Specific)-對象文件

本文是對Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2的翻譯
工具接口標準(TIS)可執行鏈接格式(ELF)規範版本 1.2

翻譯以中英對照方式,英語水品有限,如有翻譯不當的地方,請諒解。


Introduction
介紹

This book describes aspects of the ELF format that are specific to application programs designed to run on UNIX System V Release 4 or other operating systems that comply with the System V Interface Definition.
本卷描述ELF格式中特定於應用程序設計的地方,使其能夠運行在UNIX System V Release 4或其它遵守System V接口定義的操作系統
NOTE. For information on references such as BA_OS, refer to the System V Interface Definition, 3rd Edition.
注意:像BA_OS一樣的參考信息,參考System V接口定義,第三版。

Sections
分節

The following sections are UNIX System V Release 4 specific:
以下分節是UNIX System V Release 4特定的:

SHT_SYMTAB and  SHT_DYNSYM

These sections hold a symbol table. Currently, an object file may have only one section of each type, 

but this restriction may be relaxed in the future. Typically, SHT_SYMTAB 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" descriptions in Book I for details.

這些分節包含一個符號表。當前一個對象文件在每種類型都只有一個分節,但是這個限制可能在將來放鬆。

典型的,SHT_SYMTAB提供鏈接編輯的符號,雖然它也被用於動態鏈接。作爲一個完整的符號表,

它包含了許多動態鏈接中必要的符號。因此,一個對象文件也包含SHT_DYNSYM分節,

該分節包含一個爲節約空間的最小的動態鏈接符號集合。看卷I“符號表”中的細節描述。

SHT_STRTAB

An object file may have multiple string table sections. See "String Table'' in Book I for details.

一個對象文件可能含有多個字符串表分節。

SHT_HASH

All objects 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 Chapter 2 for details.

所有參與動態鏈接的對象必須包含一個符號哈希表。當前,一個對象文件值有一個哈希表,但是這個限制可能在將來被放鬆。看章節2“哈希表”中的細節。

SHT_DYNAMIC

Currently, an object file may have only one dynamic section, but this restriction may be relaxed in the future. See "Dynamic Section" in Chapter 2 for details.

當前,一個對象文件只有一個動態分節,但是這個限制可能在將來被放鬆。看章節2“動態分節”中的細節。



Two members in the section header, sh_link and sh_info, hold special information, depending on section type. A symbol table section's sh_info section header member holds the symbol table index for the first non-local symbol.
在這個分節頭中的2個成員sh_link和sh_info,包含特殊信息,依賴於分節類型。一個符號表分節的sh_info成員包含第一個非本地符號的符號表索引。

Figure 1-1. sh_link and sh_info Interpretation

圖1-1.sh_link和sh_info解釋

sh_type

sh_link

sh_info

SHT_SYMTAB

SHT_DYNSYM

The section header index of the 

associated string table.

關聯字符串表的分節頭索引

 

One greater than the symbol table index 

of the last local symbol (binding STB_LOCAL).

最後一個本地符號的符號表索引加1



Special Sections
特殊分節

The following sections hold program and control information used in UNIX System V Release 4. The sections in the list below are used by the system and have the indicated types and attributes. Most of these sections are required for the linking process. The information for dynamic linking is provided in the .dynsym, .dynstr, .interp, .hash, .dynamic, .rel, .rela, .got and .plt sections. The actual contents of some of these sections (.plt and .got, for example) are processor specific, but they all support the same linkage model.
以下分節包含UNIX System V Release 4使用的程序和控制信息,以下列表中的分節被系統使用,指明瞭類型和屬性。這些分節中的大多數都是被鏈接處理需要的。動態鏈接需要的信息在.dynsym, .dynstr, .interp, .hash, .dynamic, .rel, .rela, .got和.plt分節。這些分節(比如.plt和.got)中的一些的實際內容是處理器相關的,但是它們都支持相同的鏈接模型。


The .init and .fini sections contribute to the process initialization and termination code.
.init和.fini分節中有進程初始化和終結的代碼。

Figure 1-2. Special Sections

圖1-2.特殊分節

名字(Name)

類型(Type)

屬性(Attribute)

.dynstr

SHT_STRTAB

SHF_ALLOC

.dynsym

SHT_DYNSYM

SHF_ALLOC

.fini

SHT_PROGBITS

SHF_ALLOC + SHF_EXECINSTR

.init

SHT_PROGBITS

SHF_ALLOC + SHF_EXECINSTR

.interp

SHT_PROGBITS

see below

.relname

SHT_REL

see below

.relaname

SHT_RELA

see below



.dynstr

This section holds strings needed for dynamic linking, most commonly the strings 

that represent the names associated with symbol table entries. See Chapter 2 for more information.

此分節包含動態鏈接需要的字符串,最常見的字符串表示的名稱與符號表入口相關聯。看章節2獲取更多信息。

.dynsym

This section holds the dynamic linking symbol table, as "Symbol Table'' describes. See Chapter 2 for more information.

如“符號表”描述,此分節包含動態鏈接符號表。看章節2獲取更多信息。

.fini

This section holds executable instructions that contribute to the process termination code. 

When a program exits normally, the system executes the code in this section.

此分節包含程序結束時的可執行指令。當一個程序正常退出,系統會執行此分節的代碼。

.init

This section holds executable instructions that contribute to the process initialization code. 

When a program starts to run, the system executes the code in this section 

before calling the main program entry point (called main for C programs).

此分節包含程序初始化時的可執行指令。當程序開始運行,系統在調用程序入口點main之前執行這些代碼(C程序是調用的main)

.interp

This section holds the path name of a program interpreter. If the 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 Chapter 2 for more information.
此分節包含程序解釋器的路徑名。假如文件有一個包含分節的可加載的分段,分節的屬性會包含SHF_ALLOC位;

否則,該位會關閉。看章節2獲取更多信息。

.relname and .relaname

These sections hold relocation information, as "Relocation'' below describes. If the file has a loadable segment that includes relocation, 

the sections' attributes will include the SHF_ALLOC bit; otherwise, that bit will be off. Conventionally,

 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.
這些分節包含重定位信息,如下面“重定位”描述。假如文件有一個包含重定位的可加載的分段,

這個分節的屬性會包含SHF_ALLOC位;否則,該位會關閉。照慣例,名字由重定位申請的分節提供。

因此一個針對.text的重定位分節會使用名字.rel.text 或者.rela.text。




Symbol Table
符號表

st_name

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.

假如是非0值,它表示一個指向符號名的字符串表索引。否則,符號表入口沒有名字。


NOTE. External C symbols have the same names in C and object files' symbol tables.
注意:外部C符號在C和對象文件符號表中有相同的名字。


Function symbols (those with type STT_FUNC) in shared object files have special significance. When another object file references a function from a shared object, the link editor automatically creates a procedure linkage table entry for the referenced symbol. Shared object symbols with types other than STT_FUNC will not be referenced automatically through the procedure linkage table. See "Symbol Table" descriptions in Book I and "Function Addresses'' in the appendix at the end of this book for details.
函數符號(那些類型STT_FUNC指定的符號)在共享對象文件中有特殊的意義。當另外的對象文件從共享對象引用一個函數,鏈接編輯器自動爲引用符號創建一個過程鏈接表入口。除了STT_FUNC類型以外的共享對象符號不會通過過程鏈接表自動引用。看卷I“符號表”描述和本書末尾附錄“函數地址”以獲取更多細節。


Global and weak symbols differ in two major ways.
• When the link editor combines several relocatable object files, it does not allow multiple definitions of STB_GLOBAL symbols with the same name. On the other hand, if a defined global symbol exists, the appearance of a weak symbol with the same name will not cause an error. The link editor honors the global definition and ignores the weak ones. Similarly, if a common symbol exists (that is, a symbol whose st_shndx field holds SHN_COMMON), the appearance of a weak symbol with the same name will not cause an error. The link editor honors the common definition and ignores the weak ones.
• When the link editor searches archive libraries, it extracts archive members that contain definitions of undefined global symbols. The member's definition may be either a global or a weak symbol. The link editor does not extract archive members to resolve undefined weak symbols. Unresolved weak symbols have a zero value.
全局和弱符號主要在以下兩方面不同:

  • 當連接編輯器合併幾個重定向對象文件時,它不會允許多個STB_GLOBAL符號定義使用相同的名字。另一方面,假如定義的全局符號存在,一個使用相同名字弱符號不會導致錯誤。連接編輯器尊重全局定義並忽略弱符號。同樣,假如一個普通符號存在(就是說,一個st_shndx字段包含SHN_COMMON的符號),使用相同名字的弱符號出現也不會導致一個錯誤。連接編輯器尊重普通符號定義並忽略弱符號。
  • 當連接編輯器搜索歸檔庫時,針對未定義符號,它展開包含定義的歸檔成員。成員的定義可能是一個全局或弱符號。鏈接編輯器不會展開歸檔成員來解析未定義的弱符號。未解析的弱符號使用0值。

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