How To Write Shared Libraries(3)

1.2 The Move To ELF

For programmers the main advantage of the switch to ELF was that creating ELF shared libraries, or in ELF- speak DSOs, becomes very easy. The only difference be- tween generating an application and a DSO is in the final link command line. One additional option (--shared in the case of GNU ld) tells the linker to generate a DSO instead of an application, the latter being the default. In fact, DSOs are little more than a special kind of binary; the difference is that they have no fixed load address and hence require the dynamic linker to actually become ex- ecutable. With Position Independent Executable (PIEs) the difference shrinks even more.
ELF的优势是实现共享库非常简单。库和程序唯一的不同是最后的链接命令。一个额外的选项(ld的--shared)告知链接器生成共享库,而不是默认的应用程序。实际上DSO更像一个特殊的程序;不同的地方在于有固定的加载地址,因此动态连接库可执行。带有PIE参数,差异很小。

This, together with the introduction of GNU Libtool which will be described later, has led to the wide adoption of DSOs by programmers. Proper use of DSOs can help save large amounts of resources. But some rules must be followed to get any benefits, and some more rules have to be followed to get optimal results. Explaining these rules will be the topic of a large portion of this paper.
因此,之后介绍的GNU libtool是的开发者广泛使用共享库。使用共享库可以节省资源。有付出才有回报,所有有很多需要遵守的规则。展开这些规则是占据本文的大部分内容。

Not all uses of DSOs are for the purpose of saving re- sources. DSOs are today also often used as a way to structure programs. Different parts of the program are put into separate DSOs. This can be a very powerful tool, especially in the development phase. Instead of relink- ing the entire program it is only necessary to relink the DSO(s) which changed. This is often much faster.
不是所有使用DSO都是为了节约资源。如今DSO也是编程架构的一部分。不同的功能放在不同的库中实现。这非常有用,尤其是开发阶段。不用重新链接整个项目,这样只需要链接修改内容。这通常快很多。

Some projects decide to keep many separate DSOs even in the deployment phase even though the DSOs are not reused in other programs. In many situations it is cer- tainly a useful thing to do: DSOs can be updated indi- vidually, reducing the amount of data which has to be transported. But the number of DSOs must be kept to a reasonable level. Not all programs do this, though, and we will see later on why this can be a problem.
一些项目即使在开发阶段或者不会重用的情况也会使用DSO。在许多情况下这是一个非常有用的选项:DSO可以独立更新,减少传输的数据量。但数量必须保证在一个可理解范围。不是所有的程序都如此,后续会分析为什么这是个问题。

Before we can start discussing all this some understand- ing of ELF and its implementation is needed.
在讨论之前需要理解ELF实现。

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