From: Alexey Samsonov Date: Fri, 16 Nov 2012 12:53:14 +0000 (+0000) Subject: UBSan: enable proper linking with UBsan runtime on Darwin. Turn on building ubsan... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75fcb193aeeec5c4f10cc39df60a5ce7526b1b28;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168168 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 819907b664..a8b33c3ec0 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -317,12 +317,29 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, SanitizerArgs Sanitize(getDriver(), Args); + // Add Ubsan runtime library, if required. + if (Sanitize.needsUbsanRt()) { + if (Args.hasArg(options::OPT_dynamiclib) || + Args.hasArg(options::OPT_bundle)) { + // Assume the binary will provide the Ubsan runtime. + } else if (isTargetIPhoneOS()) { + getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) + << "-fsanitize=undefined"; + } else { + AddLinkRuntimeLib(Args, CmdArgs, "libclang_rt.ubsan_osx.a"); + + // The Ubsan runtime library requires C++. + AddCXXStdlibLibArgs(Args, CmdArgs); + } + } + // Add ASAN runtime library, if required. Dynamic libraries and bundles // should not be linked with the runtime library. if (Sanitize.needsAsanRt()) { if (Args.hasArg(options::OPT_dynamiclib) || - Args.hasArg(options::OPT_bundle)) return; - if (isTargetIPhoneOS()) { + Args.hasArg(options::OPT_bundle)) { + // Assume the binary will provide the ASan runtime. + } else if (isTargetIPhoneOS()) { getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) << "-fsanitize=address"; } else { diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 4dea717f98..8763f7aa77 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -4710,10 +4710,11 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_L); SanitizerArgs Sanitize(getToolChain().getDriver(), Args); - // If we're building a dynamic lib with -fsanitize=address, unresolved - // symbols may appear. Mark all of them as dynamic_lookup. - // Linking executables is handled in lib/Driver/ToolChains.cpp. - if (Sanitize.needsAsanRt()) { + // If we're building a dynamic lib with -fsanitize=address, or + // -fsanitize=undefined, unresolved symbols may appear. Mark all + // of them as dynamic_lookup. Linking executables is handled in + // lib/Driver/ToolChains.cpp. + if (Sanitize.needsAsanRt() || Sanitize.needsUbsanRt()) { if (Args.hasArg(options::OPT_dynamiclib) || Args.hasArg(options::OPT_bundle)) { CmdArgs.push_back("-undefined"); diff --git a/runtime/compiler-rt/Makefile b/runtime/compiler-rt/Makefile index 3475d24e9b..cb38f96719 100644 --- a/runtime/compiler-rt/Makefile +++ b/runtime/compiler-rt/Makefile @@ -76,7 +76,8 @@ RuntimeDirs += darwin RuntimeLibrary.darwin.Configs := \ eprintf.a 10.4.a osx.a ios.a cc_kext.a cc_kext_ios5.a \ asan_osx.a asan_osx_dynamic.dylib \ - profile_osx.a profile_ios.a + profile_osx.a profile_ios.a \ + ubsan_osx.a endif # On Linux, include a library which has all the runtime functions.