diff mbox

[Revisedx3] Enable libsanitizer on darwin

Message ID 20121115174249.GA15356@bromo.med.uc.edu
State New
Headers show

Commit Message

Jack Howarth Nov. 15, 2012, 5:42 p.m. UTC
The attached patch assumes that the current mach_override/mach_override.h and
mach_override/mach_override.c files have been imported by the libsanitizer maintainers
from llvm compiler-rt svn for use by darwin. The patch adds darwin to the supported
target list in configure.tgt and defines USING_MACH_OVERRIDE for darwin in 
configure.ac. The definition of USING_MACH_OVERRIDE is used in Makefile.am as
the test for appending mach_override/mach_override.c to libinterception_la_SOURCES.
LINK_COMMAND_SPEC_A in gcc/config/darwin.h is modified to add an entry to handle
faddress-sanitizer so that the required linkages are used for libasan. The static
linkage of libasan.a in LINK_COMMAND_SPEC_A is handle separately for -static-libstdc++
(which requires libstdc++.a) and the -static, -static-gcc and -static-gfortran cases.
Tested on x86_64-apple-darwin12 against the mach_override/mach_override.h and
mach_override/mach_override.c from llvm compiler-rt svn for both -m32 and -m64 with
the both use-after-free.c testcase and...

 make -k check RUNTESTFLAGS="asan.exp --target_board=unix'{-m32,-m64}'"

without regressions.
              Jack
ps Note that this patch assumes that both mach_override.h and mach_override.c
reside in a mach_override subdirectory in interception as is the case in the
llvm's compiler-rt.

gcc/

2012-11-15  Jack Howarth <howarth@bromo.med.uc.edu>

	* config/darwin.h (LINK_COMMAND_SPEC_A): Deal with -faddress-sanitizer.

libsanitizer/

2012-11-15  Jack Howarth <howarth@bromo.med.uc.edu>

	* configure.tgt: Add darwin to supported targets.
	* configure.ac: Define USING_MACH_OVERRIDE when on darwin.
	* interception/Makefile.am: Compile mach_override.c when
	USING_MACH_OVERRIDE defined.
	* configure: Regenerated.
	* interception/Makefile.in: Likewise.

Comments

Mike Stump Nov. 15, 2012, 10:06 p.m. UTC | #1
On Nov 15, 2012, at 9:42 AM, Jack Howarth <howarth@bromo.med.uc.edu> wrote:
> The attached patch assumes that the current mach_override/mach_override.h and
> mach_override/mach_override.c files have been imported by the libsanitizer maintainers
> from llvm compiler-rt svn for use by darwin. The patch adds darwin to the supported
> target list in configure.tgt and defines USING_MACH_OVERRIDE for darwin in 
> configure.ac.

I'm tending to want to approve this…  Any known downsides from the asan people?
diff mbox

Patch

Index: libsanitizer/interception/Makefile.am
===================================================================
--- libsanitizer/interception/Makefile.am	(revision 193537)
+++ libsanitizer/interception/Makefile.am	(working copy)
@@ -14,7 +14,11 @@  interception_files = \
         interception_mac.cc \
         interception_win.cc
 
-libinterception_la_SOURCES = $(interception_files) 
+if USING_MACH_OVERRIDE
+libinterception_la_SOURCES = $(interception_files) mach_override/mach_override.c
+else
+libinterception_la_SOURCES = $(interception_files)
+endif
 
 # Work around what appears to be a GNU make bug handling MAKEFLAGS
 # values defined in terms of make variables, as is the case for CC and
Index: libsanitizer/configure.ac
===================================================================
--- libsanitizer/configure.ac	(revision 193537)
+++ libsanitizer/configure.ac	(working copy)
@@ -22,6 +22,12 @@  AC_CANONICAL_SYSTEM
 target_alias=${target_alias-$host_alias}
 AC_SUBST(target_alias)
 
+case "$host" in
+  *-*-darwin*) MACH_OVERRIDE=true ;;
+  *) MACH_OVERRIDE=false ;;
+esac
+AM_CONDITIONAL(USING_MACH_OVERRIDE, $MACH_OVERRIDE)
+
 AM_INIT_AUTOMAKE(foreign)
 AM_ENABLE_MULTILIB(, ..)
 
Index: libsanitizer/configure.tgt
===================================================================
--- libsanitizer/configure.tgt	(revision 193537)
+++ libsanitizer/configure.tgt	(working copy)
@@ -22,6 +22,8 @@ 
 case "${target}" in
   x86_64-*-linux* | i?86-*-linux*)
 	;;
+  x86_64-*-darwin* | i?86-*-darwin*)
+	;;
   *)
 	UNSUPPORTED=1
 	;;
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 193537)
+++ gcc/config/darwin.h	(working copy)
@@ -180,6 +180,9 @@  extern GTY(()) int darwin_ms_struct;
     %{L*} %(link_libgcc) %o %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
     %{fopenmp|ftree-parallelize-loops=*: \
       %{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } } \
+    %{faddress-sanitizer: \
+      %{static|static-libgcc|static-libgfortran: -framework CoreFoundation -lstdc++ libasan.a%s; \
+      static-libstdc++: -framework CoreFoundation libstdc++.a%s libasan.a%s; : -framework CoreFoundation -lasan } } \
     %{fgnu-tm: \
       %{static|static-libgcc|static-libstdc++|static-libgfortran: libitm.a%s; : -litm } } \
     %{!nostdlib:%{!nodefaultlibs:\