Cannot find -lasan and libasan_preinit.o - debugging

When I use -fsanitize=address to link some object into a binary, g++ says the two lib in the title do not exist.
My g++ version is:
$ /opt/rh/devtoolset-2/root/usr/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/opt/rh/devtoolset-2/root/usr/bin/g++
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/opt/rh/devtoolset-2/root/usr --mandir=/opt/rh/devtoolset-2/root/usr/share/man --infodir=/opt/rh/devtoolset-2/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,fortran,lto --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/cloog-install --with-mpc=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC)
Do I need to manually compile libasan if I use g++?

Sanitizer runtimes typically come in a separate package. E.g. on Debian you'll need to install libasanN ("N" depends on your GCC version).

Related

Why does the MinGW bundled with CLion disables LTO (Link Time Optimization)?

I found the recent version of CLion come bundled with MinGW. However, it seems that LTO (Link Time Optimization) is disabled (--disable-lto). Could anyone tell me why? Thx.
C:\Program Files\JetBrains\CLion 2021.1\bin\mingw\bin>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-w64-mingw32
Configured with: ../gcc-11.2.0/configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --build=x86_64-alpine-linux-musl --prefix=/win --enable-checking=release --enable-fully-dynamic-string --enable-languages=c,c++ --enable-libatomic --enable-libgomp --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --enable-seh-exceptions --enable-shared --enable-static --enable-threads=posix --enable-version-specific-runtime-libs --disable-bootstrap --disable-graphite --disable-libada --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-libquadmath --disable-lto --disable-nls --disable-multilib --disable-rpath --disable-symvers --disable-werror --disable-win32-registry --with-gnu-as --with-gnu-ld --with-system-libiconv --with-system-libz --with-gmp=/win/makedepends --with-mpfr=/win/makedepends --with-mpc=/win/makedepends
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)
We made it pretty minimal to be able to compile simple projects like "Hello, world!" and that's it. It also does not include any tooling like MSYS2, so it's even not possible to install additional development libraries there.

gc8.4.1 and _GLIBCXX_USE_CXX11_ABI=0 still uses the new ABI

I use RHEL/Centos 8 to compile app/lib for RHEL/Centos 7.
Centos 7's stdlibc++ has maximum (old ABI):
CXXABI_1.3.7
GLIBCXX_3.4.19
I use CMake with -DCMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 to compile my libraries and my applications for the old ABI to be run on Centos 7.
Nevertheless, the application still requires upper versions: CXXABI_1.3.9 and GLIBCXX_3.4.21.
Why? How can I compile for the old ABI?
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)

Unknown pseudo-op: `.pushsection'. AS version 2.29.1

Cygwin x86. GCC version 7.3.0. Assembler version 2.29.1.
I am trying to build Seabios (CSM16.bin). But i have error:
stacks.s: Assembler messages:
stacks.s:139: Error: unknown pseudo-op: `.pushsection'
As version is not very old. But why assembler dosn't understand opcode?
Sorry for my english...
Gcc -v:
Используются внутренние спецификации.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/7.3.0/lto-wrapper.exe
Целевая архитектура: i686-pc-cygwin
Параметры конфигурации: /cygdrive/i/szsz/tmpp/gcc/gcc-7.3.0-3.i686/src/gcc-7.3.0/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-7.3.0-3.i686/src/gcc-7.3.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libcilkrts --enable-libgomp --enable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Модель многопоточности: posix
gcc версия 7.3.0 (GCC)
As the manual says .pushsection is one of the ELF section stack manipulation directives. The cygwin target is not ELF, it's COFF/PE. As such that directive is not available (even though it would make sense).

How to add '-march=' as default option to gcc?

I can not compile a simple c program without specifying '-march=native', I need to run it as: 'gcc -march=native -o hello hello.c'.
I did:
export CFLAGS='-march=native'
export CXXFLAGS='-march=native'
but didn't help.
user#server:~$ gcc -march=native -Q --help=target
...
-march=corei7-avx
...
Output of gcc -v:
user#server:~$ gcc -v
Using built-in specs.
gcc: error: missing argument to ‘-march=’
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
Where and how can I add this option to be default?
Two options:
Hard way. You may dump your specs file with gcc -dumpspecs > specs
command. Now put this file to /usr/lib/gcc/x86_64-linux-gnu/4.7/
folder and edit it to add option as described in documentation.
In your case I suggest to start from removing all
march=<something> lines, this might trivially help. But general case is troubles and creativity at this point.
Easy way: rename gcc binary to, say gcc-4.7 and make alias with
alias gcc='gcc-4.7 -march=native'

DSO's dynamic symbol table has more entries under 64-bit GCC than 32-bit GCC

I'm building a DSO under 32-bit GCC 4.2.5 and 64-bit GCC. The 64-bit DSO has extra entries in the dynamic symbol table (nm -D libname.so) that don't appear in the 32-bit DSO.
I'm almost positive this is because the 32-bit DSO uses a static version of libstdc++: all of the extra entries in the table are related to std::vector. Some examples:
W _ZNSt6vectorIPN3BVT17FileSonarListenerESaIS2_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS2_S4_EERKS2_
W _ZNSt6vectorIPN3BVT3Net16UDPMessageSocketESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_
W _ZNSt6vectorIPN3BVT3Net21MessageSocketListenerESaIS3_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS3_S5_EERKS3_
W _ZNSt6vectorIPN3BVT4HeadESaIS2_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS2_S4_EERKS2_
W _ZSt6__findIN9__gnu_cxx17__normal_iteratorIPN3BVT15ServerDiscovery5EntryESt6vectorIS4_SaIS4_EEEES4_ET_SA_SA_RKT0_St26random_access_iterator_tag
The other symbols in the table are explicitly flagged in the source with default visibility with a traditional DLL_EXPORT macro, and I'm compiling with the -fvisibility=hidden flag.
Is there any way to remove these unexpected symbols without affecting clients of the DSO? The DSO defines a pure C interface, so no STL types are being passed around.
Here is the output of gcc -v for both compilers:
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--enable-mpfr --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Target: x86_64-linux-gnu
Configured with: ../src/configure -v
--with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4'
--with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.5 --enable-shared --enable-multiarch
--with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.5
--libdir=/usr/lib/x86_64-linux-gnu --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-gold
--enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc
--disable-werror --with-arch-32=i686 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
Perhaps you could link -lstdc++ when building your .so files? Something like g++ -shared -o yourlib.so yourobjects*.pic.o -lstdc++
And perhaps using a more recent GCC (e.g. 4.6) could help.

Resources