3

我最近从默认的 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                                           

这实际上是链接器问题:

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 (现在引起我注意的那个)。

4

1 回答 1

5

我想到的解决方案是通过 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                                  
于 2015-02-14T20:48:55.200 回答