您的位置:首页 > 其它

工具接口标准(TIS)可执行链接格式(ELF)规范-卷III-操作系统特性-程序加载和动态链接(四)

2014-01-13 10:37 447 查看
本文是对Tool Interface Standard (TIS) Executable and Linking Format (ELF) Specification Version 1.2的翻译

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

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

Shared Object Dependencies

共享对象依赖


When the link editor processes an archive library, it extracts library members and copies them into the output object file. These statically linked services are available during execution without involving the dynamic linker. Shared objects also provide services,
and the dynamic linker must attach the proper shared object files to the process image for execution. Thus executable and shared object files describe their specific dependencies.

当连接编辑器处理一个归档库,它展开库成员并拷贝它们到输出对象文件。这些静态的链接服务在不涉及动态链接器的执行中是有效的。共享对象也提供服务,动态链接器必须附着到适当共享对象文件来处理执行映像。因此可执行和共享对象文件描述了它们特定的依赖。

When the dynamic linker creates the memory segments for an object file, the dependencies (recorded in DT_NEEDED entries of the dynamic structure) tell what shared objects are needed to supply the program's services. By repeatedly connecting referenced shared
objects and their dependencies, the dynamic linker builds a complete process image. When resolving symbolic references, the dynamic linker examines the symbol tables with a breadth-first search. That is, it first looks at the symbol table of the executable
program itself, then at the symbol tables of the DT_NEEDED entries (in order), then at the second level DT_NEEDED entries, and so on. Shared object files must be readable by the process; other permissions are not required.

当动态链接器为一个对象文件创建内存分段,依赖信息(记录在动态结构中的DT_NEEDED条目)会告诉那些共享对象是需要用来提供程序服务的。通过反复的链接引用的共享对象和它们的依赖对象,动态链接器建立一个完整的进程映像。当解析符号引用时,动态链接器通过宽度优先搜索检查符号表。就是说,它首先看可执行程序自身的符号表,然后依顺序检查DT_NEEDED条目,然后在第二级DT_NEEDED条目等。共享对象文件必须能够被进程读取;其它权限不是必须的。

NOTE. Even when a shared object is referenced multiple times in the dependency list, the dynamic linker will connect the object only once to the process.

注意:即使一个共享文件在依赖列表中被引用多次,动态链接器也只将其连接到进程一次。

Names in the dependency list are copies either of the DT_SONAME strings or the path names of the shared objects used to build the object file. For example, if the link editor builds an executable file using one shared object with a DT_SONAME entry of lib1 and
another shared object library with the path name /usr/lib/lib2, the executable file will contain lib1 and /usr/lib/lib2 in its dependency list.

依赖列表中的名字是拷贝自DT_SONAME字符串及用于建立对象文件的共享对象路径名。举例来说,假如链接编辑器使用一个有着DT_SONAME条目的共享对象lib1和另外一个路径名为/usr/lib/lib2的共享对象库建立一个可执行文件,这个可执行文件会包lib1和/usr/lib/lib2在它的依赖列表。

If a shared object name has one or more slash (/) characters anywhere in the name, such as /usr/lib/lib2 above or directory/file, the dynamic linker uses that string directly as the path name. If the name has no slashes, such as lib1 above, three facilities
specify shared object path searching, with the following precedence.

• First, the dynamic array tag DT_RPATH may give a string that holds a list of directories, separated by colons (:). For example, the string /home/dir/lib:/home/dir2/lib:tells the dynamic linker to search first the directory /home/dir/lib, then /home/dir2/lib,
and then the current directory to find dependencies.

• Second, a variable called LD_LIBRARY_PATH in the process environment [see exec(BA_OS)] may hold a list of directories as above, optionally followed by a semicolon (;) and another directory list. The following values would be equivalent to the previous example:

■ LD_LIBRARY_PATH=/home/dir/lib:/home/dir2/lib:

■ LD_LIBRARY_PATH=/home/dir/lib;/home/dir2/lib:

■ LD_LIBRARY_PATH=/home/dir/lib:/home/dir2/lib:;

All LD_LIBRARY_PATH directories are searched after those from DT_RPATH. Although some programs (such as the link editor) treat the lists before and after the semicolon differently, the dynamic linker does not. Nevertheless, the dynamic linker accepts the semicolon
notation, with the semantics described above.

• Finally, if the other two groups of directories fail to locate the desired library, the dynamic linker searches /usr/lib.

假如一个共享对象名有一个或多个斜线(/)字符在名字中出现,比如上述的/usr/lib/lib2或目录/文件,动态链接器使用该字符串直接作为路径名。假如名字没有斜线,比如上述的lib1,三个机制以下述的优先级指定了共享对象路径搜索方式:

第一,动态数组标签DT_RPATH可能给出了一个包含目录列表的字符串,通过冒号(:)分隔。比如,字符串/home/dir/lib:/home/dir2/lib:告诉动态链接器首先搜索目录/home/dir/lib,然后/home/dir2/lib,然后是当前目录来查找依赖。

第二,一个进程环境下的名为LD_LIBRARY_PATH的环境变量[看exec(BA_OS)]可能包含一个上述的目录列表,随后的分号(;)是可选的及其它的目录列表。以下值等同于前面的例子。

■ LD_LIBRARY_PATH=/home/dir/lib:/home/dir2/lib:

■ LD_LIBRARY_PATH=/home/dir/lib;/home/dir2/lib:

■ LD_LIBRARY_PATH=/home/dir/lib:/home/dir2/lib:;

所有的LD_LIBRARY_PATH目录是在DT_RPATH目录搜索之后被搜索。虽然一些程序(比如链接编辑器)处理分号前后的列表不同,但动态链接器不会。不过,动态链接器接受分号符号,使用上述的语义。

最后,假如其它2个目录分组定位需要的库失败时,动态链接器搜索目录

NOTE. For security, the dynamic linker ignores environmental search specifications (such as LD_LIBRARY_PATH) for set-user and set-group ID programs. It does, however, search DT_RPATH directories and /usr/lib. The same restriction may be applied to processes
that have more then minimal privileges on systems with installed extended security systems.

注意:为了安全,动态链接器对设置了用户和组ID的程序忽略环境搜索规范(比如LD_LIBRARY_PATH)。如果确实设置了,就只搜索DT_RPATH目录和/usr/lib。相同的限制会被应用来处理安装了扩展安全的系统

Global Offset Table

全局偏移表


The Global Offset Table holds the absolute addresses in private data. This makes it possible to have the addresses available without compromising the position-independence and sharability of program text. This table is essential in the System V environment
for the dynamic linking process to work. The actual contents and form of this table depend upon the processor, and are described in the appendix at the end of this book.

全局偏移表在私有数据中包含绝对地址。在没有妥协位置无关和共享的程序代码时,这使得它可能有可用的地址。这个表是在System V环境中为动态链接进程工作必不可少的。实际内容和表格式依赖于处理器,在本卷末尾的附录有描述。

Procedure Linkage Table

过程链接表


Similar to how the global offset table redirects position-independent address calculations to absolute locations, the procedure linkage table redirects position-independent function calls to absolute locations. The link editor cannot resolve execution transfers,
such as function calls, from one executable or shared object to another. Consequently, the link editor arranges to have the program transfer control to entries in the procedure linkage table. The actual contents, layout and location of the procedure linkage
table is determined by the processor and are described in the appendix at the end of this book.

与全局偏移表如何重定向位置无关地址运算到绝对位置类似,过程链接表重定向位置无关函数调用到绝对位置。链接编辑器不能解析执行转换,比如函数调用,从一个可执行或者共享对象到另一个。因此,链接编辑器安排程序传输控制到过程链接表条目。过程链接表的实际内容、布局和定位是由处理器决定的,在本卷末尾附录有描述。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐