Add -static-libasan option to the GCC driver
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 17 Nov 2012 20:31:06 +0000 (20:31 +0000)
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 17 Nov 2012 20:31:06 +0000 (20:31 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@193589 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/common.opt
gcc/doc/invoke.texi
gcc/gcc.c

index 68a5ac1..eb01532 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2012-11-17  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/55342
index 0a7c953..be6fe4f 100644 (file)
@@ -2516,6 +2516,9 @@ static-libgo
 Driver
 ; Documented for Go, but always accepted by driver.
 
+static-libasan
+Driver
+
 symbolic
 Driver
 
index b3abc09..885bf66 100644 (file)
@@ -452,8 +452,8 @@ Objective-C and Objective-C++ Dialects}.
 @xref{Link Options,,Options for Linking}.
 @gccoptlist{@var{object-file-name}  -l@var{library} @gol
 -nostartfiles  -nodefaultlibs  -nostdlib -pie -rdynamic @gol
--s  -static  -static-libgcc  -static-libstdc++ -shared  @gol
--shared-libgcc  -symbolic @gol
+-s  -static -static-libgcc -static-libasan -static-libstdc++ @gol
+-shared -shared-libgcc  -symbolic @gol
 -T @var{script}  -Wl,@var{option}  -Xlinker @var{option} @gol
 -u @var{symbol}}
 
@@ -9937,6 +9937,15 @@ for the languages used in the program, or using the option
 @option{-shared-libgcc}, such that it is linked with the shared
 @file{libgcc}.
 
+@item -static-libasan
+When the @option{-faddress-sanitizer} option is used to link a program,
+the GCC driver automatically links against @option{libasan}.  If
+@file{libasan} is available as a shared library, and the @option{-static}
+option is not used, then this links against the shared version of
+@file{libasan}.  The @option{-static-libasan} option directs the GCC
+driver to link @file{libasan} statically, without necessarily linking
+other libraries statically.
+
 @item -static-libstdc++
 When the @command{g++} program is used to link a C++ program, it
 normally automatically links against @option{libstdc++}.  If
index e584319..7a275e1 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -544,6 +544,15 @@ proper position among the other output files.  */
    wrapping.  */
 #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}"
 
+#ifndef LIBASAN_SPEC
+#ifdef HAVE_LD_STATIC_DYNAMIC
+#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
+                    "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}"
+#else
+#define LIBASAN_SPEC "-lasan"
+#endif
+#endif
+
 /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
    included.  */
 #ifndef LIBGCC_SPEC
@@ -687,7 +696,7 @@ proper position among the other output files.  */
     %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
     %(mflib) " STACK_SPLIT_SPEC "\
     %{fprofile-arcs|fprofile-generate*|coverage:-lgcov}\
-    %{faddress-sanitizer:-lasan}\
+    %{faddress-sanitizer:" LIBASAN_SPEC "}\
     %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\
     %{!nostdlib:%{!nostartfiles:%E}} %{T*} }}}}}}"
 #endif