eugenis created this revision.
The linux part is a bit ahead of time - the instrumentation code where this
matters have not landed yet. But when it does, this would be the right
condition, and for now ELF instrumentation simply ignores this setting.
Repository:
rL LLVM
https://reviews.llvm.org/D32064
Files:
lib/CodeGen/BackendUtil.cpp
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -132,16 +132,20 @@
// that we add to the PassManagerBuilder.
class PassManagerBuilderWrapper : public PassManagerBuilder {
public:
- PassManagerBuilderWrapper(const CodeGenOptions ,
+ PassManagerBuilderWrapper(const Triple ,
+const CodeGenOptions ,
const LangOptions )
- : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {}
+ : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts),
+LangOpts(LangOpts) {}
+ const Triple () const { return TargetTriple; }
const CodeGenOptions () const { return CGOpts; }
const LangOptions () const { return LangOpts; }
+
private:
+ const Triple
const CodeGenOptions
const LangOptions
};
-
}
static void addObjCARCAPElimPass(const PassManagerBuilder ,
PassManagerBase ) {
@@ -188,16 +192,36 @@
PM.add(createSanitizerCoverageModulePass(Opts));
}
+// Check if ASan should use GC-friendly instrumentation for globals.
+// First of all, there is no point if -fdata-sections is off (expect for MachO,
+// where this is not a factor). Also, on ELF this feature requires an assembler
+// extension that only works with -integrated-as at the moment.
+static bool asanUseGlobalsGC(const Triple , const CodeGenOptions ) {
+ switch (T.getObjectFormat()) {
+ case Triple::MachO:
+return true;
+ case Triple::COFF:
+return CGOpts.DataSections;
+ case Triple::ELF:
+return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
+ default:
+return false;
+ }
+}
+
static void addAddressSanitizerPasses(const PassManagerBuilder ,
legacy::PassManagerBase ) {
const PassManagerBuilderWrapper =
static_cast(Builder);
+ const Triple = BuilderWrapper.getTargetTriple();
const CodeGenOptions = BuilderWrapper.getCGOpts();
bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Address);
bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope;
+ bool UseGlobalsGC = asanUseGlobalsGC(T, CGOpts);
PM.add(createAddressSanitizerFunctionPass(/*CompileKernel*/ false, Recover,
UseAfterScope));
- PM.add(createAddressSanitizerModulePass(/*CompileKernel*/false, Recover));
+ PM.add(createAddressSanitizerModulePass(/*CompileKernel*/ false, Recover,
+ UseGlobalsGC));
}
static void addKernelAddressSanitizerPasses(const PassManagerBuilder ,
@@ -435,16 +459,16 @@
if (CodeGenOpts.DisableLLVMPasses)
return;
- PassManagerBuilderWrapper PMBuilder(CodeGenOpts, LangOpts);
-
// Figure out TargetLibraryInfo. This needs to be added to MPM and FPM
// manually (and not via PMBuilder), since some passes (eg. InstrProfiling)
// are inserted before PMBuilder ones - they'd get the default-constructed
// TLI with an unknown target otherwise.
Triple TargetTriple(TheModule->getTargetTriple());
std::unique_ptr TLII(
createTLII(TargetTriple, CodeGenOpts));
+ PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);
+
// At O0 and O1 we only run the always inliner which is more efficient. At
// higher optimization levels we run the normal inliner.
if (CodeGenOpts.OptimizationLevel <= 1) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -132,16 +132,20 @@
// that we add to the PassManagerBuilder.
class PassManagerBuilderWrapper : public PassManagerBuilder {
public:
- PassManagerBuilderWrapper(const CodeGenOptions ,
+ PassManagerBuilderWrapper(const Triple ,
+const CodeGenOptions ,
const LangOptions )
- : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {}
+ : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts),
+LangOpts(LangOpts) {}
+ const Triple () const { return TargetTriple; }
const CodeGenOptions () const { return CGOpts; }
const LangOptions () const { return LangOpts; }
+
private:
+ const Triple
const CodeGenOptions
const LangOptions
};
-
}
static void addObjCARCAPElimPass(const PassManagerBuilder , PassManagerBase ) {
@@ -188,16 +192,36 @@
PM.add(createSanitizerCoverageModulePass(Opts));
}
+// Check if ASan should use GC-friendly instrumentation for globals.
+// First of all, there is no point if -fdata-sections is off (expect