您的位置:首页 > 其它

工具接口标准(TIS)可执行链接格式(ELF)规范-卷I-符号表(Symbol Table)

2014-01-06 17:50 696 查看
本文是对Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2的翻译

工具接口标准(TIS)可执行链接格式(ELF)规范版本 1.2

翻译以中英对照方式,英语水品有限,如有翻译不当的地方,请谅解。

Symbol Table

符号表


An object file's symbol table holds information needed to locate and relocate a program's symbolic definitions and references. A symbol table index is a subscript into this array. Index 0 both designates the first entry in the table and serves as the undefined
symbol index. The contents of the initial entry are specified later in this section.

对象文件的符号表包含需要被定位和重定位的信息(程序符号定义和引用),一个符号表索引是这个数组的下标。索引0指定了表的第一个入口,充当未定义符号索引。这个初始化入口的内容会在本节后面部分指定。

名字(Name)值(Value)
STN_UNDEF
0
A symbol table entry has the following format.

一个符号表入口有以下格式

Figure 1-15. Symbol Table Entry

图1-15.符号表入口


typedef struct {

Elf32_Word st_name;

Elf32_Addr st_value;

Elf32_Word st_size;

unsigned char st_info;

unsigned char st_other;

Elf32_Half st_shndx;

} Elf32_Sym;

st_nameThis member holds an index into the object file's symbol string table, which holds the character representations of the symbol names.

此成员包含一个对象文件符号字符串表的索引,对象文件符号字符串表包含符号名的字符表达。

st_value

This member gives the value of the associated symbol. Depending on the context, this may be an absolute value,

an address, and so on; details appear below.

此成员给出关联符号的值。依赖于上下文,此值可能是一个绝对值、一个地址等;细节会在后面定义。

st_size

Many symbols have associated sizes. For example, a data object's size is the number of bytes contained in the object.

This member holds 0 if the symbol has no size or an unknown size.

许多符号都有关联大小。比如,一个数据对象大小是该对象包含的字节数。此成员在符号没有大小或者大小未知的情况下为0。

st_info

This member specifies the symbol's type and binding attributes. A list of the values and meanings appears below.

The following code shows how to manipulate the values.

此成员指定符号类型和绑定属性。取值和意思的列表在后面定义。下面的代码介绍了如何操作该成员的值。

#define ELF32_ST_BIND(i) ((i)>>4)

#define ELF32_ST_TYPE(i) ((i)&0xf)

#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))

st_other

This member currently holds 0 and has no defined meaning.

此成员当前没有定义,被默认置0。

st_shndx

Every symbol table entry is "defined'' in relation to some section; this member holds the relevant section header table index.

As Figure 1-7 and the related text describe, some section indexes indicate special meanings.

每个符号表入口定义了和某个分节的关系;此成员包含相关的分节头表索引。像图1-7以及相关文字描述的一样,

某些分节索引指明了特殊的含义。

A symbol's binding determines the linkage visibility and behavior.

一个符号的绑定决定了链接的可见性和行为。

Figure1-16. Symbol Binding, ELF32_ST_BIND

图1-16.符号绑定,ELF32_ST_BIND

名字(Name)
值(Value)
STB_LOCAL
0
STB_GLOBLE
1
STB_WEAK
2
STB_LOPROC
13
STB_HIPROC
15
STB_LOCAL

Local symbols are not visible outside the object file containing their definition. Local symbols of the same name may exist in multiple files without interfering with each other.

本地符号在包含其定义的对象文件外是不可见的。在不同的文件中同名的本地符号是不会相互干扰的。

STB_GLOBAL

Global symbols are visible to all object files being combined. One file's definition of a global symbol will satisfy another file's undefined reference to the same global symbol.

全局符号在所有需要被组合的对象文件中都是可见的。一个文件的全局符号定义可以满足另一个文件中未定义的同名全局符号引用。

STB_WEAK

Weak symbols resemble global symbols, but their definitions have lower precedence.

弱符号像全局符号,但它们的定义具有低优先级。

STB_LOPROC through STB_HIPROC

Values in this inclusive range are reserved for processor-specific semantics.

在此范围内的值为处理器特定语义保留

In each symbol table, all symbols with STB_LOCAL binding precede the weak and global

symbols. A symbol's type provides a general classification for the associated entity.

在每个符号表,所有的本地符号绑定优先于弱符号和全局符号。符号类型提供普通的关联入口分类。

Figure1-17. Symbol Types, ELF32_ST_TYPE

图1-17.符号类型,ELF32_ST_TYPE

名字(Name)
值(Value)
STT_NOTYPE
0
STT_OBJECT
1
STT_FUNC
2
STT_SECTION
3
STT_FILE
4
STT_LOPROC
13
STT_HIPROC
15
STT_NOTYPEThe symbol's type is not specified.

未定义的符号类型

STT_OBJECT

The symbol is associated with a data object, such as a variable, an array, and so on.

关联数据对象的符号,比如一个变量、一个数组等。

STT_FUNC

The symbol is associated with a function or other executable code.

关联函数或其他可执行代码的符号。

STT_SECTION

The symbol is associated with a section. Symbol table entries of this type exist primarily for relocation and normally have STB_LOCAL binding.

关联一个分节的符号。此类型的符号表入口主要为重定位存在,有着本地绑定的属性。

STT_LOPROC through STT_HIPROC

Values in this inclusive range are reserved for processor-specific semantics.

If a symbol's value refers to a specific location within a section, its section index member,

st_shndx, holds an index into the section header table. As the section moves during relocation,

the symbol's value changes as well, and references to the symbol continue to "point'' to

the same location in the program. Some special section index values give other semantics.

此范围的值为处理器特定语义保留。假如一个符号值涉及一个分节中的指定位置,

它的分节索引成员st_shndx包含此分节头表的索引。当分节在重定向中移动时,符号值也随之变化,

并且符号引用继续指向程序中的相同定位。一些特殊的分节索引值有其它的语义。

STT_FILE

A file symbol has STB_LOCAL binding, its section index is SHN_ABS,

and it precedes the other STB_LOCAL symbols for the file, if it is present.

一个文件符号有着本地绑定的属性,它的分节索引是SHN_ABS,并且它优先于针对该文件的其它的本地符号。

The symbols in ELF object files convey specific information to the linker and loader. See the

operating system sections for a description of the actual linking model used in the system.

ELF对象文件中的符号传达特定信息给链接器和加载器。在操作系统章节中有系统实际使用的链接模型的描述。

SHN_ABSThe symbol has an absolute value that will not change because of relocation.

此符号包含一个不会因为重定位改变的绝对值。

SHN_COMMON

The symbol labels a common block that has not yet been allocated. The symbol's value gives alignment constraints,

similar to a section's sh_addralign member. That is, the link editor will allocate the storage for the symbol at an address

that is a multiple of st_value. The symbol's size tells how many bytes are required.

此符号标记着一个还没有被申请的通用块。此符号值给出了对其限制,就像分节中的sh_addralign成员。

因此,链接编辑器会在一个st_value整数倍的地址处申请此变量的存储空间。此符号大小告诉了所需的字节数大小。

SHN_UNDEF

This section table index means the symbol is undefined. When the link editor combines this object file

with another that defines the indicated symbol, this file's references to the symbol will be linked to the actual definition.

这个分节表索引意味着符号未定义。当链接编辑器将这个对象文件和另一个定义了这个符号的对象文件组合时,

这个符号在文件中的引用将被链接到实际的定义。

As mentioned above, the symbol table entry for index 0 (STN_UNDEF) is reserved; it holds the

following.

就像上面提到的,索引0的符号表入口是被保留的;包含以下内容

Figure1-18. Symbol Table Entry: Index 0

图1-13.特殊分节

名字(Name)
值(Value)
注解(Note)
st_name
0
没有名字
st_value
0
0
st_size
0
没有大小
st_info
0
没有类型,本地绑定
st_other
0
st_shndx
SHN_UNDEF
没有分节
Symbol Values

符号值


Symbol table entries for different object file types have slightly different interpretations for the st_value member.

• In relocatable files, st_value holds alignment constraints for a symbol whose section index is SHN_COMMON.

• In relocatable files,st_value holds a section offset for a defined symbol. That is, st_value is an offset from the beginning of the section that st_shndx identifies.

• In executable and shared object files, st_value holds a virtual address. To make these files' symbols more useful for the dynamic linker, the section offset (file interpretation) gives way to a virtual address (memory interpretation) for which the section
number is irrelevant.

不同对象文件类型的符号表入口对st_value成员的有细微的差别。

在重定位文件,分节索引为SHN_COMMON的符号的st_value有对齐约束;
在重定位文件,一个定义的符号的st_value包含分节偏移。因此,st_value是从st_shndx标识的分节开始处计算的偏移;
在可执行文件盒共享对象文件,st_value包含一个虚拟地址。为了使文件符号在动态链接器中更有用,分节偏移(文件解释)为了分节号无关让步于虚拟地址(内存解释)。

Although the symbol table values have similar meanings for different object files, the data

allow efficient access by the appropriate programs.

虽然符号表取值对不同的对象文件有相同的意义,数据还是允许被适当的程序有效访问。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: