[hjl@gnu-tools-1 gcc]$ ./xgcc -B./ x.o -o x -faddress-sanitizer -B../x86_64-unknown-linux-gnu/libsanitizer/asan/.libs/ -static-libasan [hjl@gnu-tools-1 gcc]$ ldd a.out linux-vdso.so.1 => (0x00007fffc6991000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000003341200000) libm.so.6 => /lib64/libm.so.6 (0x0000003338200000) libgomp.so.1 => /lib64/libgomp.so.1 (0x0000003343e00000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000333aa00000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003337a00000) libc.so.6 => /lib64/libc.so.6 (0x0000003337200000) /lib64/ld-linux-x86-64.so.2 (0x0000003336e00000) librt.so.1 => /lib64/librt.so.1 (0x0000003337e00000) [hjl@gnu-tools-1 gcc]$
It should be [hjl@gnu-tools-1 gcc]$ ./xgcc -B./ x.o -o x -faddress-sanitizer -B../x86_64-unknown-linux-gnu/libsanitizer/asan/.libs/ -static-libasan -static [hjl@gnu-tools-1 gcc]$ ldd a.out linux-vdso.so.1 => (0x00007fff91699000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000003341200000) libm.so.6 => /lib64/libm.so.6 (0x0000003338200000) libgomp.so.1 => /lib64/libgomp.so.1 (0x0000003343e00000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000333aa00000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003337a00000) libc.so.6 => /lib64/libc.so.6 (0x0000003337200000) /lib64/ld-linux-x86-64.so.2 (0x0000003336e00000) librt.so.1 => /lib64/librt.so.1 (0x0000003337e00000) [hjl@gnu-tools-1 gcc]$
[hjl@gnu-tools-1 gcc]$ ./xgcc -B./ x.o -o x -faddress-sanitizer -B../x86_64-unknown-linux-gnu/libsanitizer/asan/.libs/ -static-libasan -static -v Reading specs from ./specs COLLECT_GCC=./xgcc COLLECT_LTO_WRAPPER=./lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /export/gnu/import/git/sources/gcc/configure --enable-languages=c,c++ --disable-bootstrap --prefix=/usr/gcc-4.8.0 --with-local-prefix=/usr/local --enable-gnu-indirect-function --with-fpmath=sse : (reconfigured) /export/gnu/import/git/sources/gcc/configure --disable-bootstrap --prefix=/usr/gcc-4.8.0 --with-local-prefix=/usr/local --enable-gnu-indirect-function --with-fpmath=sse CFLAGS=-g CXXFLAGS=-g --enable-languages=c,c++,lto --no-create --no-recursion Thread model: posix gcc version 4.8.0 20121117 (experimental) (GCC) COMPILER_PATH=./:../x86_64-unknown-linux-gnu/libsanitizer/asan/.libs/ LIBRARY_PATH=./:../x86_64-unknown-linux-gnu/libsanitizer/asan/.libs/:/lib/../lib64/:/usr/lib/../lib64/:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-B' './' '-o' 'x' '-faddress-sanitizer' '-B' '../x86_64-unknown-linux-gnu/libsanitizer/asan/.libs/' '-static-libasan' '-static' '-v' '-mtune=generic' '-march=x86-64' ./collect2 -m elf_x86_64 -static -o x /lib/../lib64/crt1.o /lib/../lib64/crti.o ./crtbeginT.o -L. -L../x86_64-unknown-linux-gnu/libsanitizer/asan/.libs -L/lib/../lib64 -L/usr/lib/../lib64 x.o -Bstatic -lasan -Bdynamic --start-group -lgcc -lgcc_eh -lc --end-group ./crtend.o /lib/../lib64/crtn.o [hjl@gnu-tools-1 gcc]$
Note: fully static linking is not supported by libsanitizer at all and I don't think it will. Reason: on linux asan uses "dlsym(RTLD_NEXT, ...)" and on Mac it uses (will soon use) function inerposition. Neither works for fully static binaries, afaict.
(In reply to comment #3) > Note: fully static linking is not supported by libsanitizer at all and I don't > think it will. > Reason: on linux asan uses "dlsym(RTLD_NEXT, ...)" and on Mac it uses > (will soon use) function inerposition. > Neither works for fully static binaries, afaict. Then we should issue an error if -static is used with -faddress-sanitizer.
For -static one could perhaps use --wrap ld option to wrap various symbols, but we'd need special libasan_static.a for that. Not worth it.
So we need %{static:%e-fsanitize=address requires dynamic linking} or similar in LIBASAN_SPEC.
Author: hjl Date: Thu Nov 22 15:17:21 2012 New Revision: 193728 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193728 Log: Issue an error for -static with fsanitize=address PR sanitizer/55379 * gcc.c (LINK_COMMAND_SPEC): Issue an error for -static with -fsanitize=address. Modified: trunk/gcc/ChangeLog trunk/gcc/gcc.c
Fixed.