On Thu, Oct 4, 2012 at 3:36 AM, PaX Team <span dir="ltr"><<a href="mailto:pageexec@freemail.hu" target="_blank">pageexec@freemail.hu</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 4 Oct 2012 at 1:36, Richard Smith wrote:<br>
<br>
> Hi,<br>
><br>
> The attached patches to compiler-rt and Clang add a new runtime library<br>
> which -fcatch-undefined-behavior will call into when it detects undefined<br>
> behavior.<br>
<br>
</div>Index: lib/Driver/Tools.cpp<br>
===================================================================<br>
--- lib/Driver/Tools.cpp        (revision 164853)<br>
+++ lib/Driver/Tools.cpp        (working copy)<br>
@@ -1458,6 +1458,23 @@<br>
   }<br>
 }<br>
<br>
+/// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags<br>
+/// (Linux).<br>
+static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args,<br>
+                            ArgStringList &CmdArgs) {<br>
+  if (!Args.hasArg(options::OPT_fcatch_undefined_behavior))<br>
+    return;<br>
+  if (!Args.hasArg(options::OPT_shared)) {<br>
+    // LibUbsan is "libclang_rt.ubsan-<ArchName>.a" in the Linux library<br>
+    // resource directory.<br>
+    SmallString<128> LibUbsan(TC.getDriver().ResourceDir);<br>
+    llvm::sys::path::append(LibUbsan, "lib", "linux",<br>
+                            (Twine("libclang_rt.ubsan-") +<br>
+                             TC.getArchName() + ".a"));<br>
+    CmdArgs.push_back(Args.MakeArgString(LibUbsan));<br>
+  }<br>
+}<br>
<br>
would it be possible to check for -ffreestanding here and not add the library<br>
forcibly in that case? i'm (once again ;) thinking of a kernel environment here<br>
where using such a library may not be an option (no c++ allowed for one) and the<br>
kernel would like to handle these functions in its own way (much like it handles<br>
memcpy, etc already).</blockquote><div><br></div><div>It would certainly be possible, but I'm not in favor of it, because I'm not happy to make API stability guarantees for the compiler->runtime interface. I'd much rather provide a stable API for some (replaceable) diagnostic reporting facility within the runtime. You can get the effect you're asking for by not specifying -fcatch-undefined-behavior when you link, but if you go down this path, I won't promise not to break you.</div>
</div>