什么是GNU链接部分链接? [英] What is Partial Linking in GNU Linker?

查看:188
本文介绍了什么是GNU链接部分链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能找到的最好的解释是从官方文档:

The best explanation I was able to find was from the official document:

-r
  --relocateable生成重定位输出 - 即,产生一个输出文件,可以反过来作为输入到ld。这通常被称为
  部分链接。作为一个副作用,在支持环境
  标准的Unix幻数,此选项还设置输出文件的
  神奇的数字来OMAGIC。如果没有指定这个选项,绝对
  文件产生。当连接C ++程序,此选项将不
  解析构造函数的引用;要做到这一点,使用-ur。此选项
  做同样的事情`-I'。

-r --relocateable Generate relocatable output--i.e., generate an output file that can in turn serve as input to ld. This is often called partial linking. As a side effect, in environments that support standard Unix magic numbers, this option also sets the output file's magic number to OMAGIC. If this option is not specified, an absolute file is produced. When linking C++ programs, this option will not resolve references to constructors; to do that, use -Ur. This option does the same thing as `-i'.

我在知道发生了什么,以投入到链接符号present特别感兴趣。以一个特定的情况下,当我有一个静态库的 libstatic.a 其中包含一个目标文件的 component.o
现在,我想创建另一个静态库的 libfinal.a 这将作为一个接口工作,以 libstatic.a 。我用这个命令来创建它:

I am specifically interested in knowing what happens to the symbols present in inputs to linker. Take a specific case when I have a static library libstatic.a which contains a single object file component.o. Now, I want to create another static library libfinal.a which will work as an interface to libstatic.a. I use this command to create it:

LD -r -o libfinal.a wrapper.o -L。 -lstatic

其中的 wrapper.o 独家提供的API来调用libstatic.a定义的函数

Where wrapper.o provides exclusive APIs to call the functions defined in libstatic.a

将具有 libfinal.a 只是一个合并的归档文件的 wrapper.o component.o 或所有引用它可以成为的-resolved之间的 wrapper.o component.o 来解决(连接),然后放入 libfinal.a

Will the libfinal.a be just a combined archive having wrapper.o and component.o or all the references which can-be-resolved between wrapper.o and component.o be resolved(linking) and then placed into libfinal.a?

Edit_1:更新的基础上取得的进展的问题:
objdump的组件库的 libstatic.a objdump的-D libstatic.a )分别显示的.text 部分对每种功能(如预期)。而在组合库 libfinal.a ,已经由部分链接( -r 标记)创建有刚一个单一的的.text 部分。我想这意味着,内部联已经发生,它不只是创建一个普通的档案。

Edit_1: Updating the question based on the progress made: The objdump of the component library libstatic.a (objdump -D libstatic.a) shows .text sections separately for each function (as expected). Whereas in the combined library libfinal.a, which has been created by partial linking (-rflag) there is just one single .text section. I guess this means that an internal-linking has taken place and it's not just creating a plain archive.

推荐答案

LD 创建可执行文件和共享库,而不是目标文件归档(.a文件)。

ld creates executables and shared libraries, not object file archives (.a files).

AR 创建和修改对象文件存档。

ar creates and modifies object file archives.

-r,--relocateable 选项是有用的,当你想解决的.so ,并产生另一个的.so

-r, --relocateable option is useful when you would like to resolve certain (unresolved) symbols of a .so and produce another .so.

这篇关于什么是GNU链接部分链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆