How To Write Shared Libraries(13)

1.5.4 Lookup Scope(1)

The lookup scope has so far been described as an ordered list of most loaded object. While this is correct it has also been intentionally vague. It is now time to explain the lookup scope in more detail.
加载过程中查找范围一直被描述为一个有序列表。如果有意模糊可以这样理解。现在该详细分析了。

The lookup scope consists in fact of up to three parts. The main part is the global lookup scope. It initially consists of the executable itself and all its dependencies. The dependencies are added in breadth-first order. That means first the dependencies of the executable are added in the order of their DT NEEDED entries in the executable’s dynamic section. Then the dependencies of the first dependency are added in the same fashion. DSOs already loaded are skipped; they do not appear more than once on the list. The process continues recursively and it will stop at some point since there are only a limited number of DSOs available. The exact number of DSOs loaded this way can vary widely. Some executables depend on only two DSOs, others on 200.
查找表实际分3部分。主要是全局查找表。它通过程序本身和所有的依赖初始化。通过广度优先增加内容。这也意味着第一额增加的是动态段内容。依赖的内容以同样的方式添加。DSO已经加载跳过,不会加载两次。程序继续递归,知道所有DSO加载。这种方式会加载很多。一些可执行程序实际中需要两个而不是200个。

If an executable has the DF SYMBOLIC flag set (see sec- tion 2.2.7) the object with the reference is added in front of the global lookup scope. Note, only the object with the reference itself is added in front, not its dependen- cies. The effects and reasons for this will be explained later.
如果一个可执行程序有设置DF SYMBOLIC标记,这个对象会驾到全局查找表之前。注意,只有引用被加到前面,不是它的依赖。后面解释原因可以效率。

A more complicated modification of the lookup scope happens when DSOs are loaded dynamic using dlopen. If a DSO is dynamically loaded it brings in its own set of dependencies which might have to be searched.
更复杂的修改用于使用dlopen加载动态内容。如果DSO是动态加载的会有自己需要搜索的依赖内容。
These objects, starting with the one which was requested in the dlopen call, are appended to the lookup scope if the object with the reference is among those objects which have been loaded by dlopen. That means, those objects are not added to the global lookup scope and they are not searched for normal lookups. This third part of the lookup scope, we will call it local lookup scope, is there- fore dependent on the object which has the reference.
这些对象从dlopen调用中请求的对象开始,如果具有引用的对象在dlopen加载的对象之中,则将附加到查找范围。这意味着,这些对象不会添加到全局查找范围,也不会对它们进行普通查找。查找范围的第三部分,我们将其称为局部查找范围,因此依赖于具有引用的对象。(有道翻译)

你可能感兴趣的:(How To Write Shared Libraries(13))