Bug 55379 - -static -static-libasan pass -Bdynamic to linker
Summary: -static -static-libasan pass -Bdynamic to linker
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-18 14:50 UTC by H.J. Lu
Modified: 2012-11-22 15:19 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-11-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2012-11-18 14:50:56 UTC
[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]$
Comment 1 H.J. Lu 2012-11-18 14:52:24 UTC
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]$
Comment 2 H.J. Lu 2012-11-18 14:55:57 UTC
[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]$
Comment 3 Konstantin Serebryany 2012-11-18 18:58:00 UTC
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.
Comment 4 H.J. Lu 2012-11-18 19:35:21 UTC
(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.
Comment 5 Jakub Jelinek 2012-11-22 11:14:18 UTC
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.
Comment 6 Jakub Jelinek 2012-11-22 11:30:55 UTC
So we need %{static:%e-fsanitize=address requires dynamic linking} or similar
in LIBASAN_SPEC.
Comment 7 hjl@gcc.gnu.org 2012-11-22 15:17:26 UTC
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
Comment 8 H.J. Lu 2012-11-22 15:18:26 UTC
Fixed.
Comment 9 H.J. Lu 2012-11-22 15:19:00 UTC
Fixed.