用黄金代替 ld - 有什么经验吗?
有没有人尝试使用 gold
而不是 ld?
gold
承诺比ld<快得多/code>,因此它可能有助于加快大型 C++ 应用程序的测试周期,但它可以用作 ld 的直接替代品吗?
gcc
/g++
可以直接调用gold
吗?
是否存在任何已知的错误或问题?
尽管gold
已经成为 GNU binutils 的一部分已经有一段时间了,但我在网络上几乎没有找到“成功案例”,甚至没有“Howtos”。
(更新:添加了黄金链接和解释它的博客条目)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
目前它正在 Ubuntu 10.04 上编译更大的项目。在这里,您可以轻松安装它并将其与
binutils-gold
软件包集成(如果删除该软件包,您将获得旧的ld
)。 Gcc 将自动使用黄金。一些经验:
/usr/local/lib
中搜索什么不起作用:它无法编译内核内容,因此没有内核模块。如果 Ubuntu 更新了 fglrx 等专有驱动程序,则 Ubuntu 会通过 DKMS 自动执行此操作。
ld-gold
失败(您必须删除 gold,重新启动 DKMS,重新安装ld-gold
。At the moment it is compiling bigger projects on Ubuntu 10.04. Here you can install and integrate it easily with the
binutils-gold
package (if you remove that package, you get your oldld
). Gcc will automatically use gold then.Some experiences:
/usr/local/lib
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, reinstallld-gold
.由于我花了一些时间才找到如何有选择地使用 gold(即不是在系统范围内使用符号链接),因此我将在这里发布解决方案。它基于 http://code.google.com/p/chromium/wiki/ LinuxFasterBuilds#Linking_using_gold 。
~/bin/gold/
。将以下胶水脚本放在那里并将其命名为
~/bin/gold/ld
:<前><代码>#!/bin/bash
黄金“$@”
显然,使其可执行,
chmod a+x ~/bin/gold/ld
。将对
gcc
的调用更改为gcc -B$HOME/bin/gold
,这使得 gcc 在给定目录中查找ld
这样的帮助程序 code>,因此使用glue脚本而不是系统默认的ld
。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 .
~/bin/gold/
.Put the following glue script there and name it
~/bin/gold/ld
:Obviously, make it executable,
chmod a+x ~/bin/gold/ld
.Change your calls to
gcc
togcc -B$HOME/bin/gold
which makes gcc look in the given directory for helper programs likeld
and thus uses the glue script instead of the system-defaultld
.只是为了补充答案:有一个 gcc 选项
-fuse-ld=gold
(参见 gcc 文档)。不过,据我所知,可以在构建过程中配置 gcc,但该选项不会产生任何效果。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.最低综合基准:LD vs 黄金 vs LLVM LLD
结果:
-Wl,--threads -Wl,--thread-count=$(nproc)
启用多线程测试环境:
sudo apt install lld
LLD 10基准测试参数的简化描述:
不同基准参数的结果:
这是生成所有符号的脚本用于链接测试的对象:
generate-objects
GitHub 上游。
请注意,目标文件的生成可能会非常慢,因为每个 C 文件都可能非常大。
给定类型的输入:
它生成:
main.c
f_0.c
,f_1.c
, ...,f_.c
0.c
、1.c
、...、导致:
重定位。
然后我比较了:
在选择测试参数时我一直试图减轻的一些限制:
我还在 gem5 的调试版本中观察到了 2x :https://gem5.googlesource.com/public/gem5/+/fafe4e80b76e93e3d0d05797904c199285 87f5b5
类似的问题:https://unix.stackexchange.com/questions/545699/what- is-the-gold-linker
Phoronix 基准测试
Phoronix 在 2017 年对一些现实世界的项目做了一些基准测试,但对于他们检查的项目来说,黄金收益并没有那么显着:https://www.phoronix.com/scan。 php?page=article&item=lld4-linux-tests&num=2 (存档)。
已知的不兼容性
/issues/109 我的调试符号在LLD基准测试
位于https: //lld.llvm.org/ 他们给出了一些知名项目的构建时间。与我的综合基准结果相似。不幸的是,没有给出项目/链接器版本。在他们的结果中:
他们评论道:
结果如下:
Minimal synthetic benchmark: LD vs gold vs LLVM LLD
Outcome:
-Wl,--threads -Wl,--thread-count=$(nproc)
to enable multithreadingTested on:
sudo apt install lld
LLD 10Simplified description of the benchmark parameters:
Results for different benchmark parameters:
This is the script that generates all the objects for the link tests:
generate-objects
GitHub upstream.
Note that the object file generation can be quite slow, since each C file can be quite large.
Given an input of type:
it generates:
main.c
f_0.c
,f_1.c
, ...,f_<n_funcs>.c
0.c
,1.c
, ...,<n_int_files>.c
which leads to:
relocations on the link.
Then I compared:
Some limits I've been trying to mitigate when selecting the test parameters:
I have also observed a 2x in the debug build of gem5: https://gem5.googlesource.com/public/gem5/+/fafe4e80b76e93e3d0d05797904c19928587f5b5
Similar question: https://unix.stackexchange.com/questions/545699/what-is-the-gold-linker
Phoronix benchmarks
Phoronix did some benchmarking in 2017 for some real world projects, but for the projects they examined, the gold gains were not so significant: https://www.phoronix.com/scan.php?page=article&item=lld4-linux-tests&num=2 (archive).
Known incompatibilities
LLD benchmarks
At https://lld.llvm.org/ they give build times for a few well known projects. with similar results to my synthetic benchmarks. Project/linker versions are not given unfortunately. In their results:
They comment:
and results look like:
作为一名 Samba 开发人员,几年来我几乎只在 Ubuntu、Debian 和 Fedora 上使用 gold 链接器。我的评估:
我没有选择性地使用黄金,但一直在使用符号链接或替代机制(如果发行版提供)。
As a Samba developer, I have been using the gold linker almost exclusively on Ubuntu, Debian, and Fedora since several years now. My assessment:
I have not used gold selectively, but have been using symlinks or the alternatives mechanism if the distribution provides it.
您可以将
ld
链接到gold
(如果您安装了ld
以避免覆盖,则在本地二进制目录中):或者
You could link
ld
togold
(in a local binary directory if you haveld
installed to avoid overwriting):or
有些项目似乎与gold不兼容,因为ld和gold之间存在一些不兼容的差异。示例:OpenFOAM,请参阅 http://www.openfoam.org/mantisbt/view。 php?id=685 。
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 .
DragonFlyBSD 切换到 gold 作为默认链接器。所以它似乎已经为各种工具做好了准备。
更多详情:
http://phoronix.com/scan.php?page=news_item& ;px=DragonFlyBSD-Gold-Linker
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