工具接口標準(TIS)可執行鏈接格式(ELF)規範-卷I-符號表(Symbol Table)

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

This 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_NOTYPE

The 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_ABS

The 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.
雖然符號表取值對不同的對象文件有相同的意義,數據還是允許被適當的程序有效訪問。

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