public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] RFC asan support for i?86/x86_64-*freebsd*
@ 2015-11-29 23:34 Andreas Tobler
  2015-11-30 22:27 ` Jeff Law
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Tobler @ 2015-11-29 23:34 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]

All,

this patch adds support for asan for i?86/x86_64-*freebsd*.

Test results can be found on the list.

These modifications belong only to gcc. There is one modification to 
asan/asan_linux.cc, this one is sent upstream. Until this one is in, my 
patch is on hold.

One thing to note, FreeBSD does not need to link against -ldl. That is 
why I added an extra config check.

But nevertheless I'd like to get some comments on the patch.

Thanks to Jakub and Dan McGregor.

Thanks,
Andreas


2015-11-29  Andreas Tobler  <andreast@gcc.gnu.org>

	* config/i386/i386.h: Define two new macros:
	SUBTARGET_SHADOW_OFFSET_64 and SUBTARGET_SHADOW_OFFSET_32.
	* config/i386/i386.c (ix86_asan_shadow_offset): Use these macros.
	* config/i386/darwin.h: Override the SUBTARGET_SHADOW_OFFSET_64
	macro.
	* config/i386/freebsd.h: Override the SUBTARGET_SHADOW_OFFSET_64
	and the SUBTARGET_SHADOW_OFFSET_32 macro.
	* config/freebsd.h (LIBASAN_EARLY_SPEC): Define.
	(LIBTSAN_EARLY_SPEC): Likewise.
	(LIBLSAN_EARLY_SPEC): Likewise.

2015-11-29  Andreas Tobler  <andreast@gcc.gnu.org>

	* configure.ac: Replace the hard-coded -ldl requirement for
	link_sanitizer_common with a configure time check for -ldl.
	* configure: Regenerate.
	* configure.tgt: Add x86_64- and i?86-*-freebsd* targets.

[-- Attachment #2: asan-freebsd-20151129-1.diff --]
[-- Type: text/plain, Size: 5020 bytes --]

Index: gcc/config/freebsd.h
===================================================================
--- gcc/config/freebsd.h	(revision 231047)
+++ gcc/config/freebsd.h	(working copy)
@@ -62,6 +62,27 @@
 #define USE_LD_AS_NEEDED 1
 #endif
 
+/* 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 with --{,no-}whole-archive around
+   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} " \
+  "%{static-libasan:%{!shared:" \
+  LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \
+  LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan -lpthread}"
+#undef LIBTSAN_EARLY_SPEC
+#define LIBTSAN_EARLY_SPEC "%{static-libtsan:%{!shared:" \
+  LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \
+  LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan -lpthread}"
+#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 -lpthread}"
+#endif
+
 /************************[  Target stuff  ]***********************************/
 
 /* All FreeBSD Architectures support the ELF object file format.  */
Index: gcc/config/i386/darwin.h
===================================================================
--- gcc/config/i386/darwin.h	(revision 231047)
+++ gcc/config/i386/darwin.h	(working copy)
@@ -295,3 +295,8 @@
     = darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING));	\
   darwin_rename_builtins ();					\
 } while(0)
+
+/* Define the shadow offset for asan.  */
+#undef SUBTARGET_SHADOW_OFFSET_64
+#define SUBTARGET_SHADOW_OFFSET_64  (HOST_WIDE_INT_1 << 44)
+
Index: gcc/config/i386/freebsd.h
===================================================================
--- gcc/config/i386/freebsd.h	(revision 231047)
+++ gcc/config/i386/freebsd.h	(working copy)
@@ -135,3 +135,9 @@
 
 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
+/* Define the shadow offsets for asan.  */
+#undef SUBTARGET_SHADOW_OFFSET_32
+#define SUBTARGET_SHADOW_OFFSET_32  (HOST_WIDE_INT_1 << 30)
+#undef SUBTARGET_SHADOW_OFFSET_64
+#define SUBTARGET_SHADOW_OFFSET_64  (HOST_WIDE_INT_1 << 46)
+
Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 231047)
+++ gcc/config/i386/i386.c	(working copy)
@@ -7312,9 +7312,8 @@
 static unsigned HOST_WIDE_INT
 ix86_asan_shadow_offset (void)
 {
-  return TARGET_LP64 ? (TARGET_MACHO ? (HOST_WIDE_INT_1 << 44)
-				     : HOST_WIDE_INT_C (0x7fff8000))
-		     : (HOST_WIDE_INT_1 << 29);
+  return TARGET_LP64 ? SUBTARGET_SHADOW_OFFSET_64 
+    : SUBTARGET_SHADOW_OFFSET_32; 
 }
 \f
 /* Argument support functions.  */
Index: gcc/config/i386/i386.h
===================================================================
--- gcc/config/i386/i386.h	(revision 231047)
+++ gcc/config/i386/i386.h	(working copy)
@@ -1272,6 +1272,16 @@
 #define SUBTARGET_FRAME_POINTER_REQUIRED 0
 #endif
 
+/* Define the shadow offset for asan. Other OS's can override in the
+   respective tm.h files.  */
+#ifndef SUBTARGET_SHADOW_OFFSET_32
+#define SUBTARGET_SHADOW_OFFSET_32  (HOST_WIDE_INT_1 << 29)
+#endif
+
+#ifndef SUBTARGET_SHADOW_OFFSET_64
+#define SUBTARGET_SHADOW_OFFSET_64  (HOST_WIDE_INT_C (0x7fff8000))
+#endif
+
 /* Make sure we can access arbitrary call frames.  */
 #define SETUP_FRAME_ADDRESSES()  ix86_setup_frame_addresses ()
 
Index: libsanitizer/configure.ac
===================================================================
--- libsanitizer/configure.ac	(revision 231047)
+++ libsanitizer/configure.ac	(working copy)
@@ -96,7 +96,7 @@
 AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime)
 
 # Common libraries that we need to link against for all sanitizer libs.
-link_sanitizer_common='-lpthread -ldl -lm'
+link_sanitizer_common='-lpthread -lm'
 
 # At least for glibc, shm_open is in librt.  But don't pull that
 # in if it still doesn't give us the function we want.  This
@@ -130,6 +130,12 @@
 # Other sanitizers do not override clock_* API
 ])
 
+# Do a configure time check for -ldl
+AC_CHECK_LIB(dl, dlsym,
+    [link_libasan="-ldl $link_libasan"
+link_libtsan="-ldl $link_libtsan"
+])
+
 case "$host" in
   *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
   *) MAC_INTERPOSE=false ;;
Index: libsanitizer/configure.tgt
===================================================================
--- libsanitizer/configure.tgt	(revision 231047)
+++ libsanitizer/configure.tgt	(working copy)
@@ -21,6 +21,8 @@
 # Filter out unsupported systems.
 TSAN_TARGET_DEPENDENT_OBJECTS=
 case "${target}" in
+  x86_64-*-freebsd* | i?86-*-freebsd*)
+	;;
   x86_64-*-linux* | i?86-*-linux*)
 	if test x$ac_cv_sizeof_void_p = x8; then
 		TSAN_SUPPORTED=yes

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

* Re: [patch] RFC asan support for i?86/x86_64-*freebsd*
  2015-11-29 23:34 [patch] RFC asan support for i?86/x86_64-*freebsd* Andreas Tobler
@ 2015-11-30 22:27 ` Jeff Law
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Law @ 2015-11-30 22:27 UTC (permalink / raw)
  To: Andreas Tobler, GCC Patches

On 11/29/2015 03:10 PM, Andreas Tobler wrote:
> All,
>
> this patch adds support for asan for i?86/x86_64-*freebsd*.
>
> Test results can be found on the list.
>
> These modifications belong only to gcc. There is one modification to
> asan/asan_linux.cc, this one is sent upstream. Until this one is in, my
> patch is on hold.
>
> One thing to note, FreeBSD does not need to link against -ldl. That is
> why I added an extra config check.
>
> But nevertheless I'd like to get some comments on the patch.
>
> Thanks to Jakub and Dan McGregor.
>
> Thanks,
> Andreas
>
>
> 2015-11-29  Andreas Tobler  <andreast@gcc.gnu.org>
>
>      * config/i386/i386.h: Define two new macros:
>      SUBTARGET_SHADOW_OFFSET_64 and SUBTARGET_SHADOW_OFFSET_32.
>      * config/i386/i386.c (ix86_asan_shadow_offset): Use these macros.
>      * config/i386/darwin.h: Override the SUBTARGET_SHADOW_OFFSET_64
>      macro.
>      * config/i386/freebsd.h: Override the SUBTARGET_SHADOW_OFFSET_64
>      and the SUBTARGET_SHADOW_OFFSET_32 macro.
>      * config/freebsd.h (LIBASAN_EARLY_SPEC): Define.
>      (LIBTSAN_EARLY_SPEC): Likewise.
>      (LIBLSAN_EARLY_SPEC): Likewise.
>
> 2015-11-29  Andreas Tobler  <andreast@gcc.gnu.org>
>
>      * configure.ac: Replace the hard-coded -ldl requirement for
>      link_sanitizer_common with a configure time check for -ldl.
>      * configure: Regenerate.
>      * configure.tgt: Add x86_64- and i?86-*-freebsd* targets.
The configury bits are fine.  Uros would own review on the x86 specific 
changes.

jeff

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

* Re: [patch] RFC asan support for i?86/x86_64-*freebsd*
  2015-12-01 12:22 Uros Bizjak
@ 2015-12-01 20:33 ` Andreas Tobler
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Tobler @ 2015-12-01 20:33 UTC (permalink / raw)
  To: Uros Bizjak, gcc-patches; +Cc: Jeff Law

Hi!

On 01.12.15 13:22, Uros Bizjak wrote:

>> 2015-11-29  Andreas Tobler  <andreast@gcc.gnu.org>
>>
>> * config/i386/i386.h: Define two new macros:
>> SUBTARGET_SHADOW_OFFSET_64 and SUBTARGET_SHADOW_OFFSET_32.
>> * config/i386/i386.c (ix86_asan_shadow_offset): Use these macros.
>> * config/i386/darwin.h: Override the SUBTARGET_SHADOW_OFFSET_64
>> macro.
>> * config/i386/freebsd.h: Override the SUBTARGET_SHADOW_OFFSET_64
>> and the SUBTARGET_SHADOW_OFFSET_32 macro.
>> * config/freebsd.h (LIBASAN_EARLY_SPEC): Define.
>> (LIBTSAN_EARLY_SPEC): Likewise.
>> (LIBLSAN_EARLY_SPEC): Likewise.
>
> IMO, there is no compelling reason for _64 and _32 subtargets split,
> especially since it depends on TARGET_LP64, not on the usual
> TARGET_64BIT. Due to this, I'd rather introduce only
> TARGET_SHADOW_OFFSET, like:
>
> #define TARGET_SHADOW_OFFSET \
>    (TARGET_LP64 ? HOST_WIDE_INT_C (0x7fff8000) : HOST_WIDE_INT_1 << 29)
>
> (and similar for other targets).

Thank you for the feedback. I put your suggestion into my local tree and 
the results are equal. Thanks, diff reduced :)

Andreas

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

* Re: [patch] RFC asan support for i?86/x86_64-*freebsd*
@ 2015-12-01 12:22 Uros Bizjak
  2015-12-01 20:33 ` Andreas Tobler
  0 siblings, 1 reply; 4+ messages in thread
From: Uros Bizjak @ 2015-12-01 12:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andreas Tobler, Jeff Law

Hello!

> 2015-11-29  Andreas Tobler  <andreast@gcc.gnu.org>
>
> * config/i386/i386.h: Define two new macros:
> SUBTARGET_SHADOW_OFFSET_64 and SUBTARGET_SHADOW_OFFSET_32.
> * config/i386/i386.c (ix86_asan_shadow_offset): Use these macros.
> * config/i386/darwin.h: Override the SUBTARGET_SHADOW_OFFSET_64
> macro.
> * config/i386/freebsd.h: Override the SUBTARGET_SHADOW_OFFSET_64
> and the SUBTARGET_SHADOW_OFFSET_32 macro.
> * config/freebsd.h (LIBASAN_EARLY_SPEC): Define.
> (LIBTSAN_EARLY_SPEC): Likewise.
> (LIBLSAN_EARLY_SPEC): Likewise.

IMO, there is no compelling reason for _64 and _32 subtargets split,
especially since it depends on TARGET_LP64, not on the usual
TARGET_64BIT. Due to this, I'd rather introduce only
TARGET_SHADOW_OFFSET, like:

#define TARGET_SHADOW_OFFSET \
  (TARGET_LP64 ? HOST_WIDE_INT_C (0x7fff8000) : HOST_WIDE_INT_1 << 29)

(and similar for other targets).

Uros.

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

end of thread, other threads:[~2015-12-01 20:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-29 23:34 [patch] RFC asan support for i?86/x86_64-*freebsd* Andreas Tobler
2015-11-30 22:27 ` Jeff Law
2015-12-01 12:22 Uros Bizjak
2015-12-01 20:33 ` Andreas Tobler

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).