diff options
Diffstat (limited to 'clang/lib/Driver/ToolChains.cpp')
-rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index e3dab2040fc..aaaab9cecd2 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -399,26 +399,10 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, const SanitizerArgs &Sanitize = getSanitizerArgs(); - - if (Sanitize.needsAsanRt()) { - if (!isTargetMacOS() && !isTargetIOSSimulator()) { - // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds. - getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) - << "-fsanitize=address"; - } else { - AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); - } - } - - if (Sanitize.needsUbsanRt()) { - if (!isTargetMacOS() && !isTargetIOSSimulator()) { - // FIXME: Move this check to SanitizerArgs::filterUnsupportedKinds. - getDriver().Diag(diag::err_drv_clang_unsupported_per_platform) - << "-fsanitize=undefined"; - } else { - AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); - } - } + if (Sanitize.needsAsanRt()) + AddLinkSanitizerLibArgs(Args, CmdArgs, "asan"); + if (Sanitize.needsUbsanRt()) + AddLinkSanitizerLibArgs(Args, CmdArgs, "ubsan"); // Otherwise link libSystem, then the dynamic runtime library, and finally any // target specific static runtime library. @@ -1097,6 +1081,18 @@ void Darwin::CheckObjCARC() const { getDriver().Diag(diag::err_arc_unsupported_on_toolchain); } +SanitizerMask Darwin::getSupportedSanitizers() const { + SanitizerMask Res = ToolChain::getSupportedSanitizers(); + if (isTargetMacOS() || isTargetIOSSimulator()) { + // ASan and UBSan are available on Mac OS and on iOS simulator. + Res |= SanitizerKind::Address; + Res |= SanitizerKind::Vptr; + } + if (isTargetMacOS()) + Res |= SanitizerKind::SafeStack; + return Res; +} + /// Generic_GCC - A tool chain using the 'gcc' command to perform /// all subcommands; this relies on gcc translating the majority of /// command line options. @@ -2737,6 +2733,24 @@ bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } +SanitizerMask FreeBSD::getSupportedSanitizers() const { + const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; + const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; + const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || + getTriple().getArch() == llvm::Triple::mips64el; + SanitizerMask Res = ToolChain::getSupportedSanitizers(); + Res |= SanitizerKind::Address; + Res |= SanitizerKind::Vptr; + if (IsX86_64 || IsMIPS64) { + Res |= SanitizerKind::Leak; + Res |= SanitizerKind::Thread; + } + if (IsX86 || IsX86_64) { + Res |= SanitizerKind::SafeStack; + } + return Res; +} + /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. NetBSD::NetBSD(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) @@ -3641,6 +3655,27 @@ bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); } +SanitizerMask Linux::getSupportedSanitizers() const { + const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; + const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; + const bool IsMIPS64 = getTriple().getArch() == llvm::Triple::mips64 || + getTriple().getArch() == llvm::Triple::mips64el; + SanitizerMask Res = ToolChain::getSupportedSanitizers(); + Res |= SanitizerKind::Address; + Res |= SanitizerKind::Vptr; + if (IsX86_64 || IsMIPS64) { + Res |= SanitizerKind::DataFlow; + Res |= SanitizerKind::Leak; + Res |= SanitizerKind::Memory; + Res |= SanitizerKind::Thread; + } + if (IsX86 || IsX86_64) { + Res |= SanitizerKind::Function; + Res |= SanitizerKind::SafeStack; + } + return Res; +} + /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. DragonFly::DragonFly(const Driver &D, const llvm::Triple& Triple, const ArgList &Args) |