[gcc/devel/ranger] gcc: Enable bits for sanitizer support on FreeBSD x86_64

Aldy Hernandez aldyh@gcc.gnu.org
Wed Jun 17 20:56:51 GMT 2020


https://gcc.gnu.org/g:d730fd95eebaecad8e26f9e089c7df4630e94f1c

commit d730fd95eebaecad8e26f9e089c7df4630e94f1c
Author: Andreas Tobler <andreast@gcc.gnu.org>
Date:   Fri May 1 09:04:01 2020 +0200

    gcc: Enable bits for sanitizer support on FreeBSD x86_64
    
    This patch add the necessary bits to suport libasan on FreeBSD x86_64.
    
    gcc
            * config/i386/i386.h: Define a new macro: SUBTARGET_SHADOW_OFFSET.
            * config/i386/i386.c (ix86_asan_shadow_offset): Use this macro.
            * config/i386/darwin.h: Override the SUBTARGET_SHADOW_OFFSET macro.
            * config/i386/freebsd.h: Likewise.
            * config/freebsd.h (LIBASAN_EARLY_SPEC): Define.
            LIBTSAN_EARLY_SPEC): Likewise. (LIBLSAN_EARLY_SPEC): Likewise.
    
    libsanitizer:
    
            * configure.tgt: Add x86_64- and i?86-*-freebsd* targets.

Diff:
---
 gcc/ChangeLog              |  9 +++++++++
 gcc/config/freebsd.h       | 21 +++++++++++++++++++++
 gcc/config/i386/darwin.h   |  6 ++++++
 gcc/config/i386/freebsd.h  |  4 ++++
 gcc/config/i386/i386.c     |  4 +---
 gcc/config/i386/i386.h     |  7 +++++++
 libsanitizer/ChangeLog     |  3 +++
 libsanitizer/configure.tgt |  2 ++
 8 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4c2ef0d4a1a..5a0a82128a8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2020-05-01  Andreas Tobler  <andreast@gcc.gnu.org>
+
+	* config/i386/i386.h: Define a new macro: SUBTARGET_SHADOW_OFFSET.
+	* config/i386/i386.c (ix86_asan_shadow_offset): Use this macro.
+	* config/i386/darwin.h: Override the SUBTARGET_SHADOW_OFFSET macro.
+	* config/i386/freebsd.h: Likewise.
+	* config/freebsd.h (LIBASAN_EARLY_SPEC): Define.
+	LIBTSAN_EARLY_SPEC): Likewise. (LIBLSAN_EARLY_SPEC): Likewise.
+
 2020-04-30  Alexandre Oliva <oliva@adacore.com>
 
 	* doc/sourcebuild.texi (Effective-Target Keywords): Document
diff --git a/gcc/config/freebsd.h b/gcc/config/freebsd.h
index d9d6be7a8c8..4b5140bae02 100644
--- a/gcc/config/freebsd.h
+++ b/gcc/config/freebsd.h
@@ -62,6 +62,27 @@ along with GCC; see the file COPYING3.  If not see
 #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.  */
diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index 5faa1f40089..cff9a8c6b01 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -347,6 +347,12 @@ along with GCC; see the file COPYING3.  If not see
 #define SUBTARGET_INIT_BUILTINS						\
   do {									\
     ix86_builtins[(int) IX86_BUILTIN_CFSTRING]				\
+
+/* Define the shadow offset for asan.  */
+#undef SUBTARGET_SHADOW_OFFSET
+#define SUBTARGET_SHADOW_OFFSET	\
+  (TARGET_LP64 ? HOST_WIDE_INT_1 << 44 : HOST_WIDE_INT_1 << 29)
+
       = darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING)); \
     darwin_rename_builtins ();						\
   } while(0)
diff --git a/gcc/config/i386/freebsd.h b/gcc/config/i386/freebsd.h
index 8fb0f0aaf5c..9d66602142e 100644
--- a/gcc/config/i386/freebsd.h
+++ b/gcc/config/i386/freebsd.h
@@ -129,3 +129,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
+/* Define the shadow offsets for asan.  */
+#undef SUBTARGET_SHADOW_OFFSET
+#define SUBTARGET_SHADOW_OFFSET	\
+  (TARGET_LP64 ? HOST_WIDE_INT_1 << 46 : HOST_WIDE_INT_1 << 30)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 59101d8028a..c4a538ed0c8 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -1397,9 +1397,7 @@ ix86_legitimate_combined_insn (rtx_insn *insn)
 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 SUBTARGET_SHADOW_OFFSET;
 }
 
 /* Argument support functions.  */
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index b8dddfc1594..08245f64322 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1321,6 +1321,13 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 #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
+#define SUBTARGET_SHADOW_OFFSET	    \
+  (TARGET_LP64 ? HOST_WIDE_INT_C (0x7fff8000) : HOST_WIDE_INT_1 << 29)
+#endif
+
 /* Make sure we can access arbitrary call frames.  */
 #define SETUP_FRAME_ADDRESSES()  ix86_setup_frame_addresses ()
 
diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog
index 476cb416c36..134018503c3 100644
--- a/libsanitizer/ChangeLog
+++ b/libsanitizer/ChangeLog
@@ -1,3 +1,6 @@
+2020-05-01  Andreas Tobler  <andreast@gcc.gnu.org>
+
+	* configure.tgt: Add x86_64- and i?86-*-freebsd* targets.
 
 2020-05-01  Andreas Tobler  <andreast@gcc.gnu.org>
 
diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt
index 5d46990eba4..52503f1a880 100644
--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -22,6 +22,8 @@
 TSAN_TARGET_DEPENDENT_OBJECTS=
 SANITIZER_COMMON_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


More information about the Gcc-cvs mailing list