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

Richard Smith richard at metafoo.co.uk
Thu Oct 4 11:53:22 PDT 2012


On Thu, Oct 4, 2012 at 3:36 AM, PaX Team <pageexec at freemail.hu> wrote:

> 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).


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121004/9bb1858d/attachment.html>


More information about the llvm-commits mailing list