我的Haskell项目花费了大量时间,Linking dist/build/myapp/myapp ...
并且在执行TemplateHaskell
代码时也加载了共享库.
我怀疑这是因为ld
速度慢.
如何通过切换到gold
链接器来改善链接时间?
Uccntu构建的gcc-6.2((Ubuntu 6.2.0-3ubuntu11~16.04)6.2.0 20160901)不再存在这个问题.
我使用了Ubuntu建立GCC-6.1的[1]((Ubuntu的6.1.1-3ubuntu11〜14.04.1)6.1.1 20160511),GNU binutils的2.24,和libstdc ++与GLIBCXX_3.4.22支持.即使在简单的"hello world"程序中,指定清洁剂也不会强制使用黄金链接器.
#include <iostream>
int main() {
std::cout << "Hello, world!\n";
}
Run Code Online (Sandbox Code Playgroud)
编译和链接
g++ -fsanitize=address -c -o main main.cpp
g++ -fsanitize=address -o main main.o
Run Code Online (Sandbox Code Playgroud)
给出了错误
/usr/bin/ld: unrecognized option '--push-state'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
这表示该-fsanitize
选项未选择黄金链接器.当然,简单的解决方法是-fuse-ld=gold
在链接期间使用,但是在使用消毒剂时,gcc的先前版本不需要这样做.例如,这个代码在gcc-5.3和4.9下完全正常(两者都是Ubuntu版本).是否有其他人在使用非Ubuntu构建的gcc-6.1时遇到此问题?Ubuntu构建是否破损?
[1]使用以下标志构建(gcc-5.3和gcc-4.9的构建只有名称和后缀的差异)
--with-pkgversion='Ubuntu 6.1.1-3ubuntu11~14.04.1'
--with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++
--prefix=/usr
--program-suffix=-6
--enable-shared
--enable-linker-build-id
--libexecdir=/usr/lib
--without-included-gettext
--enable-threads=posix
--libdir=/usr/lib
--enable-nls
--with-sysroot=/
--enable-clocale=gnu
--enable-libstdcxx-debug
--enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=gcc4-compatible
--disable-libstdcxx-dual-abi
--enable-gnu-unique-object
--disable-vtable-verify
--enable-libmpx …
Run Code Online (Sandbox Code Playgroud) 如果我想编译我的项目-flto
是否足以建立gcc --enable-gold
或者我还需要构建黄金并用它替换ld?我还需要其他标志吗?即我这样做
gcc -flto one.c two.c
Run Code Online (Sandbox Code Playgroud) 国家的人gold
:
-L DIR, --library-path DIR
Add directory to search path
--rpath-link DIR
Add DIR to link time shared library search path
Run Code Online (Sandbox Code Playgroud)
bfd的男人ld
让它有点像-rpath-link
用于递归包含sos 的声音.
ld.lld
甚至没有将其列为参数.
有人可以为我澄清这种情况吗?
尝试使用类似命令在我的计算机上安装任何软件包时
cabal install http-conduit
Run Code Online (Sandbox Code Playgroud)
安装中止,出现以下错误:
/usr/bin/ld: --hash-size=31: unknown option
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
注意:这个问题故意不会显示研究工作,因为它是以问答方式立即回答的.
我正在尝试按照入门步骤构建Google的ligjingle ,并且我已经到达了"Building"部分.
当我发出任何一个
ninja -C out/Debug
Run Code Online (Sandbox Code Playgroud)
要么
ninja -C out/Release
Run Code Online (Sandbox Code Playgroud)
我收到以下错误: 如果您愿意,我也会在pastebin中发布输出
ninja -C out/Debug
ninja: Entering directory `out/Debug'
[3/2606] LINK genmacro
FAILED: cc -Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -pthread -Wl,-z,noexecstack -fPIC -B/home/nschoe/workspace/webrtc/jingle/trunk/third_party/binutils/Linux_x64/Release/bin -Wl,--disable-new-dtags -m64 -Wl,--icf=none -fuse-ld=gold -Wl,--gdb-index -o genmacro -Wl,--start-group obj/third_party/yasm/source/patched-yasm/tools/genmacro/genmacro.genmacro.o -Wl,--end-group
/home/nschoe/workspace/webrtc/jingle/trunk/third_party/binutils/Linux_x64/Release/bin/ld.gold: -plugin: unknown option
/home/nschoe/workspace/webrtc/jingle/trunk/third_party/binutils/Linux_x64/Release/bin/ld.gold: use the --help option for usage information
collect2: error: ld returned 1 exit status
[3/2606] CC obj/net/third_party/nss/ssl/libssl.sslauth.o
ninja: build stopped: subcommand failed.
Run Code Online (Sandbox Code Playgroud)
我试过了
ld.gold --help | grep "plugin"
Run Code Online (Sandbox Code Playgroud)
得到了:
--plugin PLUGIN Load …
Run Code Online (Sandbox Code Playgroud) 我正在开始编写自己的 clang 工具。这些是我到目前为止所遵循的步骤:
使用带有以下标志的 ninja 构建 clang 和 llvm (没有这些标志就一直挂在我身上)
-DLLVM_USE_LINKER=gold
-DLLVM_PARALLEL_LINK_JOBS=1
-DLLVM_LINK_LLVM_DYLIB=true
-DLLVM_USE_SPLIT_DWARF=ON
-DBUILD_SHARED_LIBS=ON
已安装叮当声
现在我想将 clang 设置为它自己的编译器。因此,我使用“ccmake ../llvm”在配置文件中设置了这些标志。我不确定这是否是正确的做法?现在我尝试构建 clang,它说检测到的链接器是 GNU ld。如何重置我的配置文件并实际更改链接器以使其更快?我有 8GB 内存。
其次,我每次编写工具时都必须一次又一次地构建 clang 吗?比如说每次需要3-4个小时吗?
更新
正如 sandthorn 在评论中所建议的那样,我通过使用将并行作业限制为 1 ninja -j 1
。然而,构建再次失败,并出现以下错误:
[3840/4138] Linking CXX shared library lib/libLTO.so.7
FAILED: lib/libLTO.so.7
: && /usr/bin/c++ -fPIC -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=gold …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用mingw构建GNU binutils中包含的黄金链接器.我采取的步骤 -
我已经将./configure的完整输出包含在了一个pastebin中:http: //pastebin.com/1XLkZVVm
但重要的是这个:
make[2]: Entering directory `c:/binutils-2.23.1/binutils-2.23.1/gold'
g++ -DHAVE_CONFIG_H -I. -I. -I./../include -I./../elfcpp -DLOCALEDIR="\"/usr/lo
cal/share/locale\"" -DBINDIR="\"/usr/local/bin\"" -DTOOLBINDIR="\"/usr/local//bi
n\"" -DTOOLLIBDIR="\"/usr/local//lib\"" -W -Wall -Wno-format -Werror -D_LAR
GEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -frandom-seed=expression.o -MT expression.
o -MD -MP -MF .deps/expression.Tpo -c -o expression.o expression.cc
In file included from expression.cc:33:0:
script-c.h:221:7: ???: 'yylex' initialized and declared 'extern' [-Werror]
script-c.h:221:7: ???: 'YYSTYPE' was not declared in this scope
script-c.h:221:15: ???: expected primary-expression before ',' token
script-c.h:221:17: ???: expected …
Run Code Online (Sandbox Code Playgroud) 从源代码构建gcc 5.1时,configure脚本会列出以下选项:
--enable-gold[=ARG] build gold [ARG={default,yes,no}]
Run Code Online (Sandbox Code Playgroud)
这是什么意思?是否告诉gcc如果在盒子上安装了黄金,可以使用黄金作为链接器?如果是这样,它是否会期望黄金成为默认链接器,或者我应该通过黄金指向黄金
--with-ld=<path/to/linker>
Run Code Online (Sandbox Code Playgroud)
选项?
我在在线gcc配置文档中找不到--enable-gold的引用.
谢谢!
我最近已从默认的binutils链接程序ld.bfd切换到ld.gold(以使链接时间优化工作正常,为什么不这样做?)。它是手工制作的(例如:http://wiki.gentoo.org/wiki/Gold)。结果,我得到了从/ usr / bin / ld到ld.gold二进制文件的符号链接链,因此在构建过程中透明更改了链接器。
但是,当我尝试重建所有软件包时,我发现ld.gold有时会导致配置/编译失败,例如“ C编译器无法创建可执行文件”:
checking for x86_64-pc-linux-gnu-gcc... x86_64-pc-linux-gnu-gcc
checking whether the C compiler works... no
configure: error: in `/var/tmp/portage/sys-libs/db-6.0.30-r1/work/db-6.0.30/build_unix-abi_x86_64.amd64':
configure: error: C compiler cannot create executables
Run Code Online (Sandbox Code Playgroud)
哪个实际上是链接器问题:
configure: checking whether the C compiler works
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.4/../../../../x86_64-pc-linux-gnu/bin/ld: --default-symver: unknown option
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.4/../../../../x86_64-pc-linux-gnu/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
但是可以使用默认的bfd链接器成功构建软件包,因此问题是对于不能使用ld.gold构建的软件包,如何返回bfd链接器?
问题软件包为= sys-libs / db-6.0.30-r1(目前引起我注意的软件包)。
我正在为LLVM/Clang编写自定义传递,重新编译往往需要一段时间并使用大量内存.我听说黄金链接器(1)花费的时间更少,(2)使用的内存比标准的ld链接器少.
有没有办法将标志传递到LLVM/Clang构建过程并更改为黄金链接器?根据这个答案,我一直在尝试使用覆盖文件,但我似乎没有取得很大的成功.
我还要注意到我正在使用Clang 3.9编译最新的Clang/LLVM版本(4.0); 如果有必要,我不介意切换回GCC,而是宁愿避免它.
我正在讨论如何调试一个我无法简化为最小例子的重大问题.
问题:我编译了链接到许多不同库的应用程序.标志包括:
-static-libstdc++ -static-libgcc -pipe -std=c++1z -fno-PIC -flto=10 -m64 -O3 -flto=10 -fuse-linker-plugin -fuse-ld=gold -UNDEBUG -lrt -ldl
编译器是gcc-7.3.0,针对binutils-2.30编译.Boost编译时使用与程序其余部分相同的标志,并静态链接.
当程序被链接时,我得到关于重定位的各种警告,指的是丢弃的部分,在我自己的代码和boost中.例如:
/tmp/ccq2Ddku.ltrans13.ltrans.o:<artificial>:function boost::system::(anonymous namespace)::generic_error_category::message(int) const: warning: relocation refers to discarded section
Run Code Online (Sandbox Code Playgroud)
然后,当我运行该程序时,它会使用回溯进行破坏:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff7345a49 in __run_exit_handlers () from /lib64/libc.so.6
#2 0x00007ffff7345a95 in exit () from /lib64/libc.so.6
#3 0x00007ffff732eb3c in __libc_start_main () from /lib64/libc.so.6
#4 0x000000000049b3e3 in _start ()
Run Code Online (Sandbox Code Playgroud)
尝试调用的函数指针是0x0.
如果我使用static-libstdc ++删除,链接器警告和运行时段错误就会消失.
如果我从c ++ 1z更改为c ++ 14,链接器警告和运行时段错误就会消失. …