diff mbox series

Fix driver -fsanitize= handling with -static (PR sanitizer/84285)

Message ID 20180209062757.GC5867@tucnak
State New
Headers show
Series Fix driver -fsanitize= handling with -static (PR sanitizer/84285) | expand

Commit Message

Jakub Jelinek Feb. 9, 2018, 6:27 a.m. UTC
Hi!

When linking with -static-lib{a,t,l,ub}san -fsanitize=whatever, we link
-l{a,t,l,ub}san statically into the binary and add the set of libraries
needed by the lib{a,t,l,ub}san.a afterwards (-lpthread, -ldl etc.).
When doing -static -fsanitize=whatever link, we link the sanitizer library
statically too due to -static, so we need to also ensure we append
the libraries needed by that.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2018-02-09  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/84285
	* gcc.c (STATIC_LIBASAN_LIBS, STATIC_LIBTSAN_LIBS,
	STATIC_LIBLSAN_LIBS, STATIC_LIBUBSAN_LIBS): Handle -static like
	-static-lib*san.


	Jakub

Comments

Richard Biener Feb. 9, 2018, 6:37 a.m. UTC | #1
On February 9, 2018 7:27:57 AM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>When linking with -static-lib{a,t,l,ub}san -fsanitize=whatever, we link
>-l{a,t,l,ub}san statically into the binary and add the set of libraries
>needed by the lib{a,t,l,ub}san.a afterwards (-lpthread, -ldl etc.).
>When doing -static -fsanitize=whatever link, we link the sanitizer
>library
>statically too due to -static, so we need to also ensure we append
>the libraries needed by that.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?

OK. 

Richard. 

>2018-02-09  Jakub Jelinek  <jakub@redhat.com>
>
>	PR sanitizer/84285
>	* gcc.c (STATIC_LIBASAN_LIBS, STATIC_LIBTSAN_LIBS,
>	STATIC_LIBLSAN_LIBS, STATIC_LIBUBSAN_LIBS): Handle -static like
>	-static-lib*san.
>
>--- gcc/gcc.c.jj	2018-01-09 09:01:39.017042679 +0100
>+++ gcc/gcc.c	2018-02-08 15:56:13.361836160 +0100
>@@ -684,7 +684,7 @@ proper position among the other output f
> 
> #ifndef LIBASAN_SPEC
> #define STATIC_LIBASAN_LIBS \
>-  " %{static-libasan:%:include(libsanitizer.spec)%(link_libasan)}"
>+  "
>%{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}"
> #ifdef LIBASAN_EARLY_SPEC
> #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
> #elif defined(HAVE_LD_STATIC_DYNAMIC)
>@@ -702,7 +702,7 @@ proper position among the other output f
> 
> #ifndef LIBTSAN_SPEC
> #define STATIC_LIBTSAN_LIBS \
>-  " %{static-libtsan:%:include(libsanitizer.spec)%(link_libtsan)}"
>+  "
>%{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}"
> #ifdef LIBTSAN_EARLY_SPEC
> #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
> #elif defined(HAVE_LD_STATIC_DYNAMIC)
>@@ -720,7 +720,7 @@ proper position among the other output f
> 
> #ifndef LIBLSAN_SPEC
> #define STATIC_LIBLSAN_LIBS \
>-  " %{static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)}"
>+  "
>%{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}"
> #ifdef LIBLSAN_EARLY_SPEC
> #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
> #elif defined(HAVE_LD_STATIC_DYNAMIC)
>@@ -738,7 +738,7 @@ proper position among the other output f
> 
> #ifndef LIBUBSAN_SPEC
> #define STATIC_LIBUBSAN_LIBS \
>-  " %{static-libubsan:%:include(libsanitizer.spec)%(link_libubsan)}"
>+  "
>%{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
> #ifdef HAVE_LD_STATIC_DYNAMIC
> #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
> 		     "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
>
>	Jakub
diff mbox series

Patch

--- gcc/gcc.c.jj	2018-01-09 09:01:39.017042679 +0100
+++ gcc/gcc.c	2018-02-08 15:56:13.361836160 +0100
@@ -684,7 +684,7 @@  proper position among the other output f
 
 #ifndef LIBASAN_SPEC
 #define STATIC_LIBASAN_LIBS \
-  " %{static-libasan:%:include(libsanitizer.spec)%(link_libasan)}"
+  " %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}"
 #ifdef LIBASAN_EARLY_SPEC
 #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
 #elif defined(HAVE_LD_STATIC_DYNAMIC)
@@ -702,7 +702,7 @@  proper position among the other output f
 
 #ifndef LIBTSAN_SPEC
 #define STATIC_LIBTSAN_LIBS \
-  " %{static-libtsan:%:include(libsanitizer.spec)%(link_libtsan)}"
+  " %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}"
 #ifdef LIBTSAN_EARLY_SPEC
 #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
 #elif defined(HAVE_LD_STATIC_DYNAMIC)
@@ -720,7 +720,7 @@  proper position among the other output f
 
 #ifndef LIBLSAN_SPEC
 #define STATIC_LIBLSAN_LIBS \
-  " %{static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)}"
+  " %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}"
 #ifdef LIBLSAN_EARLY_SPEC
 #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
 #elif defined(HAVE_LD_STATIC_DYNAMIC)
@@ -738,7 +738,7 @@  proper position among the other output f
 
 #ifndef LIBUBSAN_SPEC
 #define STATIC_LIBUBSAN_LIBS \
-  " %{static-libubsan:%:include(libsanitizer.spec)%(link_libubsan)}"
+  " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}"
 #ifdef HAVE_LD_STATIC_DYNAMIC
 #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
 		     "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \