This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libsanitizer] Fix Mac OS X 10.7 bootstrap (PR sanitizer/82824)


Mac OS X 10.7 bootstrap is currently broken in libsanitizer since
lsan/lsan_common_mac.cc uses VM_MEMORY_OS_ALLOC_ONCE which was only
introduced in Mac OS X 10.9.  Upstream rejected the trivial patch to
make the use conditional since that's likely to be unreliable:

	https://reviews.llvm.org/D39888

Given that the macro is used in a file that's compiled even when lsan
isn't supported (as on Mac OS X, probably due to lsan's use of the
blocks extension that gcc doesn't support), the reasonable solution
seems to be to allow predefining CAN_SANITIZE_LEAKS in
lsan/lsan_common.h and disable that in the build system so the affected
files are effectively empty.

When I tried to do this within LLVM's build system, I ran into so many
road blocks with building LLVM trunk on Mac OS X 10.7 (and 10.13) with
gcc that I gave up.  Perhaps the two-line change to lsan/lsan_common.h
can still go upstream, otherwise it would have to be gcc-local like
similar code for CAN_SANITIZE_UB in ubsan/ubsan_platform.h.

The rest of the patch is gcc-private anyway since it only affects the
build system.  It consists of two parts:

* Defining CAN_SANITIZE_LEAKS=0 for affected Mac OS X versions
  (everything before Darwin 13/Mac OS X 10.9).

* This is not enough, however: before Xcode 4.5, the Darwin ld cannot
  handle undefined weak symbols which are now assumed to be supported on
  Darwin since the last libsanitizer import from upstream.  Fortunately,
  one can define SANITIZER_SUPPORTS_WEAK_HOOKS=0 to avoid this, which
  the patch does as well, again by a OS version test since a proper
  configure test is probably too involved.

Tested by rebuilding libsanitizer on x86_64-apple-darwin11.4.2 and
running the {asan,tsan,ubsan}.exp tests for both multilibs: testresults
are now en par with Darwin 17.

I've also bootstrapped the test on x86_64-pc-linux-gnu to check that
neither defines above are enabled.

Ok for mainline?

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2017-11-13  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	PR sanitizer/82824
	* configure.ac (LSAN_COMMON_SUPPORTED): New conditional.  Disable
	before *-*-darwin13*.
	(WEAK_HOOKS_SUPPORT): New conditional.
	* configure: Regenerate.
	* asan/Makefile.am (DEFS) [!LSAN_COMMON_SUPPORTED]: Disable
	CAN_SANITIZE_LEAKS.
	(DEFS) [!LSAN_COMMON_SUPPORTED]: Disable
	SANITIZER_SUPPORTS_WEAK_HOOKS.
	* asan/Makefile.in: Regenerate.
	* lsan/Makefile.am (DEFS) [!LSAN_COMMON_SUPPORTED]: Disable
	CAN_SANITIZE_LEAKS.
	(DEFS) [!LSAN_COMMON_SUPPORTED]: Disable
	SANITIZER_SUPPORTS_WEAK_HOOKS.
	* lsan/Makefile.in: Regenerate.
	* lsan/lsan_common.h: Allow predefining CAN_SANITIZE_LEAKS.
	* sanitizer_common/Makefile.am (DEFS) [!LSAN_COMMON_SUPPORTED]:
	Disable SANITIZER_SUPPORTS_WEAK_HOOKS.
	* sanitizer_common/Makefile.in: Regenerate.

# HG changeset patch
# Parent  eaaab03d905888004baa739a681a239d4b4e3d29
Fix Mac OS X 10.7 bootstrap

diff --git a/libsanitizer/asan/Makefile.am b/libsanitizer/asan/Makefile.am
--- a/libsanitizer/asan/Makefile.am
+++ b/libsanitizer/asan/Makefile.am
@@ -7,6 +7,12 @@ DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_C
 if USING_MAC_INTERPOSE
 DEFS += -DMAC_INTERPOSE_FUNCTIONS -DMISSING_BLOCKS_SUPPORT
 endif
+if !LSAN_COMMON_SUPPORTED
+DEFS += -DCAN_SANITIZE_LEAKS=0
+endif
+if !WEAK_HOOKS_SUPPORT
+DEFS += -DSANITIZER_SUPPORTS_WEAK_HOOKS=0
+endif
 AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros -fno-ipa-icf
 AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS)
 AM_CXXFLAGS += -std=gnu++11
diff --git a/libsanitizer/configure.ac b/libsanitizer/configure.ac
--- a/libsanitizer/configure.ac
+++ b/libsanitizer/configure.ac
@@ -140,6 +140,24 @@ case "$host" in
 esac
 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
 
+# lsan_common_mac.cc needs VM_MEMORY_OS_ALLOC_ONCE which was only
+# introduced in Mac OS X 10.9/Darwin 13.
+case "$host" in
+  *-*-darwin[[1-9]] | *-*-darwin[[1-9]].* | *-*-darwin1[[0-2]]*)
+    LSAN_COMMON=false ;;
+  *) LSAN_COMMON=true ;;
+esac
+AM_CONDITIONAL(LSAN_COMMON_SUPPORTED, $LSAN_COMMON)
+
+# Before Xcode 4.5, the Darwin linker doesn't properly support undefined
+# weak symbols.
+case "$host" in
+  *-*-darwin[[1-9]] | *-*-darwin[[1-9]].* | *-*-darwin1[[0-2]]*)
+    WEAK_HOOKS=false ;;
+  *) WEAK_HOOKS=true ;;
+esac
+AM_CONDITIONAL(WEAK_HOOKS_SUPPORT, $WEAK_HOOKS)
+
 backtrace_supported=yes
 
 AC_MSG_CHECKING([for necessary platform features])
diff --git a/libsanitizer/lsan/Makefile.am b/libsanitizer/lsan/Makefile.am
--- a/libsanitizer/lsan/Makefile.am
+++ b/libsanitizer/lsan/Makefile.am
@@ -4,6 +4,12 @@ AM_CPPFLAGS = -I $(top_srcdir)/include -
 gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
 
 DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
+if !LSAN_COMMON_SUPPORTED
+DEFS += -DCAN_SANITIZE_LEAKS=0
+endif
+if !WEAK_HOOKS_SUPPORT
+DEFS += -DSANITIZER_SUPPORTS_WEAK_HOOKS=0
+endif
 AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros
 AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS)
 AM_CXXFLAGS += -std=gnu++11
diff --git a/libsanitizer/lsan/lsan_common.h b/libsanitizer/lsan/lsan_common.h
--- a/libsanitizer/lsan/lsan_common.h
+++ b/libsanitizer/lsan/lsan_common.h
@@ -20,6 +20,7 @@
 #include "sanitizer_common/sanitizer_stoptheworld.h"
 #include "sanitizer_common/sanitizer_symbolizer.h"
 
+#ifndef CAN_SANITIZE_LEAKS
 // LeakSanitizer relies on some Glibc's internals (e.g. TLS machinery) thus
 // supported for Linux only. Also, LSan doesn't like 32 bit architectures
 // because of "small" (4 bytes) pointer size that leads to high false negative
@@ -42,6 +43,7 @@
 #else
 #define CAN_SANITIZE_LEAKS 0
 #endif
+#endif // CAN_SANITIZE_LEAKS
 
 namespace __sanitizer {
 class FlagParser;
diff --git a/libsanitizer/sanitizer_common/Makefile.am b/libsanitizer/sanitizer_common/Makefile.am
--- a/libsanitizer/sanitizer_common/Makefile.am
+++ b/libsanitizer/sanitizer_common/Makefile.am
@@ -4,6 +4,9 @@ AM_CPPFLAGS = -I $(top_srcdir)/include -
 gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
 
 DEFS = -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS @RPC_DEFS@
+if !WEAK_HOOKS_SUPPORT
+DEFS += -DSANITIZER_SUPPORTS_WEAK_HOOKS=0
+endif
 AM_CXXFLAGS = -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long  -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros
 AM_CXXFLAGS += $(LIBSTDCXX_RAW_CXX_CXXFLAGS)
 AM_CXXFLAGS += -std=gnu++11

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]