c - gentoo ld.gold 在 sys-libs/db 上失败

标签 c linker ld gentoo gold-linker

我最近从默认的 binutils 链接器 ld.bfd 切换到 ld.gold(为了让链接时间优化工作,为什么不呢?)。它是由手动制作的(如此处:http://wiki.gentoo.org/wiki/Gold)。结果,我得到了从/usr/bin/ld 到 ld.gold 二进制文件的符号链接(symbolic link)链,因此链接器已针对构建过程透明地更改。

但是当我尝试重建所有包时,我发现 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                                           

这实际上是链接器问题:

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

但是可以使用默认的 bfd 链接器成功构建包,所以问题是如何返回 bfd 链接器来获取无法使用 ld.gold 构建的包?

问题包是=sys-libs/db-6.0.30-r1(现在引起我注意的那个)。

最佳答案

我想到的解决方案是通过 package.env 使用每个包的环境修改。在问题包中使用了 libtool,它调用 gcc 作为链接器,所以需要添加的是 -Wl,-fuse-ld=bfd(在链接阶段,LDFLAGS)。

所以,完整的解决方案是:

mkdir -p /etc/portage/env                                                                          
echo 'LDFLAGS="${LDFLAGS} -Wl,-fuse-ld=bfd"' >> /etc/portage/env/force-bfd.conf                    
echo 'sys-libs/db force-bfd.conf' >> /etc/portage/package.env                                  

关于c - gentoo ld.gold 在 sys-libs/db 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28520166/

相关文章:

c - 如何保护动态字符不被第二个动态字符覆盖?

c - 是什么导致 Labwindows/CVI C 程序讨厌数字 2573?

android - 什么时候链接 "Sdk Assemblies Only"?

c++ - 如何防止特定符号被编译器/链接器剥离?

linker - 黄金链接器 ld.gold -plugin : unknown option

C++ 如何使用 readprocessmemory 查找进程内存中使用的最后一个(偏移量 - 地址)

c - 为什么黄金链接器会导致 dl_iterate_phdr() 不返回我的自定义注释部分?

c++ - 链接我自己的静态库时无法解析的外部符号

带 LD 的 Linux 最小加载地址

c - 如何链接来自不同目录的对象(运行 ld)