<div dir="ltr"><div>Hi Steven,</div><div><br></div><div>This looks interesting and raises a number of questions :)</div><div><br></div><div>1) Does applying this patch actually bring working sanitizers to x32 platform?</div>
<div>That is, after you build the clang, does "clang -fsanitize=whatever foo.c" compile/link/run with expected results?</div><div>I doubt that, as there is some platform-specific code in all the sanitizers, and many of them heavily depend</div>
<div>on the address space layout. Porting TSan and MSan to 32-bit address space is especially hard, and we don't plan</div><div>to do this anytime soon. I think it makes sense to build only the libraries that are expected to work on a given arch.</div>
<div><br></div><div>2) If we're stepping on the path of porting some sanitizers to x32, it would be great to</div><div>setup a buildbot, make our tests pass cleanly, and make this bot public to catch regressions.</div>
<div>Do you have plans for that? Running sanitizer test suites also leads us to...</div><div><br></div><div>3) Do you plan to add support for building sanitizers on x32 to CMake build system? It would</div><div>make sense (and, in fact, I would start from there), as our testsuite can be run only in CMake builds.</div>
<br><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 22, 2013 at 10:09 AM, Steven Newbury <span dir="ltr"><<a href="mailto:steve@snewbury.org.uk" target="_blank">steve@snewbury.org.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">X32 support patch for compiler-rt.  Applies against current trunk.<br>
<br>
--- projects/compiler-rt/make/platform/<a href="http://clang_linux.mk" target="_blank">clang_linux.mk</a>~  2013-08-21<br>
06:27:38.000000000 +0000<br>
+++ projects/compiler-rt/make/platform/<a href="http://clang_linux.mk" target="_blank">clang_linux.mk</a>   2013-08-21<br>
11:16:55.891621025 +0000<br>
@@ -41,7 +41,18 @@<br>
     SupportedArches += x86_64<br>
   endif<br>
 else<br>
-  SupportedArches := x86_64<br>
+  # x86-64 arch has two ABIs 64 bit x86-64 and 32 bit x32<br>
+  ifeq ($(lastword $(subst -gnu, ,$(CompilerTargetTriple))),x32)<br>
+    SupportedArches := x32<br>
+    ifeq ($(call TryCompile,$(CC),$(test_source),-m64),0)<br>
+      SupportedArches += x86_64<br>
+    endif<br>
+  else<br>
+    SupportedArches := x86_64<br>
+    ifeq ($(call TryCompile,$(CC),$(test_source),-mx32),0)<br>
+      SupportedArches += x32<br>
+    endif<br>
+  endif<br>
   ifeq ($(call TryCompile,$(CC),$(test_source),-m32),0)<br>
     SupportedArches += i386<br>
   endif<br>
@@ -74,6 +85,22 @@<br>
 Arch.lsan-x86_64 := x86_64<br>
 endif<br>
<br>
+# Build runtime libraries for x32.<br>
+ifeq ($(call contains,$(SupportedArches),x32),true)<br>
+Configs += full-x32 profile-x32 san-x32 asan-x32 tsan-x32 \<br>
+           msan-x32 ubsan-x32 ubsan_cxx-x32 dfsan-x32 lsan-x32<br>
+Arch.full-x32 := x32<br>
+Arch.profile-x32 := x32<br>
+Arch.san-x32 := x32<br>
+Arch.asan-x32 := x32<br>
+Arch.tsan-x32 := x32<br>
+Arch.msan-x32 := x32<br>
+Arch.ubsan-x32 := x32<br>
+Arch.ubsan_cxx-x32 := x32<br>
+Arch.dfsan-x32 := x32<br>
+Arch.lsan-x32 := x32<br>
+endif<br>
+<br>
 ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),)<br>
 Configs += asan-arm-android<br>
 Arch.asan-arm-android := arm-android<br>
@@ -89,22 +116,33 @@<br>
<br>
 CFLAGS.full-i386 := $(CFLAGS) -m32<br>
 CFLAGS.full-x86_64 := $(CFLAGS) -m64<br>
+CFLAGS.full-x32 := $(CFLAGS) -mx32<br>
 CFLAGS.profile-i386 := $(CFLAGS) -m32<br>
 CFLAGS.profile-x86_64 := $(CFLAGS) -m64<br>
+CFLAGS.profile-x32 := $(CFLAGS) -mx32<br>
 CFLAGS.san-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti<br>
 CFLAGS.san-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti<br>
+CFLAGS.san-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS) -fno-rtti<br>
 CFLAGS.asan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti \<br>
                     -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1<br>
 CFLAGS.asan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti \<br>
                     -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1<br>
+CFLAGS.asan-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS) -fno-rtti \<br>
+                    -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1<br>
 CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti<br>
+CFLAGS.tsan-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS) -fno-rtti<br>
 CFLAGS.msan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti<br>
+CFLAGS.msan-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS) -fno-rtti<br>
 CFLAGS.ubsan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti<br>
 CFLAGS.ubsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti<br>
+CFLAGS.ubsan-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS) -fno-rtti<br>
 CFLAGS.ubsan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS)<br>
 CFLAGS.ubsan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS)<br>
+CFLAGS.ubsan_cxx-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS)<br>
 CFLAGS.dfsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS)<br>
+CFLAGS.dfsan-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS)<br>
 CFLAGS.lsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS)<br>
+CFLAGS.lsan-x32 := $(CFLAGS) -mx32 $(SANITIZER_CFLAGS)<br>
<br>
 SHARED_LIBRARY.asan-arm-android := 1<br>
 ANDROID_COMMON_FLAGS := -target arm-linux-androideabi \<br>
@@ -120,30 +158,45 @@<br>
 # enough support to build the sanitizers or profile runtimes.<br>
 CFLAGS.full-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux<br>
 CFLAGS.full-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux<br>
+CFLAGS.full-x32 += --sysroot=$(ProjSrcRoot)/SDKs/linux<br>
<br>
 FUNCTIONS.full-i386 := $(CommonFunctions) $(ArchFunctions.i386)<br>
 FUNCTIONS.full-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64)<br>
+FUNCTIONS.full-x32 := $(CommonFunctions) $(ArchFunctions.x32)<br>
 FUNCTIONS.profile-i386 := GCDAProfiling<br>
 FUNCTIONS.profile-x86_64 := GCDAProfiling<br>
+FUNCTIONS.profile-x32 := GCDAProfiling<br>
 FUNCTIONS.san-i386 := $(SanitizerCommonFunctions)<br>
 FUNCTIONS.san-x86_64 := $(SanitizerCommonFunctions)<br>
+FUNCTIONS.san-x32 := $(SanitizerCommonFunctions)<br>
 FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \<br>
                                         $(SanitizerCommonFunctions)<br>
 FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \<br>
                          $(SanitizerCommonFunctions)<br>
$(LsanCommonFunctions)<br>
+FUNCTIONS.asan-x32 := $(AsanFunctions) $(InterceptionFunctions) \<br>
+                         $(SanitizerCommonFunctions)<br>
$(LsanCommonFunctions)<br>
 FUNCTIONS.asan-arm-android := $(AsanFunctions) $(InterceptionFunctions)<br>
\<br>
                                           $(SanitizerCommonFunctions)<br>
 FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \<br>
                                           $(SanitizerCommonFunctions)<br>
+FUNCTIONS.tsan-x32 := $(TsanFunctions) $(InterceptionFunctions) \<br>
+                                          $(SanitizerCommonFunctions)<br>
 FUNCTIONS.msan-x86_64 := $(MsanFunctions) $(InterceptionFunctions) \<br>
                                           $(SanitizerCommonFunctions)<br>
+FUNCTIONS.msan-x32 := $(MsanFunctions) $(InterceptionFunctions) \<br>
+                                          $(SanitizerCommonFunctions)<br>
 FUNCTIONS.ubsan-i386 := $(UbsanFunctions)<br>
 FUNCTIONS.ubsan-x86_64 := $(UbsanFunctions)<br>
+FUNCTIONS.ubsan-x32 := $(UbsanFunctions)<br>
 FUNCTIONS.ubsan_cxx-i386 := $(UbsanCXXFunctions)<br>
 FUNCTIONS.ubsan_cxx-x86_64 := $(UbsanCXXFunctions)<br>
+FUNCTIONS.ubsan_cxx-x32 := $(UbsanCXXFunctions)<br>
 FUNCTIONS.dfsan-x86_64 := $(DfsanFunctions) $(SanitizerCommonFunctions)<br>
+FUNCTIONS.dfsan-x32 := $(DfsanFunctions) $(SanitizerCommonFunctions)<br>
 FUNCTIONS.lsan-x86_64 := $(LsanFunctions) $(InterceptionFunctions) \<br>
                                           $(SanitizerCommonFunctions)<br>
+FUNCTIONS.lsan-x32 := $(LsanFunctions) $(InterceptionFunctions) \<br>
+                                          $(SanitizerCommonFunctions)<br>
<br>
 # Always use optimized variants.<br>
 OPTIMIZED := 1<br>
--- tools/clang/runtime/compiler-rt/Makefile.orig       2013-08-21<br>
16:20:43.915932247 +0000<br>
+++ tools/clang/runtime/compiler-rt/Makefile    2013-08-21<br>
17:03:15.856154519 +0000<br>
@@ -96,29 +96,66 @@<br>
     $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \<br>
     echo $$?)<br>
<br>
-# We try to build 32-bit runtimes both on 32-bit hosts and 64-bit<br>
hosts.<br>
-Runtime32BitConfigs = \<br>
+# We try to build x86 runtimes both on x86 hosts and 64-bit hosts.<br>
+Runtimex86Configs = \<br>
        full-i386.a profile-i386.a san-i386.a asan-i386.a ubsan-i386.a \<br>
        ubsan_cxx-i386.a<br>
<br>
+Runtime64BitConfigs = \<br>
+       full-x86_64.a profile-x86_64.a san-x86_64.a asan-x86_64.a \<br>
+       tsan-x86_64.a msan-x86_64.a ubsan-x86_64.a ubsan_cxx-x86_64.a \<br>
+       dfsan-x86_64.a lsan-x86_64.a<br>
+<br>
+Runtimex32Configs += \<br>
+       full-x32.a profile-x32.a san-x32.a asan-x32.a \<br>
+       tsan-x32.a msan-x32.a ubsan-x32.a ubsan_cxx-x32.a \<br>
+       dfsan-x32.a lsan-x32.a<br>
+<br>
+<br>
 # We currently only try to generate runtime libraries on x86.<br>
 ifeq ($(ARCH),x86)<br>
-RuntimeLibrary.linux.Configs += $(Runtime32BitConfigs)<br>
+RuntimeLibrary.linux.Configs += $(Runtimex86Configs)<br>
+<br>
+ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),)<br>
+RuntimeLibrary.linux.Configs += asan-arm-android.so<br>
+endif<br>
 endif<br>
<br>
 ifeq ($(ARCH),x86_64)<br>
-RuntimeLibrary.linux.Configs += \<br>
-       full-x86_64.a profile-x86_64.a san-x86_64.a asan-x86_64.a \<br>
-       tsan-x86_64.a msan-x86_64.a ubsan-x86_64.a ubsan_cxx-x86_64.a \<br>
-       dfsan-x86_64.a lsan-x86_64.a<br>
-# We need to build 32-bit ASan/UBsan libraries on 64-bit platform, and<br>
add them<br>
+CompilerTargetTriple := $(shell \<br>
+       $(CC) -v 2>&1 | grep 'Target:' | cut -d' ' -f2)<br>
+ifeq ($(CompilerTargetTriple),)<br>
+$(error "unable to infer compiler target triple for $(CC)")<br>
+endif<br>
+ifeq ($(lastword $(subst -gnu, ,$(CompilerTargetTriple))),x32)<br>
+ARCH=x32<br>
+RuntimeLibrary.linux.Configs += $(Runtimex32Configs)<br>
+# We need to build x86 ASan/UBsan libraries on x32 platform, and add<br>
them<br>
 # to the list of runtime libraries to make<br>
-# "clang -fsanitize=(address|undefined) -m32" work.<br>
-# We check that Clang can produce working 32-bit binaries by compiling<br>
a simple<br>
+# "clang -fsanitize=(address|undefined) -m32/-m64" work.<br>
+# We check that Clang can produce working 32/64-bit binaries by<br>
compiling a simple<br>
 # executable.<br>
 test_source =<br>
$(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c<br>
+ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m64),0)<br>
+RuntimeLibrary.linux.Configs += $(Runtime64BitConfigs)<br>
+endif<br>
 ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0)<br>
-RuntimeLibrary.linux.Configs += $(Runtime32BitConfigs)<br>
+RuntimeLibrary.linux.Configs += $(Runtimex86Configs)<br>
+endif<br>
+else<br>
+RuntimeLibrary.linux.Configs += $(Runtime64BitConfigs)<br>
+# We need to build x86/x32 ASan/UBsan libraries on 64-bit platform, and<br>
add them<br>
+# to the list of runtime libraries to make<br>
+# "clang -fsanitize=(address|undefined) -m32/-mx32" work.<br>
+# We check that Clang can produce working x86 binaries by compiling a<br>
simple<br>
+# executable.<br>
+test_source =<br>
$(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c<br>
+ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0)<br>
+RuntimeLibrary.linux.Configs += $(Runtimex86Configs)<br>
+endif<br>
+ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-mx32),0)<br>
+RuntimeLibrary.linux.Configs += $(Runtimex32Configs)<br>
+endif<br>
 endif<br>
 ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),)<br>
 RuntimeLibrary.linux.Configs += asan-arm-android.so<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div></div>