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

Rainer Orth ro@CeBiTec.Uni-Bielefeld.DE
Tue Nov 14 11:18:00 GMT 2017


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: macos-libsanitizer-lsan.patch
Type: text/x-patch
Size: 4019 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20171114/ae5080b3/attachment.bin>


More information about the Gcc-patches mailing list