[llvm-commits] [PATCH] Add -fcatch-undefined-behavior runtime library

PaX Team pageexec at freemail.hu
Thu Oct 4 03:36:58 PDT 2012


On 4 Oct 2012 at 1:36, Richard Smith wrote:

> Hi,
> 
> The attached patches to compiler-rt and Clang add a new runtime library
> which -fcatch-undefined-behavior will call into when it detects undefined
> behavior.

Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 164853)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -1458,6 +1458,23 @@
   }
 }

+/// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags
+/// (Linux).
+static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args,
+                            ArgStringList &CmdArgs) {
+  if (!Args.hasArg(options::OPT_fcatch_undefined_behavior))
+    return;
+  if (!Args.hasArg(options::OPT_shared)) {
+    // LibUbsan is "libclang_rt.ubsan-<ArchName>.a" in the Linux library
+    // resource directory.
+    SmallString<128> LibUbsan(TC.getDriver().ResourceDir);
+    llvm::sys::path::append(LibUbsan, "lib", "linux",
+                            (Twine("libclang_rt.ubsan-") +
+                             TC.getArchName() + ".a"));
+    CmdArgs.push_back(Args.MakeArgString(LibUbsan));
+  }
+}

would it be possible to check for -ffreestanding here and not add the library
forcibly in that case? i'm (once again ;) thinking of a kernel environment here
where using such a library may not be an option (no c++ allowed for one) and the
kernel would like to handle these functions in its own way (much like it handles
memcpy, etc already).

cheers,
  PaX Team




More information about the llvm-commits mailing list