Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-fsanitize not using gold linker in GCC-6.1

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
like image 944
Tim Avatar asked Jun 02 '16 22:06

Tim


People also ask

Which linker does GCC use?

But gcc does not link object files. Instead it uses collect2 which is just wrapper for the GNU ld linker: ~$ /usr/lib/gcc/x86_64-linux-gnu/4.9/collect2 --version collect2 version 4.9.

Does GCC 11 support C ++ 20?

GCC has experimental support for the latest revision of the C++ standard, which was published in 2020. C++20 features are available since GCC 8. To enable C++20 support, add the command-line parameter -std=c++20 (use -std=c++2a in GCC 9 and earlier) to your g++ command line.

Does GCC automatically link?

Most Windows compilers support auto-linking, as does Clang, while GCC does not support auto-linking.

Is GCC compiler a linker?

c "). GCC uses a separate linker program (called ld.exe ) to perform the linking.


1 Answers

For me the same problem and same solution using

 -fuse-ld=gold
like image 159
Jose Miguel Jimenez Merchan Avatar answered Oct 06 '22 01:10

Jose Miguel Jimenez Merchan