forked from OSchip/llvm-project
parent
dab61684ef
commit
aea92e530d
|
@ -101,6 +101,8 @@ def err_drv_mg_requires_m_or_mm : Error<
|
||||||
"option '-MG' requires '-M' or '-MM'">;
|
"option '-MG' requires '-M' or '-MM'">;
|
||||||
def err_drv_asan_android_requires_pie : Error<
|
def err_drv_asan_android_requires_pie : Error<
|
||||||
"AddressSanitizer on Android requires '-pie'">;
|
"AddressSanitizer on Android requires '-pie'">;
|
||||||
|
def err_drv_sanitizer_requires_pie : Error<
|
||||||
|
"%select{Thread|Memory}0Sanitizer requires '-pie'">;
|
||||||
def err_drv_unknown_objc_runtime : Error<
|
def err_drv_unknown_objc_runtime : Error<
|
||||||
"unknown or ill-formed Objective-C runtime '%0'">;
|
"unknown or ill-formed Objective-C runtime '%0'">;
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@ SANITIZER("use-after-scope", UseAfterScope)
|
||||||
SANITIZER_GROUP("address-full", AddressFull,
|
SANITIZER_GROUP("address-full", AddressFull,
|
||||||
Address | InitOrder | UseAfterReturn | UseAfterScope)
|
Address | InitOrder | UseAfterReturn | UseAfterScope)
|
||||||
|
|
||||||
|
// MemorySanitizer
|
||||||
|
SANITIZER("memory", Memory)
|
||||||
|
|
||||||
// ThreadSanitizer
|
// ThreadSanitizer
|
||||||
SANITIZER("thread", Thread)
|
SANITIZER("thread", Thread)
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,11 @@ static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
|
||||||
PM.add(createAddressSanitizerModulePass(LangOpts.SanitizeInitOrder));
|
PM.add(createAddressSanitizerModulePass(LangOpts.SanitizeInitOrder));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addMemorySanitizerPass(const PassManagerBuilder &Builder,
|
||||||
|
PassManagerBase &PM) {
|
||||||
|
PM.add(createMemorySanitizerPass());
|
||||||
|
}
|
||||||
|
|
||||||
static void addThreadSanitizerPass(const PassManagerBuilder &Builder,
|
static void addThreadSanitizerPass(const PassManagerBuilder &Builder,
|
||||||
PassManagerBase &PM) {
|
PassManagerBase &PM) {
|
||||||
PM.add(createThreadSanitizerPass());
|
PM.add(createThreadSanitizerPass());
|
||||||
|
@ -227,6 +232,13 @@ void EmitAssemblyHelper::CreatePasses(TargetMachine *TM) {
|
||||||
addAddressSanitizerPasses);
|
addAddressSanitizerPasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LangOpts.SanitizeMemory) {
|
||||||
|
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
|
||||||
|
addMemorySanitizerPass);
|
||||||
|
PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
|
||||||
|
addMemorySanitizerPass);
|
||||||
|
}
|
||||||
|
|
||||||
if (LangOpts.SanitizeThread) {
|
if (LangOpts.SanitizeThread) {
|
||||||
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
|
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
|
||||||
addThreadSanitizerPass);
|
addThreadSanitizerPass);
|
||||||
|
|
|
@ -30,6 +30,7 @@ class SanitizerArgs {
|
||||||
#include "clang/Basic/Sanitizers.def"
|
#include "clang/Basic/Sanitizers.def"
|
||||||
NeedsAsanRt = AddressFull,
|
NeedsAsanRt = AddressFull,
|
||||||
NeedsTsanRt = Thread,
|
NeedsTsanRt = Thread,
|
||||||
|
NeedsMsanRt = Memory,
|
||||||
NeedsUbsanRt = (Undefined & ~Bounds) | Integer
|
NeedsUbsanRt = (Undefined & ~Bounds) | Integer
|
||||||
};
|
};
|
||||||
unsigned Kind;
|
unsigned Kind;
|
||||||
|
@ -41,6 +42,7 @@ class SanitizerArgs {
|
||||||
|
|
||||||
bool needsAsanRt() const { return Kind & NeedsAsanRt; }
|
bool needsAsanRt() const { return Kind & NeedsAsanRt; }
|
||||||
bool needsTsanRt() const { return Kind & NeedsTsanRt; }
|
bool needsTsanRt() const { return Kind & NeedsTsanRt; }
|
||||||
|
bool needsMsanRt() const { return Kind & NeedsMsanRt; }
|
||||||
bool needsUbsanRt() const { return Kind & NeedsUbsanRt; }
|
bool needsUbsanRt() const { return Kind & NeedsUbsanRt; }
|
||||||
|
|
||||||
bool sanitizesVptr() const { return Kind & Vptr; }
|
bool sanitizesVptr() const { return Kind & Vptr; }
|
||||||
|
|
|
@ -1524,6 +1524,9 @@ static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
||||||
static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
||||||
ArgStringList &CmdArgs) {
|
ArgStringList &CmdArgs) {
|
||||||
if (!Args.hasArg(options::OPT_shared)) {
|
if (!Args.hasArg(options::OPT_shared)) {
|
||||||
|
if (!Args.hasArg(options::OPT_pie))
|
||||||
|
TC.getDriver().Diag(diag::err_drv_sanitizer_requires_pie) <<
|
||||||
|
/* Thread */ 0;
|
||||||
// LibTsan is "libclang_rt.tsan-<ArchName>.a" in the Linux library
|
// LibTsan is "libclang_rt.tsan-<ArchName>.a" in the Linux library
|
||||||
// resource directory.
|
// resource directory.
|
||||||
SmallString<128> LibTsan(TC.getDriver().ResourceDir);
|
SmallString<128> LibTsan(TC.getDriver().ResourceDir);
|
||||||
|
@ -1537,6 +1540,27 @@ static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If MemorySanitizer is enabled, add appropriate linker flags (Linux).
|
||||||
|
/// This needs to be called before we add the C run-time (malloc, etc).
|
||||||
|
static void addMsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
||||||
|
ArgStringList &CmdArgs) {
|
||||||
|
if (!Args.hasArg(options::OPT_shared)) {
|
||||||
|
if (!Args.hasArg(options::OPT_pie))
|
||||||
|
TC.getDriver().Diag(diag::err_drv_sanitizer_requires_pie) <<
|
||||||
|
/* Memory */ 1;
|
||||||
|
// LibMsan is "libclang_rt.msan-<ArchName>.a" in the Linux library
|
||||||
|
// resource directory.
|
||||||
|
SmallString<128> LibMsan(TC.getDriver().ResourceDir);
|
||||||
|
llvm::sys::path::append(LibMsan, "lib", "linux",
|
||||||
|
(Twine("libclang_rt.msan-") +
|
||||||
|
TC.getArchName() + ".a"));
|
||||||
|
CmdArgs.push_back(Args.MakeArgString(LibMsan));
|
||||||
|
CmdArgs.push_back("-lpthread");
|
||||||
|
CmdArgs.push_back("-ldl");
|
||||||
|
CmdArgs.push_back("-export-dynamic");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags
|
/// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags
|
||||||
/// (Linux).
|
/// (Linux).
|
||||||
static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args,
|
||||||
|
@ -5443,6 +5467,8 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
addAsanRTLinux(getToolChain(), Args, CmdArgs);
|
addAsanRTLinux(getToolChain(), Args, CmdArgs);
|
||||||
if (Sanitize.needsTsanRt())
|
if (Sanitize.needsTsanRt())
|
||||||
addTsanRTLinux(getToolChain(), Args, CmdArgs);
|
addTsanRTLinux(getToolChain(), Args, CmdArgs);
|
||||||
|
if (Sanitize.needsMsanRt())
|
||||||
|
addMsanRTLinux(getToolChain(), Args, CmdArgs);
|
||||||
|
|
||||||
if (D.CCCIsCXX &&
|
if (D.CCCIsCXX &&
|
||||||
!Args.hasArg(options::OPT_nostdlib) &&
|
!Args.hasArg(options::OPT_nostdlib) &&
|
||||||
|
|
Loading…
Reference in New Issue