clinkerldgentoogold-linker

gentoo ld.gold failed on sys-libs/db


I've recently switched from default binutils linker ld.bfd to ld.gold (to get link time optimization working and why not?). It was made by manual (like here: http://wiki.gentoo.org/wiki/Gold). As the result I got chain of symlinks from /usr/bin/ld to ld.gold binary, so linker was changed transparently for build process.

But when I tried to rebuild all packages I discovered that ld.gold sometimes caused configuration/compilation failures like "C compiler cannot create executables":

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                                           

Which actually was linker problem:

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

But package can be successfully built with default bfd linker, so question is how to go back to bfd linker for packages that are can't be built with ld.gold?

Problem package is =sys-libs/db-6.0.30-r1 (the one that got my attention for now).


Solution

  • The solution that comes to my mind -- is to use environment per-package modification via package.env. In problem package libtool is used, which invokes gcc as linker, so the thing is needed to add is -Wl,-fuse-ld=bfd (on link-stage, LDFLAGS).

    So, full solution is:

    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