C++ 用黄金替换 ld - 有经验吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3476093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 12:54:41  来源:igfitidea点击:

Replacing ld with gold - any experience?

c++clinkermigrationgold-linker

提问by IanH

Has anyone tried to use goldinstead of ld?

有没有人尝试使用gold而不是ld

goldpromisesto be much faster than ld, so it may help speeding up test cycles for large C++ applications, but can it be used as drop-in replacement for ld?

gold承诺比 快得多ld,因此它可能有助于加快大型 C++ 应用程序的测试周期,但它可以用作 ld 的直接替代品吗?

Can gcc/g++directly call gold.?

可以gcc/g++直接调用gold.?

Are there any know bugs or problems?

是否有任何已知的错误或问题?

Although goldis part of the GNU binutils since a while, I have found almost no "success stories" or even "Howtos" in the Web.

尽管gold一段时间以来它是 GNU binutils 的一部分,但我在 Web 上几乎找不到“成功案例”甚至“Howtos”。

(Update: added links to gold and blog entry explaining it)

更新:添加了黄金链接和解释它的博客条目

采纳答案by nob

At the moment it is compiling bigger projects on Ubuntu 10.04. Here you can install and integrate it easily with the binutils-goldpackage (if you remove that package, you get your old ld). Gcc will automatically use gold then.

目前它正在 Ubuntu 10.04 上编译更大的项目。在这里,您可以轻松地安装它并将其与binutils-gold软件包集成(如果您删除该软件包,则会得到旧的ld)。Gcc 将自动使用黄金。

Some experiences:

一些经验:

  • gold doesn't search in /usr/local/lib
  • gold doesn't assume libs like pthread or rt, had to add them by hand
  • it is faster and needs less memory (the later is important on big C++ projects with a lot of boost etc.)
  • 黄金不搜索 /usr/local/lib
  • gold 不假设像 pthread 或 rt 这样的库,必须手动添加它们
  • 它更快并且需要更少的内存(后者对于具有大量提升等的大型 C++ 项目很重要)

What does not work: It cannot compile kernel stuff and therefore no kernel modules. Ubuntu does this automatically via DKMS if it updates proprietary drivers like fglrx. This fails with ld-gold(you have to remove gold, restart DKMS, reinstall ld-gold.

什么不起作用:它无法编译内核内容,因此没有内核模块。如果 Ubuntu 更新像 fglrx 这样的专有驱动程序,它会通过 DKMS 自动执行此操作。这失败了ld-gold(您必须删除黄金,重新启动 DKMS,重新安装ld-gold.

回答by Tilman Vogel

As it took me a little while to find out how to selectively use gold (i.e. not system-wide using a symlink), I'll post the solution here. It's based on http://code.google.com/p/chromium/wiki/LinuxFasterBuilds#Linking_using_gold.

由于我花了一些时间来了解如何有选择地使用黄金(即不是使用符号链接在系统范围内),我将在此处发布解决方案。它基于http://code.google.com/p/chromium/wiki/LinuxFasterBuilds#Linking_using_gold

  1. Make a directory where you can put a gold glue script. I am using ~/bin/gold/.
  2. Put the following glue script there and name it ~/bin/gold/ld:

    #!/bin/bash
    gold "$@"
    

    Obviously, make it executable, chmod a+x ~/bin/gold/ld.

  3. Change your calls to gccto gcc -B$HOME/bin/goldwhich makes gcc look in the given directory for helper programs like ldand thus uses the glue script instead of the system-default ld.

  1. 创建一个目录,您可以在其中放置金胶脚本。我正在使用~/bin/gold/.
  2. 将以下胶水脚本放在那里并将其命名为~/bin/gold/ld

    #!/bin/bash
    gold "$@"
    

    显然,使其可执行,chmod a+x ~/bin/gold/ld.

  3. 更改您gccgcc -B$HOME/bin/goldwhich的调用,使 gcc 在给定的目录中查找诸如此类的帮助程序ld,因此使用胶水脚本而不是 system-default ld

回答by user2273896

Can gcc/g++ directly call gold.?

gcc/g++可以直接调用gold吗?

Just to complement the answers: there is a gcc's option -fuse-ld=gold(see gcc doc). Though, AFAIK, it is possible to configure gcc during the build in a way that the option will not have any effect.

只是为了补充答案:有一个 gcc 选项-fuse-ld=gold(请参阅gcc doc)。但是,AFAIK,可以在构建期间以该选项不会产生任何影响的方式配置 gcc。

回答by Michael Adam

As a Samba developer, I have been using the gold linker almost exclusively on Ubuntu, Debian, and Fedora since several years now. My assessment:

作为 Samba 开发人员,几年以来我几乎只在 Ubuntu、Debian 和 Fedora 上使用黄金链接器。我的评价:

  • gold is many times (felt: 5-10 times) faster than the classical linker.
  • Initially, there were a few problems, but the have gone since roughly Ubuntu 12.04.
  • The gold linker even found some dependency problems in our code, since it seems to be more correct than the classical one with respect to some details. See, e.g. this Samba commit.
  • gold 比经典链接器快很多倍(感觉:5-10 倍)。
  • 最初,有一些问题,但从 Ubuntu 12.04 开始,这些问题就消失了。
  • 黄金链接器甚至在我们的代码中发现了一些依赖问题,因为它在某些细节上似乎比经典链接器更正确。参见,例如这个 Samba commit

I have not used gold selectively, but have been using symlinks or the alternatives mechanism if the distribution provides it.

我没有选择性地使用黄金,但一直在使用符号链接或替代机制(如果发行版提供)。

回答by Delan Azabani

You could link ldto gold(in a local binary directory if you have ldinstalled to avoid overwriting):

您可以链接ldgold(如果您已ld安装以避免覆盖,则在本地二进制目录中):

ln -s `which gold` ~/bin/ld

or

或者

ln -s `which gold` /usr/local/bin/ld

回答by Kenneth Hoste

Some projects seem to be incompatible with gold, because of some incompatible differences between ld and gold. Example: OpenFOAM, see http://www.openfoam.org/mantisbt/view.php?id=685.

有些项目似乎与gold 不兼容,因为ld 和gold 之间存在一些不兼容的差异。示例:OpenFOAM,参见http://www.openfoam.org/mantisbt/view.php?id=685

回答by usr1234567

DragonFlyBSD switched over to gold as their default linker. So it seems to be ready for a variety of tools.
More details: http://phoronix.com/scan.php?page=news_item&px=DragonFlyBSD-Gold-Linker

DragonFlyBSD 切换到 gold 作为默认链接器。所以它似乎已经为各种工具做好了准备。
更多详情:http: //phoronix.com/scan.php?page=news_item&px=DragonFlyBSD-Gold-Linker