public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: Add -static-libasan to the GCC driver
@ 2012-11-17 20:00 H.J. Lu
  2012-11-17 20:22 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2012-11-17 20:00 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch adds -static-libasan.  OK to install?

Thanks.


H.J.
---
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.

diff --git a/gcc/common.opt b/gcc/common.opt
index 0a7c953..be6fe4f 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2516,6 +2516,9 @@ static-libgo
 Driver
 ; Documented for Go, but always accepted by driver.
 
+static-libasan
+Driver
+
 symbolic
 Driver
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b3abc09..885bf66 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -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
diff --git a/gcc/gcc.c b/gcc/gcc.c
index e584319..7a275e1 100644
--- 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Add -static-libasan to the GCC driver
  2012-11-17 20:00 PATCH: Add -static-libasan to the GCC driver H.J. Lu
@ 2012-11-17 20:22 ` Jakub Jelinek
  2012-11-17 23:42   ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2012-11-17 20:22 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Add -static-libasan to the GCC driver
  2012-11-17 20:22 ` Jakub Jelinek
@ 2012-11-17 23:42   ` H.J. Lu
  0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2012-11-17 23:42 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

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.

-- 
H.J.
---
2012-11-17  H.J. Lu  <hongjiu.lu@intel.com>

	* gcc.c (STATIC_LIBASAN_LIBS): New macro.
	(LIBASAN_SPEC): Add STATIC_LIBASAN_LIBS.
	* config/gnu-user.h (STATIC_LIBASAN_LIBS): New macro.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-11-17 23:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-17 20:00 PATCH: Add -static-libasan to the GCC driver H.J. Lu
2012-11-17 20:22 ` Jakub Jelinek
2012-11-17 23:42   ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).