全部博文(29)
分类: LINUX
2011-08-14 18:36:52
Executable files and shared library files are used to create a process
image when a program is started by the system.
This chapter describes the object file structures that relate to program
execution and also describes how the process image is created from
executable and shared object files.
当系统创建一个进程映像时会用到可执行文件和共享库,这章描述可执行文件的结构和进程映像是怎么从可执行文件和共享库中创建的。
This chapter addresses the following topics:
这章主要讨论一下几个话题
9.1 Object File Considerations目标文件的注意事项
The following sections describe several general factors that are
involved in the linking and loading process.
接下来几节描述装载和链接的几个因素
The following object file structures contain information that is used
in linking and loading operations:
装载和链接会用到下面几个目标文件结构
See for further details on file headers, optional headers, and section
headers.
详细描述第7章
Executable files and shared library files have a base address, which is
the lowest virtual address associated with the process image of the
program. The base address is used to relocate the process image
during dynamic linking.
可执行文件和共享库有个基址,基址是对应进程的最小虚拟地址,基址用在动态链接时重定位进程映像。
During program loading, the base address is calculated from the memory load address, the maximum page size, and the lowest virtual address of the program's loadable segment.
在程序装载时,基址是从内存装载地址,页面的最大值,程序可装载的最小的虚拟地址中计算而来的。
A program that is to be loaded by the system must have at least one
loadable segment, even though this is not required by the file format.
When the process image is created, the segments are assigned access
permissions, which are determined by the type of segment and type
of program image. shows the access permissions for the various segment and image types.
程序至少有一个可以装载的区段,虽然这不是文件格式所必须的,但是当进程被创建时,所有的段都要分配访问权限,由段的格式和程序的格式决定(具体参见表9-1)
Image | Segment | Access Permissions |
OMAGIC | text, data, bss | Read, Write, Execute |
NMAGIC | text | Read, Execute |
NMAGIC | data, bss | Read, Write, Execute |
ZMAGIC | text | Read, Execute |
ZMAGIC | data, bss | Read, Write, Execute |
上表可以看出镜像有3种格式OMAGIC,NMAGIC,ZMAGIC。
An object file segment can contain one or more sections. The number of sections in a segment is not important for program loading, but specific information must be present for linking and execution. illustrates typical segment contents for executable files and shared object files. The order of sections within a segment may vary.
目标文件可以包含一个或多个区段。程序装载时区段的数量不重要,但连接和执行是相关信息要说明,图9-1说明可执行文件和共享对象文件的典型段内容。段内的部分路段的顺序可能会有所不同
Text segments contain instructions and read-only data, and data
segments contain writable data. Text segments and data segments
typically include the sections shown in .
文本段包含指令和只读数据段,数据段包含可写数据。文本段和数据段通常包括在图9-1所示的部分。
9.2 Program Loading程序的装载
As the system creates or augments a process image, it logically copies a file's segment to a virtual memory segment. The time at which the system physically reads the file depends on the program's execution behavior, system load, and other factors. A process does not require a physical page unless it references the logical page during execution.
在该系统创建或扩充进程映像,它在逻辑上复制文件的段到虚拟内存段。在该系统物理上读取文件的时间取决于程序的执行行为,系统的负载,以及其他因素。一个进程并不需要一个物理页,除非它在执行过程中引用的逻辑页。
Processes commonly leave many pages unreferenced.
This improves system performance because delaying physical reads
frequently obviates them.
To obtain this efficiency in practice, shared executable files and
shared library files must have segment images whose virtual addresses
are zero, modulo the file system block size.
进程常常‘离开’未引用的许多页面。因为物理延时读取可以提高系统性能。要在实践中获得这种效率,共享的可执行文件和共享库文件段的虚拟地址必须都是零,模文件系统块大小的图像。(modulo the file system block size.)
Virtual addresses for the text and data segments must be aligned on
64KB (0x10000) or larger power of 2 boundaries. File offsets must be
aligned on 8KB (0x2000) or larger power of 2 boundaries.
文本段和数据段的虚拟地址必须是64KB或更大的2的边界边界上对齐。文件偏移量必须8KB或更大的2的边界边界上对齐。
Because the page size can be larger than the alignment restrictions of
a segment's file offset, up to seven file pages (depending on page
size)
can hold text or data that is not logically part of the segment.
The contents of the various file pages are as follows:
由于页面大小可以大于段的文件对齐偏移的限制,最多7个文件页(视页大小而定),文件页可容纳文本或数据段的一部分,是不合乎逻辑的。各种文件页面如下:
Logically, the system enforces the memory permissions as if each segment
were complete and separate; segment's addresses are adjusted to ensure
that each logical page in the address space has a single set of
permissions.
从逻辑上讲,系统要按照内存权限强制执行如果每个段是完整的和独立的,调整段的地址,以确保每个逻辑页在地址空间中有一个单一的权限设置。
The end of the data segment requires special handling for uninitialized
data, which must be set to zero. If a file's last data page includes
information not in the logical memory page, the extraneous data must
be set to zero, not the contents of the executable file.
数据段的结束处,需要特殊处理未初始化的数据,必须设置为零。如果最后一个数据页包括的信息不在逻辑内存页面,无关的数据,必须设置到零,而不是可执行文件的内容。
An executable file is loaded at fixed addresses; the system creates its segments using the virtual addresses from the optional header. The system transfers control directly to the entry point of the executable file.
一个可执行文件被加载在固定地址;系统利用可选头中使用虚拟地址创建它的段。系统将控制权转移直接指向可执行文件的入口点。
An executable file that uses dynamic linking requires one or more
shared libraries to be loaded in addition to the executable file. Instead of loading the executable file, the system loads the dynamic
loader, which in turn loads the executable file and its shared
libraries.
加载使用动态链接的可执行文件需要一个或多个共享库和可执行文件,装载可执行文件过程,加载系统装载器,在依次加载可执行文件和共享库。
When building an executable file that uses dynamic linking, the
linker adds the flag
F_MIPS_CALL_SHARED
to the
f_flags
field of the file header. This flag tells the system to invoke the
dynamic loader to load the executable file. Typically, the dynamic loader requested is
/sbin/loader,
the default loader.
The
exec
function and the dynamic loader cooperate to create the process image.
Creating the process image involves the following operations:
采用动态链接编译可执行文件时,链接器会将F_MIPS_CALL_SHARED标志加到f_flags文件头的字段。这个标志告诉系统调用动态加载器来加载可执行文件。通常情况下,默认动态加载器是/sbin/loader。 exec函数和动态加载器合作创建进程映像。创建过程如下:
To assist the dynamic loader, the linker also constructs the following
data items for shared library files and shared executable files:
要协助动态加载器,链接器还构建共享库文件和共享的可执行文件的以下数据项:
These data items are located in loadable segments and are available
during execution.
这些数据项都位于可装载的段,并在执行过程中可能会用到。
Shared library files may be located at virtual addresses that differ
from the addresses in the optional header.
The dynamic loader relocates the memory image and updates absolute
addresses before control is given to the program.
共享库文件的虚拟地址可能和可选头中定义的不一样。程序获得控制权前动态加载器会重定位内存映像和更新绝对地址。
If the environment variable
LD_BIND_NOW
has a non-null value, the dynamic loader processes all relocations
before transferring control to the program. The dynamic loader
may use the lazy binding technique to evaluate procedure linkage
table entries, avoiding symbol resolution and relocation for functions
that are not called.(See for information about lazy binding.)
如果环境变量LD_BIND_NOW有一个非空值,动态加载在将控制权交给程序之前执行所有重定位,动态加载器可能会使用延迟绑定技术评估链接表项的过程,避免对不调用的函数的符号解析和重定位。 (延迟绑定的信息,请参见9.3.3.1节。)
The following sections describe the various dynamic linking sections. The C language definitions are in the header files elf_abi.h and elf_mips.h.
以下各节描述的各种动态链接部分。 C语言定义在头文件中elf_abi.h和elf_mips.h的。
9.3.2 Dynamic Section (.dynamic)
The dynamic section acts as a table of contents for dynamic linking
information within the object. Dynamic sections
are present only in shared executable files and shared library files.
动态节是动态链接信息表的表内对象。动态节目前仅在共享的可执行文件和共享库文件。
The dynamic section is located by its section header. This section
header is identified by its name
(.dynamic)
or its section type
(STYP_DYNAMIC)
in the flags field
(s_flags).
动态节是位于其节头。此节头是由它的名字(.dynamic)或其部分类型的标志字段(STYP_DYNAMIC)(s_flags)确定。
The dynamic section is an array with entries of the following type:
动态节类型:
The structure and union members in the preceding structure definition
provide the following information:
结构和联盟成员的相关信息
d_tag Indicates how the d_un field is to be interpreted.
d_ptr 表示程序的虚拟地址。在执行的过程中,文件的虚拟地址可能与内存的虚拟地址不匹配。动态加载器在内存基地址和文件的虚拟地址基础上计算出实际地址。在动态节中,对象文件不包含正确的地址重定位项。
The d_tag requirements for shared executable files and shared library files are summarized in . "Mandatory" indicates that the dynamic linking array must contain an entry of that type; "optional" indicates that an entry for the tag may exist but is not required.
d_tag所需要的共享可执行文件和共享库文件的要求总结在表9-2。 “强制性”表明动态链接数组必须包含该类型的条目,“可选”表示,标签的条目可能存在,但不是必需的。
Name | Value | d_un | Executable | Shared Object |
DT_NULL | 0 | ignored | mandatory | mandatory |
DT_NEEDED | 1 | d_val | optional | optional |
DT_PLTRELSZ[Table Note 1] | 2 | d_val | optional | optional |
DT_PLTGOT | 3 | d_ptr | optional | optional |
DT_HASH | 4 | d_ptr | mandatory | mandatory |
DT_STRTAB | 5 | d_ptr | mandatory | mandatory |
DT_SYMTAB | 6 | d_ptr | mandatory | mandatory |
DT_RELA[Table Note 1] | 7 | d_ptr | mandatory | optional |
DT_RELASZ[Table Note 1] | 8 | d_val | mandatory | optional |
DT_RELAENT[Table Note 1] | 9 | d_val | mandatory | optional |
DT_STRSZ | 10 | d_val | mandatory | mandatory |
DT_SYMENT | 11 | d_val | mandatory | mandatory |
DT_INIT | 12 | d_ptr | optional | optional |
DT_FINI | 13 | d_ptr | optional | optional |
DT_SONAME | 14 | d_val | ignored | optional |
DT_RPATH | 15 | d_val | optional | ignored |
DT_SYMBOLIC | 16 | ignored | ignored | optional |
DT_REL | 17 | d_ptr | mandatory | optional |
DT_RELSZ | 18 | d_val | mandatory | optional |
DT_RELENT | 19 | d_val | mandatory | optional |
DT_PLTREL[Table Note 1] | 20 | d_val | optional | optional |
DT_DEBUG[Table Note 1] | 21 | d_ptr | optional | ignored |
DT_TEXTREL[Table Note 1] | 22 | ignored | optional | optional |
DT_JMPREL[Table Note 1] | 23 | d_ptr | optional | optional |
DT_LOPROC | 0x70000000 | unspecified | unspecified | unspecified |
DT_HIPROC | 0x7fffffff | unspecified | unspecified | unspecified |
Table Notes:
Table 9-3: Processor-Specific Dynamic Array Tags (d_tag)
Name | Value | d_un | Executable | Shared Object |
DT_MIPS_RLD_VERSION | 0x70000001 | d_val | mandatory | mandatory |
DT_MIPS_TIME_STAMP | 0x70000002 | d_val | optional | optional |
DT_MIPS_ICHECKSUM | 0x70000003 | d_val | optional | optional |
DT_MIPS_IVERSION | 0x70000004 | d_val | optional | optional |
DT_MIPS_FLAGS | 0x70000005 | d_val | mandatory | mandatory |
DT_MIPS_BASE_ADDRESS | 0x70000006 | d_ptr | mandatory | mandatory |
DT_MIPS_CONFLICT | 0x70000008 | d_ptr | optional | optional |
DT_MIPS_LIBLIST | 0x70000009 | d_ptr | optional | optional |
DT_MIPS_LOCAL_GOTNO | 0x7000000A | d_val | mandatory | mandatory |
DT_MIPS_CONFLICTNO | 0x7000000B | d_val | optional | optional |
DT_MIPS_LIBLISTNO | 0x70000010 | d_val | optional | optional |
DT_MIPS_SYMTABNO | 0x70000011 | d_val | optional | optional |
DT_MIPS_UNREFEXTNO | 0x70000012 | d_val | optional | optional |
DT_MIPS_GOTSYM | 0x70000013 | d_val | mandatory | mandatory |
DT_MIPS_HIPAGENO[Table Note 1] | 0x70000014 | d_val | mandatory | mandatory |
Table Notes:
The uses of the various processor-specific dynamic array tags are as follows:
DT_MIPS_RLD_VERSION Holds an index into the object file's string table, which holds the version of the run-time linker interface. The version is 1 for executable objects that have a single GOT and 2 for executable objects that have multiple GOTs.
Flag | Value | Meaning |
RHF_QUICKSTART | 0x00000001 | Object may be quickstarted by loader |
RHF_NOTPOT | 0x00000002 | Hash size not a power of two |
RHF_NO_LIBRARY_REPLACEMENT | 0x00000004 | Use default system libraries only |
RHF_NO_MOVE | 0x00000008 | Do not relocate |
RHF_RING_SEARCH | 0x10000000 | Symbol resolution same as DT_SYMBOLIC |
RHF_DEPTH_FIRST | 0x20000000 | Depth first symbol resolution |
RHF_USE_31BIT_ADDRESSES | 0x40000000 | TASO (Truncated Address Support Option) objects |
All other tag values are reserved. Entries may appear in any order, except for the relative order of the DT_NEEDED entries and the DT_NULL entry at the end of the array.
9.3.2.1 Shared Object DependenciesWhen the linker processes an archive library, library members are extracted and copied into the output object file. These statically linked services are available during execution and do not involve the dynamic loader. Shared executable files also provide services that require the dynamic loader to include the appropriate shared library files in the process image. To accomplish this, shared executable files and shared library files must describe their dependencies.
当链接器处理归档库,库成员被提取并复制到输出目标文件。这些静态链接的服务是在执行过程中有效,不涉及动态加载器。在进程映像里共享的可执行文件提供的服务需要动态加载器加载适当的共享库文件。而要做到这一点,共享的可执行文件和共享库文件必须描述他们的依赖关系。
The dependencies, indicated by the DT_NEEDED entries of the dynamic structure, indicate which shared library files are required for the program. The dynamic loader builds a process image by connecting the referenced shared library files and their dependencies. When resolving symbolic references, the dynamic loader looks first at the symbol table of the shared executable program, then at the symbol tables of the DT_NEEDED entries (in order), then at the second-level DT_NEEDED entries, and so on. Shared library files must be readable by the process.
依赖关系由dynamic结构的DT_NEEDED项表明,表明程序需要哪些共享库文件。动态加载器建进程映像需要连接相应的共享库文件和它们的依赖关系,解析符号引用时,动态装载器首先查找共享的可执行程序的符号表,然后在符号表的DT_NEEDED项(按顺序),然后在第二级的DT_NEEDED项,依此类推。共享库文件必须是可读的过程。
Note
Even if a shared object is referenced more than once in the dependency list, the dynamic loader includes only one instance of the object in the process image.
即使一个共享对象的依赖列表中不止一次被引用,创建进程时动态加载程序只包含对象的一个实例。
Names in the dependency list are copies of the DT_SONAME strings.
依赖列表中的名称是DT_SONAME字符串。
If a shared library name has one or more slash characters in its name, such as /usr/lib/libz, the dynamic loader uses the string as the pathname. If the name has no slashes, such as liba, the object is searched as follows:
如果共享库的名称有一个或多个斜杠字符在其名称,如/usr/lib/LIBZ,动态加载器使用的路径名的字符串。如果这个名字已经没有斜线,如liba,搜索对象如下:
The dynamic array tag DT_RPATH may give a string that holds a list of directories separated by colons, such as
DT_RPATH可能是字符串,冒号隔开
/usr/newlib:/usr/local/lib. The dynamic loader searches these directories in order and, if a library is not located, it then searches the current directory.
动态加载器按顺序搜索这些路径,如果还没有,搜索当前目录
The environment variable LD_LIBRARY_PATH can hold a list of colon-separated directories, optionally followed by a semicolon and another directory list. These directories are searched after those specified by DT_RPATH.
DT_PATH搜索完以后还会搜索环境变量LD_LIBRARY_PATH的路径
If the library was not located in any of the directories specified by DT_RPATH or LD_LIBRARY_PATH, the dynamic loader searches /usr/shlib, /usr/ccs/lib, /usr/lib/cmplrs/cc, /usr/lib, and then /usr/local/lib.
如果还没有找到动态加载器会搜索/usr/shlib,/usr/ccs/lib,/usr/lib/cmplrs/cc, /usr/lib, /usr/local/lib.
The following environment variables are defined:
_RLD_ARGS | Argument to dynamic loader |
_RLD_ROOT |
Prefix that the dynamic loader adds to all paths except those specified by LD_LIBRARY_PATH |
Note
For security, the dynamic loader ignores environmental search specifications, such as LD_LIBRARY_PATH, for set-user-ID and set-group-ID programs.
出于安全考虑,动态加载器忽略环境变量的路径搜索。
9.3.3 Global Offset Table (.got)
Position-independent code cannot contain absolute virtual addresses. Global offset tables (GOTs) hold absolute addresses in private data, thus making the addresses available without compromising the position-independence and sharability of a program's text. A program references its global offset table using position-independent addressing and extracts absolute values, thus redirecting position-independent references to absolute locations.
位置无关的代码不能包含绝对虚拟地址,全局偏移表(GOTS)里存放数据的绝对地址,从而使得地址不影响程序的文本的位置独立性和共享性。程序通过对全局偏移表地址和位置无关的地址提取绝对值,从而重定向到绝对位置的位置无关的引用。
The global offset table is split into two logically separate subtables - local and external:
全局偏移表被分成两个逻辑上独立的子表 - 本地和扩展全局偏移表:
The external entries for defined symbols must contain actual addresses. If an entry corresponds to an undefined symbol and the table entry contains a zero, the entry must be resolved by the dynamic loader, even if the dynamic loader is performing a quickstart. (See for information about quickstart processing.)
扩展项定义的符号必须包含真实地址,如果一个扩展项对应了一个未定义的符号或者扩展项有包含0,该项必须被动态加载器解析,动态加载器执行的是快速启动。(快速启动详见9.3.10)
After the system creates memory segments for a loadable object file, the dynamic loader may process the relocation entries. The only relocation entries remaining are type R_REFQUAD or R_REFLONG, referring to local entries in the GOT and data items containing addresses. The dynamic loader determines the associated symbol (or section) values, calculates their absolute addresses, and sets the proper values. Although the absolute addresses may be unknown when the linker builds an object file, the dynamic loader knows the addresses of all memory segments and can find the correct symbols and calculate the absolute addresses.
If a program requires direct access to the absolute address of a symbol, it uses the appropriate GOT entry. Because the shared executable file and shared library file have separate global offset tables, a symbol's address may appear in several tables. The dynamic loader processes all necessary relocations before giving control to the process image, thus ensuring the absolute addresses are available during execution.
The zero (first) entry of the .dynsym section is reserved and holds a null symbol table entry. The corresponding zero entry in the GOT is reserved to hold the address of the entry point in the dynamic loader to call when using lazy binding to resolve text symbols (see for information about resolving text symbols using lazy binding).
The system may choose different memory segment addresses for the same shared library file in different programs; it may even choose different library addresses for different executions of the same program. Nonetheless, memory segments do not change addresses once the process image is established. As long as a process exists, its memory segments reside at fixed virtual addresses.
A single GOT can hold a maximum of 8190 local and global entries. If a program references 8K or more global symbols, it will have multiple GOTs. Each GOT in a multiple-GOT object is referenced by means of a different global pointer value. A single .got section holds all of the GOTs in a multiple-GOT object.
一个.GOT,最多可容纳8190本地项和全局项。如果某个程序引用8K或多个全局项,它将会产生个multiple-GOT。对单个.got引用通过全局指针值,A single got section holds all of the GOTs in a multiple-GOT object.
The DT_MIPS_LOCAL_GOTNO and DT_PLTGOT entries of the dynamic section describe the attributes of the global offset table.
.dynamic节的DT_MIPS_LOCAL_GOTNO和DT_PLTGOT描述全局偏移表的属性
The GOT is used to hold addresses of position-independent functions as well as data addresses. It is not possible to resolve function calls from one shared executable file or shared library file to another at static link time, so all of the function address entries in the GOT would normally be resolved at run time by the dynamic loader. Through the use of specially constructed pieces of code known as stubs, this run-time resolution can be deferred through a technique known as lazy binding.
Using the lazy binding technique, the linker builds a stub for each called function and allocates GOT entries that initially point to the stubs. Because of the normal calling sequence for position-independent code, the call invokes the stub the first time that the call is made.
The stub code loads register t12 with an entry from the GOT. The entry loaded into register t12 is the address of the procedure in the dynamic loader that handles lazy binding. The stub code also loads register $at with the index into the .dynsym section of the referenced external symbol. The code then transfers control to the dynamic loader and loads register t12 with the address following the stub. The dynamic loader determines the correct address for the called function and replaces the address of the stub in the GOT with the address of the function.
Most undefined text references can be handled by lazy text evaluation, except when the address of a function is used in other than a jsr instruction. In the exception case, the program uses the address of the stub instead of the actual address of the function. Determining which case is in effect is based on the following processing:
The LD_BIND_NOW environment variable can also change dynamic loader behavior. If its value is non-null, the dynamic loader evaluates all symbol-table entries of type STT_FUNC, replacing their stub addresses in the GOT with the actual address of the referenced function.
Note
Lazy binding generally improves overall application performance because unused symbols do not incur the dynamic loader overhead. Two situations, however, make lazy binding undesirable for some applications:
- The initial reference to a function in a shared object file takes longer than subsequent calls because the dynamic loader intercepts the call to resolve the symbol. Some applications cannot tolerate this unpredictability.
- If an error occurs and the dynamic loader cannot resolve the symbol, the dynamic loader terminates the program. Under lazy binding, this might occur at arbitrary times. Once again, some applications cannot tolerate this unpredictability.
By turning off lazy binding, the dynamic loader forces the failure to occur during process initialization, before the application receives control.
9.3.4 Dynamic Symbol Section (.dynsym)
The dynamic symbol section provides information on all external symbols, either imported or exported from an object.
All externally visible symbols, both defined and undefined, must be hashed into the hash table (see).
Undefined symbols of type STT_FUNC that have been referenced only by jsr instructions may contain nonzero values in their st_value field denoting the stub address used for lazy evaluation for this symbol. The dynamic loader uses this to reset the GOT entry for this external symbol to its stub address when unloading a shared library file. All other undefined symbols must contain zero in their st_value fields.
Defined symbols in a shared executable file cannot be preempted. The symbol table in the shared executable file is always searched first to resolve any symbol references.
The dynamic symbol section contains an array of entries of the
following type:
The structure members in the preceding structure definition provide the following information:
st_name Contains the offset of the symbol's name in the dynamic string section.
A symbol's binding determines the linkage visibility and behavior. The binding is encoded in the st_info field and can have one of the following values:
Value | Description |
STB_LOCAL | Indicates that the symbol is local to the object. |
STB_GLOBAL | Indicates that the symbol is visible to other objects. |
STB_WEAK | Indicates that the symbol is a weak global symbol. |
STB_DUPLICATE | Indicates the symbol is a duplicate. (Used for objects that have multiple GOTs.) |
A symbol's type identifies its use. The type is encoded in the st_info field and can have one of the following values:
Value | Description |
STT_NOTYPE | Indicates that the symbol has no type or its type is unknown. |
STT_OBJECT | Indicates that the symbol is a data object. |
STT_FUNC | Indicates that the symbol is a function. |
STT_SECTION | Indicates that the symbol is associated with a program section. |
STT_FILE | Indicates that the symbol as the name of a source file. |
All symbols are defined relative to some program section. The st_shndx field identifies the section and can have one of the following values:
Value | Description |
SHN_UNDEF | Indicates that the symbol is undefined. |
SHN_ABS | Indicates that the symbol has an absolute value. |
SHN_COMMON | Indicates that the symbol has common storage (unallocated). |
SHN_MIPS_ACOMMON | Indicates that the symbol has common storage (allocated). |
SHN_MIPS_TEXT | Indicates that the symbol is in a text segment. |
SHN_MIPS_DATA | Indicates that the symbol is in a data segment. |
The entries of the dynamic symbol section are ordered as follows:
shows the layout of the .dynsym section and its relationship to the .got section.
Figure 9-2: Relationship Between .dynsym and .got
The DT_SYMENT and DT_SYMTAB entries of the dynamic section describe the attributes of the dynamic symbol table.
.dynamic节的DT_SYMENT和DT_SYMTAB条目描述了动态符号表中的属性。
The dynamic relocation section describes all locations within the object that must be adjusted if the object is loaded at an address other than its linked base address.
.rel.dyn节描述的是调整的对象,这些对象是加载在其链接的基地址以外的。
Only one dynamic relocation section is used to resolve addresses in data items, and it must be called .rel.dyn. Shared executable files can contain normal relocation sections in addition to a dynamic relocation section. The normal relocation sections may contain resolutions for any absolute values in the main program. The dynamic linker does not resolve these or relocate the main program.
只有一个.rel.dyn节是用来解析数据项的地址,并且它必须调用.rel.dyn。共享的可执行文件除了包含普通的重定位节还包含动态的重定位节。The normal relocation sections may contain resolutions for any absolute values in the main program。动态链接器不解析这些或重定位主要代码。
As noted previously, only R_REFQUAD and R_REFLONG relocation entries are supported in the dynamic relocation section.
如前所述,只有R_REFQUAD和R_REFLONG重定位项被支在.rel.dyn。
The dynamic relocation section is an array of entries of the following type:
.rel.dyn节类型如下
The structure members in the preceding structure definition provide the following information:
在前面的结构定义结构成员提供下列信息:
r_offset Identifies the location within the object to be adjusted.
The entries of the dynamic relocation section are ordered by symbol index value.
.rel.dyn节中的项是符号索引值进行排列
The DT_REL and DT_RELSZ entries of the dynamic section describe the attributes of the dynamic relocation section.
.dynamic节的DT_REL和DT_RELSZ描述.rel.dyn节的属性
9.3.6 Msym Section (.msym)The optional .msym section contains precomputed hash values and dynamic relocation indexes for each entry in the dynamic symbol table. Each entry in the .msym section maps directly to an entry in the .dynsym section. The .msym section is an array of entries of the following type:
The structure members in the preceding structure definition provide the following information:
ms_hash_value The hash value computed from the name of the corresponding dynamic symbol.
The dynamic relocation index identifies the first entry in the .rel.dyn section that references the dynamic symbol corresponding to this msym entry. If the index is 0, no dynamic relocations are associated with the symbol.
The symbol flags field is reserved for future use.
The DT_MIPS_MSYM entry of the dynamic section contains the address of the .msym section.
9.3.7 Hash Table Section (.hash)A hash table of Elf32_Word entries provides fast access to symbol entries in the dynamic symbol section. shows the contents of a hash table.
Figure 9-3: Hash Table Section
The entries in the hash table contain the following information:
The hashing function accepts a symbol name and returns a value that can be used to compute a bucket index. If the hashing function returns the value X for a name, bucket[X % nbucket] gives an index, Y, into the symbol table and chain array. If the symbol table entry indicated is not the correct one, chain[Y] indicates the next symbol table entry with the same hash value. The chain links can be followed until the correct symbol table entry is located or until the chain entry contains the value STN_UNDEF.
The DT_HASH entry of the dynamic section contains the address of the hash table section.
9.3.8 Dynamic String Section (.dynstr)The dynamic string section is the repository for all strings referenced by the dynamic linking sections. Strings are referenced by using a byte offset within the dynamic string section. The end of the string is denoted by a byte containing the value zero.
The DT_STRTAB and DT_STRSZ entries of the dynamic section describe the attributes of the dynamic string section.
9.3.9 Initialization and Termination Functions
After the dynamic loader has created the process image and performed
relocations, each shared object file gets the opportunity to execute
initialization code.
The initialization functions are called in
reverse-dependency order.
Each shared object file's initialization functions are called
only after
the initialization functions for its dependencies have been executed.
All initialization of shared object files occurs
before the executable file gains control.
Similarly, shared object files can have termination functions that are executed by the atexit mechanism when the process is terminating. Termination functions are called in dependency order - the exact opposite of the order in which initialization functions are called.
Shared object files designate initialization and termination functions through the DT_INIT and DT_FINI entries in the dynamic structure. Typically, the code for these functions resides in the .init and .fini sections.
Note
Although atexit termination processing normally is done, it is not guaranteed to have executed when the process terminates. In particular, the process does not execute the termination processing if it calls _exit or if the process terminates because it received a signal that it neither caught nor ignored.
9.3.10 Quickstart
The quickstart capability provided by the assembler supports several sections that are useful for faster startup of programs that have been linked with shared library files. Some ordering constraints are imposed on these sections. The group of structures defined in these sections and the ordering constraints allow the dynamic loader to operate more efficiently. These additional sections are also used for more complete dynamic shared library file version control.
9.3.10.1 Shared Object List (.liblist)A shared object list section is an array of Elf32_Lib structures that contains information about the various dynamic shared library files used to statically link the shared object file. Each shared library file used has an entry in the array. Each entry has the following format:
The structure members in the preceding structure definition provide
the following information:
The l_flags field can have one or both of the following flags set:
LL_EXACT_MATCH | At run time, use a unique ID composed of the l_time_stamp, l_checksum, and l_version fields to demand that the run-time dynamic shared library file match exactly the shared library file used at static link time. |
LL_IGNORE_INT_VER |
At run time, ignore any version incompatibility between
the dynamic shared library file and the shared library file used at
static link time.
Normally, if neither LL_EXACT_MATCH nor LL_IGNORE_INT_VER bits are set, the dynamic loader requires that the version of the dynamic shared library match at least one of the colon separated version strings indexed by the l_version string table index. |
The DT_MIPS_LIBLIST and DT_MIPS_LIBLISTNO entries of the dynamic section describe the attributes of the shared object list section.
9.3.10.2 Conflict Section (.conflict)Each .conflict section is an array of indexes into the .dynsym section. Each index entry identifies a symbol that is multiply defined in either of the following ways:
The shared library files that the shared object file depends on are identified at static link time.
The symbols identified in this section must be resolved by the dynamic loader, even if the object is quickstarted. The dynamic loader resolves all references of a multiply-defined symbol to a single definition.
The .conflict section is an array of Elf32_Conflict elements:
The DT_MIPS_CONFLICT and DT_MIPS_CONFLICTNO entries of the dynamic section describe the attributes of the conflict section.
9.3.10.3 Ordering of Sections
In order to take advantage of the quickstart capability, ordering
constraints are imposed on the
.rel.dyn
section.
The
.rel.dyn
section must have all local entries first, followed by the external
entries. Within these subsections, the entries must be ordered
by symbol index. This groups each symbol's relocations together.