什么是-symbolic和-shared GCC标志之间的区别? [英] What's the difference between the -symbolic and -shared GCC flags?

查看:460
本文介绍了什么是-symbolic和-shared GCC标志之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档的描述,他们似乎做同样的事情,只是不是所有的系统支持共享,只有一些系统支持符号(现在还不清楚,如果这些是同一套系统):

From the documentation's description, they seem to do the same thing except that "not all systems" support shared and "only some systems" support symbolic (it's unclear if these are the same set of systems):

-shared
      产生,然后可以与其它对象链接的共享对象
  形成一个可执行文件。并非所有的系统
  支持此选项。对于predictable
  结果,你还必须指定
  同一组的选项被用来
  产生code(-fpic,-fPIC或模型
  子选项)当您指定此
  选项​​。[1]

-shared Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options that were used to generate code (-fpic, -fPIC, or model suboptions) when you specify this option.[1]

-symbolic
      构建共享对象时绑定到全局符号引用。警告
  任何未解决的引用
  (除非覆盖链接编辑器
  选项​​-Xlinker -z -Xlinker DEFS)。
  只有少数系统支持此
  选项​​。

-symbolic Bind references to global symbols when building a shared object. Warn about any unresolved references (unless overridden by the link editor option -Xlinker -z -Xlinker defs). Only a few systems support this option.

我怀疑不同的是在产生,然后可以与其它的目的,以形成可执行的链接的共享对象的一部分,但听起来像的东西是任何库的真。这是否意味着产生的共享对象可以静态链接也?

I suspect the difference is in the "Produce a shared object which can then be linked with other objects to form an executable" part, but that sounds like something that is true of any library. Does it mean that the resulting shared object can be linked statically too?

推荐答案

摘要:-symbolic prevents内部共享对象功能的设置

Summary: -symbolic prevents intra-shared object function interposition

与共享对象链接允许一个叫做符号插入功能。这个想法是,你可以'干预'一个全球性的符号,这样它被称为甚则常规定义的新定义。

Linking with shared objects allows for a feature called symbol interposition. The idea is that you can 'interpose' a new definition of a global symbol so that it is called rather then the 'regular' definition.

一个典型的例子是malloc()函数。在最常见的情况下,的malloc()被libc的内限定。但是你可以通过加载您加载的libc之前定义符号库干预自己的版本的malloc(大部分运行时链接程序允许您使用LD_ preLOAD特定库可执行程序之前加载)。

One classic example is malloc(). In the most common case, malloc() is defined within libc. But you can interpose your own version of malloc by loading a library that defines that symbol before you load libc (most runtime linkers allow you to use LD_PRELOAD to specific libraries to load before the executable).

在默认情况下,共享对象不是静态的任何功能,是一个全球性的象征。正因为如此,在共享对象中的任何功能都可以插入上。考虑这样一个共享对象有功能高级别的()和low_level()和高级别的()调用low_level()作为它的一部分场景的实现,既没有高级别的(),也不low_level()是静态的功能。

By default, any function within a shared object that is not static is a global symbol. Because of that, any functions within the shared object can be interposed on. Consider a scenario where a shared object has function high_level() and low_level() and high_level() calls low_level() as part of it's implementation and neither high_level() nor low_level() are static functions.

这是可能的干预low_level()这样高级别的()被调用low_level()来自不同的共享对象。

It's possible to interpose low_level() such that high_level() is calling a low_level() from a different shared object.

这就是-symbolic进来。在创建共享对象,链接器会看到low_level()在相同的共享对象定义为高级别的()和绑定调用,使得它不能被插入的。这样,你知道,从你的共享对象到另一个在相同的共享对象的一个​​函数调用的任何永远不会被夹上。

This is where -symbolic comes in. When creating your shared object, the linker will see that low_level() is defined in the same shared object as high_level() and bind the call such that it can't be interposed on. This way, you know that any calls from one function in your shared object to another in the same shared object will never be interposed on.

这篇关于什么是-symbolic和-shared GCC标志之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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