共享对象文件如何与其他共享对象或常规对象链接以生成新的对象文件?

How can shared object files be linked with other shared or regular objects to produce new object files?

我正在阅读 ELF 规范:https://refspecs.linuxbase.org/elf/elf.pdf

第 15 页:

A shared object file holds code and data suitable for linking in two contexts. First, the link editor may process it with other relocatable and shared object files to create another object file. Second, the dynamic linker combines it with an executable file and other shared objects to create a process image.

我看到其他人在 SO 上提出了多个关于静态链接共享对象的问题,这似乎是这一段所暗示的,但常见的答案似乎通常是这样做是不可能的。

要么我误解了这句话的意思(可能),要么对于共享对象可以做什么没有达成共识。

这段话是什么意思?

Either I'm misunderstanding what this is saying (probably)

该段似乎试图表达的内容:可以在两种情况下使用共享库:

  1. 通过静态 linker(又名 link 编辑器)构建一个 new 共享库或可重定位对象的可执行文件(即构建一个来自 ET_RELs 的新 ET_DYNET_EXEC,以及
  2. 通过动态 linker 构建过程映像。

请注意,案例 1 中构建的新共享库包含现有的共享库。只需要现有的库,这样静态 linker 就知道新的共享库(或可执行文件)应该如何引用现有库中的符号。

我见过的大多数问题(可能还有你提到的问题)都是"how do I put existing libfoo.so into a new libbar.so?",而这实际上是不可能的。

更新:

I'm still not sure I understand. Is #1 the initial creation of the shared library?

是:创建新的共享库或可执行文件。

Because then an executable also has two contexts: 1) The static linker creating the executable out of relocatable objects and 2) By use of the loader to build a process image.

确实如此,但仅适用于动态 linked 的可执行文件。全静态可执行文件根本不涉及加载程序。

I could say a similar thing for relocatable objects as well

不完全是:可重定位对象通常不参与过程映像构建(也有例外,但它们确实很特殊和古怪),而且它们肯定不会被动态处理 linker (装载机)。

出于所有实际目的,可重定位对象仅用作共享库或可执行文件的构建块。