Patchwork PATCH: Add -static-libasan to the GCC driver

login
register
mail settings
Submitter H.J. Lu
Date Nov. 17, 2012, 11:42 p.m.
Message ID <CAMe9rOoRXtmqW2r=AwzrEbfbQgrdx9ENK+-b1VokeMDEQe8Tfw@mail.gmail.com>
Download mbox | patch
Permalink /patch/199889/
State New
Headers show

Comments

H.J. Lu - Nov. 17, 2012, 11:42 p.m.
On Sat, Nov 17, 2012 at 12:22 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Sat, Nov 17, 2012 at 12:00:00PM -0800, H.J. Lu wrote:
>> This patch adds -static-libasan.  OK to install?
>
> Okay, thanks.
>
>> 2012-11-17  H.J. Lu  <hongjiu.lu@intel.com>
>>
>>       * common.opt (static-libasan): New option.
>>       * gcc.c (LIBASAN_SPEC): New macro.
>>       (LINK_COMMAND_SPEC): Replace -lasan with LIBASAN_SPEC.
>>       * doc/invoke.texi: Document -static-libasan.
>
>         Jakub

This patch adds STATIC_LIBASAN_LIBS so that user doesn't
need to add -ldl -lpthread by hand.  OK to install?

Thanks.

Patch

diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
index cb45749..8c4bbc6 100644
--- a/gcc/config/gnu-user.h
+++ b/gcc/config/gnu-user.h
@@ -98,3 +98,7 @@  see the files COPYING3 and COPYING.RUNTIME
respectively.  If not, see

 #define TARGET_C99_FUNCTIONS 1
 #define TARGET_HAS_SINCOS 1
+
+/* Additional libraries needed by -static-libasan.  */
+#undef STATIC_LIBASAN_LIBS
+#define STATIC_LIBASAN_LIBS "-ldl -lpthread"
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 7a275e1..ef8a485 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -546,8 +546,12 @@  proper position among the other output files.  */

 #ifndef LIBASAN_SPEC
 #ifdef HAVE_LD_STATIC_DYNAMIC
+#ifndef STATIC_LIBASAN_LIBS
+#define STATIC_LIBASAN_LIBS
+#endif
 #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
-		     "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}"
+		     "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION \
+		     " " STATIC_LIBASAN_LIBS "}"
 #else
 #define LIBASAN_SPEC "-lasan"
 #endif