diff mbox

Handle -fsanitize=leak more similarly to address/thread

Message ID 20140814163748.GI1784@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Aug. 14, 2014, 4:37 p.m. UTC
Hi!

Right now when -fsanitize=leak adds -llsan, it adds it late on the command
line, so e.g. -lstdc++ comes after it, which seems to be bad.
The following patch puts it early on the link command line like we do for
-lasan or -ltsan.  Bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?

2014-08-14  Jakub Jelinek  <jakub@redhat.com>

	* config/gnu-user.h (LIBLSAN_EARLY_SPEC): Define.
	* gcc.c (LIBLSAN_SPEC, LIBLSAN_EARLY_SPEC): Follow LIBTSAN*_SPEC.
	(SANITIZER_EARLY_SPEC): Include LIBLSAN_EARLY_SPEC for -fsanitize=leak.


	Jakub

Comments

Dodji Seketeli Aug. 17, 2014, 10:16 a.m. UTC | #1
Jakub Jelinek <jakub@redhat.com> writes:


> Right now when -fsanitize=leak adds -llsan, it adds it late on the command
> line, so e.g. -lstdc++ comes after it, which seems to be bad.
> The following patch puts it early on the link command line like we do for
> -lasan or -ltsan.  Bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk?
>
> 2014-08-14  Jakub Jelinek  <jakub@redhat.com>
>
> 	* config/gnu-user.h (LIBLSAN_EARLY_SPEC): Define.
> 	* gcc.c (LIBLSAN_SPEC, LIBLSAN_EARLY_SPEC): Follow LIBTSAN*_SPEC.
> 	(SANITIZER_EARLY_SPEC): Include LIBLSAN_EARLY_SPEC for -fsanitize=leak.

This looks OK to me.

Thanks!
Jeff Law Aug. 29, 2014, 9:06 p.m. UTC | #2
On 08/14/14 10:37, Jakub Jelinek wrote:
> Hi!
>
> Right now when -fsanitize=leak adds -llsan, it adds it late on the command
> line, so e.g. -lstdc++ comes after it, which seems to be bad.
> The following patch puts it early on the link command line like we do for
> -lasan or -ltsan.  Bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk?
>
> 2014-08-14  Jakub Jelinek  <jakub@redhat.com>
>
> 	* config/gnu-user.h (LIBLSAN_EARLY_SPEC): Define.
> 	* gcc.c (LIBLSAN_SPEC, LIBLSAN_EARLY_SPEC): Follow LIBTSAN*_SPEC.
> 	(SANITIZER_EARLY_SPEC): Include LIBLSAN_EARLY_SPEC for -fsanitize=leak.
OK.
Jeff
diff mbox

Patch

--- gcc/config/gnu-user.h.jj	2014-01-03 11:41:11.000000000 +0100
+++ gcc/config/gnu-user.h	2014-08-11 13:42:24.187122214 +0200
@@ -114,7 +114,8 @@  see the files COPYING3 and COPYING.RUNTI
 /* Link -lasan early on the command line.  For -static-libasan, don't link
    it for -shared link, the executable should be compiled with -static-libasan
    in that case, and for executable link link with --{,no-}whole-archive around
-   it to force everything into the executable.  And similarly for -ltsan.  */
+   it to force everything into the executable.  And similarly for -ltsan
+   and -llsan.  */
 #if defined(HAVE_LD_STATIC_DYNAMIC)
 #undef LIBASAN_EARLY_SPEC
 #define LIBASAN_EARLY_SPEC "%{!shared:libasan_preinit%O%s} " \
@@ -125,4 +126,8 @@  see the files COPYING3 and COPYING.RUNTI
 #define LIBTSAN_EARLY_SPEC "%{static-libtsan:%{!shared:" \
   LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
   LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}"
+#undef LIBLSAN_EARLY_SPEC
+#define LIBLSAN_EARLY_SPEC "%{static-liblsan:%{!shared:" \
+  LD_STATIC_OPTION " --whole-archive -llsan --no-whole-archive " \
+  LD_DYNAMIC_OPTION "}}%{!static-liblsan:-llsan}"
 #endif
--- gcc/gcc.c.jj	2014-08-01 09:23:35.000000000 +0200
+++ gcc/gcc.c	2014-08-11 13:45:27.994253297 +0200
@@ -576,13 +576,19 @@  proper position among the other output f
 #ifndef LIBLSAN_SPEC
 #define STATIC_LIBLSAN_LIBS \
   " %{static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)}"
-#ifdef HAVE_LD_STATIC_DYNAMIC
-#define LIBLSAN_SPEC "%{!shared:%{static-liblsan:" LD_STATIC_OPTION \
+#ifdef LIBLSAN_EARLY_SPEC
+#define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
+#elif defined(HAVE_LD_STATIC_DYNAMIC)
+#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
 		     "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
-		     STATIC_LIBLSAN_LIBS "}"
+		     STATIC_LIBLSAN_LIBS
 #else
-#define LIBLSAN_SPEC "%{!shared:-llsan" STATIC_LIBLSAN_LIBS "}"
+#define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
+#endif
 #endif
+
+#ifndef LIBLSAN_EARLY_SPEC
+#define LIBLSAN_EARLY_SPEC ""
 #endif
 
 #ifndef LIBUBSAN_SPEC
@@ -772,7 +778,8 @@  proper position among the other output f
 #ifndef SANITIZER_EARLY_SPEC
 #define SANITIZER_EARLY_SPEC "\
 %{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \
-    %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "}}}"
+    %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \
+    %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}"
 #endif
 
 /* Linker command line options for -fsanitize= late on the command line.  */