-fsanitize not using gold linker in GCC-6.1
Asked Answered
S

1

17

Update (30-Sept-2016)

The Ubuntu build of gcc-6.2 ((Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901) no longer has this issue.


I'm using the Ubuntu build of gcc-6.1[1] ((Ubuntu 6.1.1-3ubuntu11~14.04.1) 6.1.1 20160511), GNU binutils 2.24, and libstdc++ with GLIBCXX_3.4.22 support. Even on a simple "hello world" program, specifying a sanitizer is not forcing use of the gold linker.

main.cpp

#include <iostream>
int main() {
    std::cout << "Hello, world!\n";
}

Compiling and linking

g++ -fsanitize=address -c -o main main.cpp
g++ -fsanitize=address -o main main.o

gives the error

/usr/bin/ld: unrecognized option '--push-state'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status

Which indicates the -fsanitize option isn't selecting the gold linker. Of course, the simple fix is to use -fuse-ld=gold during linking, but previous builds of gcc didn't need this when using the sanitizers. For example, this code works perfectly fine under gcc-5.3 and 4.9 (both are Ubuntu builds). Is anyone else having this issue with non-Ubuntu builds of gcc-6.1? Are the Ubuntu builds broken?


[1] Built with the following flags (gcc-5.3 and gcc-4.9 were built with only differences in the names and suffixes)

--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
--enable-plugin
--with-system-zlib
--disable-browser-plugin
--enable-java-awt=gtk
--enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre
--enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64
--with-arch-directory=amd64
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc
--enable-multiarch
--disable-werror
--with-arch-32=i686
--with-abi=m64
--with-multilib-list=m32,m64,mx32
--enable-multilib
--with-tune=generic
--enable-checking=release
--build=x86_64-linux-gnu
--host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Signorino answered 2/6, 2016 at 22:36 Comment(6)
Looks very much like a bug in the Ubuntu package.Sandglass
@BaummitAugen That's what I was thinking, but there are no differences in the configure options used to build 6.1 and 5.3, but 5.3 works fine.Signorino
I've had the same issue. Either way, passing -fuse-ld=gold explicitly solves the problem.Evadnee
5.4 has this issue as well. -fuse-ld=gold solves it though. Thanks!Indoiranian
Had the same issue on 5.4.1 on Ubuntu 14.04 and -fuse-ld=gold solves the issue. Anyone submitted a bug report?Urnfield
Well this problem leads to inability to use lld linker with sanitizers on ubuntu, because it is not gold but still unrecognizes --push-stateMuslim
L
4

For me the same problem and same solution using

 -fuse-ld=gold
Liege answered 9/2, 2017 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.