工具接口标准(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值。

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