<p dir="ltr">This needs a regression test for the driver.</p>
<div class="gmail_quote">On Nov 16, 2012 4:55 AM, "Alexey Samsonov" <<a href="mailto:samsonov@google.com">samsonov@google.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: samsonov<br>
Date: Fri Nov 16 06:53:14 2012<br>
New Revision: 168168<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=168168&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=168168&view=rev</a><br>
Log:<br>
UBSan: enable proper linking with UBsan runtime on Darwin. Turn on building ubsan on OS X in 'make' build system. Patch by Jean-Daniel Dupas.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Driver/ToolChains.cpp<br>
    cfe/trunk/lib/Driver/Tools.cpp<br>
    cfe/trunk/runtime/compiler-rt/Makefile<br>
<br>
Modified: cfe/trunk/lib/Driver/ToolChains.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=168168&r1=168167&r2=168168&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=168168&r1=168167&r2=168168&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)<br>
+++ cfe/trunk/lib/Driver/ToolChains.cpp Fri Nov 16 06:53:14 2012<br>
@@ -317,12 +317,29 @@<br>
<br>
   SanitizerArgs Sanitize(getDriver(), Args);<br>
<br>
+  // Add Ubsan runtime library, if required.<br>
+  if (Sanitize.needsUbsanRt()) {<br>
+    if (Args.hasArg(options::OPT_dynamiclib) ||<br>
+        Args.hasArg(options::OPT_bundle)) {<br>
+      // Assume the binary will provide the Ubsan runtime.<br>
+    } else if (isTargetIPhoneOS()) {<br>
+      getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)<br>
+        << "-fsanitize=undefined";<br>
+    } else {<br>
+      AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a");<br>
+<br>
+      // The Ubsan runtime library requires C++.<br>
+      AddCXXStdlibLibArgs(Args, CmdArgs);<br>
+    }<br>
+  }<br>
+<br>
   // Add ASAN runtime library, if required. Dynamic libraries and bundles<br>
   // should not be linked with the runtime library.<br>
   if (Sanitize.needsAsanRt()) {<br>
     if (Args.hasArg(options::OPT_dynamiclib) ||<br>
-        Args.hasArg(options::OPT_bundle)) return;<br>
-    if (isTargetIPhoneOS()) {<br>
+        Args.hasArg(options::OPT_bundle)) {<br>
+      // Assume the binary will provide the ASan runtime.<br>
+    } else if (isTargetIPhoneOS()) {<br>
       getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)<br>
         << "-fsanitize=address";<br>
     } else {<br>
<br>
Modified: cfe/trunk/lib/Driver/Tools.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=168168&r1=168167&r2=168168&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=168168&r1=168167&r2=168168&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Nov 16 06:53:14 2012<br>
@@ -4710,10 +4710,11 @@<br>
   Args.AddAllArgs(CmdArgs, options::OPT_L);<br>
<br>
   SanitizerArgs Sanitize(getToolChain().getDriver(), Args);<br>
-  // If we're building a dynamic lib with -fsanitize=address, unresolved<br>
-  // symbols may appear. Mark all of them as dynamic_lookup.<br>
-  // Linking executables is handled in lib/Driver/ToolChains.cpp.<br>
-  if (Sanitize.needsAsanRt()) {<br>
+  // If we're building a dynamic lib with -fsanitize=address, or<br>
+  // -fsanitize=undefined, unresolved symbols may appear. Mark all<br>
+  // of them as dynamic_lookup. Linking executables is handled in<br>
+  // lib/Driver/ToolChains.cpp.<br>
+  if (Sanitize.needsAsanRt() || Sanitize.needsUbsanRt()) {<br>
     if (Args.hasArg(options::OPT_dynamiclib) ||<br>
         Args.hasArg(options::OPT_bundle)) {<br>
       CmdArgs.push_back("-undefined");<br>
<br>
Modified: cfe/trunk/runtime/compiler-rt/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/compiler-rt/Makefile?rev=168168&r1=168167&r2=168168&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/compiler-rt/Makefile?rev=168168&r1=168167&r2=168168&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/runtime/compiler-rt/Makefile (original)<br>
+++ cfe/trunk/runtime/compiler-rt/Makefile Fri Nov 16 06:53:14 2012<br>
@@ -76,7 +76,8 @@<br>
 RuntimeLibrary.darwin.Configs := \<br>
        eprintf.a 10.4.a osx.a ios.a cc_kext.a cc_kext_ios5.a \<br>
        asan_osx.a asan_osx_dynamic.dylib \<br>
-       profile_osx.a profile_ios.a<br>
+       profile_osx.a profile_ios.a \<br>
+       ubsan_osx.a<br>
 endif<br>
<br>
 # On Linux, include a library which has all the runtime functions.<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>