[PATCH] D26764: [compiler-rt] [cmake] Remove i686 target that is duplicate to i386
eugenis accepted this revision. eugenis added a comment. This revision is now accepted and ready to land. LGTM https://reviews.llvm.org/D26764 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26796: [Driver] Use arch type to find compiler-rt libraries (on Linux)
eugenis accepted this revision. eugenis added a comment. This revision is now accepted and ready to land. LGTM https://reviews.llvm.org/D26796 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31760: [lsan] Enable LSan on arm Linux, clang part
eugenis added inline comments. Comment at: lib/Driver/ToolChains/Linux.cpp:867 getTriple().getArch() == llvm::Triple::aarch64_be; + const bool IsArmArch = getTriple().getArch() == llvm::Triple::arm; SanitizerMask Res = ToolChain::getSupportedSanitizers(); I think we should also check for thumb. We allow asan on thumb, it would be surprising if lsan was not allowed. Repository: rL LLVM https://reviews.llvm.org/D31760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31760: [lsan] Enable LSan on arm Linux, clang part
eugenis added a comment. I think it should also include armeb and thumbeb for completeness. Repository: rL LLVM https://reviews.llvm.org/D31760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31760: [lsan] Enable LSan on arm Linux, clang part
eugenis accepted this revision. eugenis added a comment. This revision is now accepted and ready to land. LGTM Repository: rL LLVM https://reviews.llvm.org/D31760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and CGOpts
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 &CGOpts, + PassManagerBuilderWrapper(const Triple &TargetTriple, +const CodeGenOptions &CGOpts, const LangOptions &LangOpts) - : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {} + : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts), +LangOpts(LangOpts) {} + const Triple &getTargetTriple() const { return TargetTriple; } const CodeGenOptions &getCGOpts() const { return CGOpts; } const LangOptions &getLangOpts() const { return LangOpts; } + private: + const Triple &TargetTriple; const CodeGenOptions &CGOpts; const LangOptions &LangOpts; }; - } static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { @@ -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 &T, const CodeGenOptions &CGOpts) { + 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 &Builder, legacy::PassManagerBase &PM) { const PassManagerBuilderWrapper &BuilderWrapper = static_cast(Builder); + const Triple &T = BuilderWrapper.getTargetTriple(); const CodeGenOptions &CGOpts = 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 &Builder, @@ -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 &CGOpts, + PassManagerBuilderWrapper(const Triple &TargetTriple, +const CodeGenOptions &CGOpts, const LangOptions &LangOpts) - : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {} + : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts), +LangOpts(LangOpts) {} + const Triple &getTargetTriple() const { return TargetTriple; } const CodeGenOptions &getCGOpts() const { return CGOpts; } const LangOptions &getLangOpts() const { return LangOpts; } + private: + const Triple &TargetTriple; const CodeGenOptions &CGOpts; const LangOptions &LangOpts; }; - } static void addObjCARCAPEl
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and CGOpts
eugenis added a comment. From a quick look at the code, it seems like -fno-data-sections on COFF would suppress GC of globals the same as on ELF. Is that true? Repository: rL LLVM https://reviews.llvm.org/D32064 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis updated this revision to Diff 95254. eugenis retitled this revision from "[asan] Disable ASan global-GC depending on the target and CGOpts" to "[asan] Disable ASan global-GC depending on the target and compiler flags". Repository: rL LLVM https://reviews.llvm.org/D32064 Files: lib/Driver/SanitizerArgs.cpp test/Driver/asan-gc.c Index: test/Driver/asan-gc.c === --- /dev/null +++ test/Driver/asan-gc.c @@ -0,0 +1,14 @@ +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-data-sections -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-integrated-as -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC + +// RUN: %clang -target x86_64-apple-macosx10.11.0 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang -target x86_64-apple-macosx10.11.0 -fsanitize=address -fno-integrated-as %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC + +// RUN: %clang -target x86_64-pc-windows-msvc19.0.24215 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang -target x86_64-pc-windows-msvc19.0.24215 -fsanitize=address -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC + + +// WITHOUT-GC: "-mllvm" "-asan-globals-live-support=0" +// WITH-GC-NOT: -asan-globals-live-support=0 Index: lib/Driver/SanitizerArgs.cpp === --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -618,6 +618,29 @@ CmdArgs.push_back(Args.MakeArgString(LinkerOptionFlag)); } +// 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 useAsanGlobalsGC(const ToolChain &TC, + const llvm::opt::ArgList &Args) { + bool IntegratedAs = TC.useIntegratedAs(); + bool DataSections = + Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections, + tools::isUseSeparateSections(TC.getTriple())); + + switch (TC.getTriple().getObjectFormat()) { + case llvm::Triple::MachO: +return true; + case llvm::Triple::COFF: +return DataSections; + case llvm::Triple::ELF: +return DataSections && IntegratedAs; + default: +return false; + } +} + void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const { @@ -745,6 +768,11 @@ Sanitizers.Mask & CFIClasses) << "-fvisibility="; } + + if (Sanitizers.has(Address) && !useAsanGlobalsGC(TC, Args)) { +CmdArgs.push_back("-mllvm"); +CmdArgs.push_back("-asan-globals-live-support=0"); + } } SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, Index: test/Driver/asan-gc.c === --- /dev/null +++ test/Driver/asan-gc.c @@ -0,0 +1,14 @@ +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-data-sections -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-integrated-as -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC + +// RUN: %clang -target x86_64-apple-macosx10.11.0 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC +// RUN: %clang -target x86_64-apple-macosx10.11.0 -fsanitize=address -fno-integrated-as %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC + +// RUN: %clang -target x86_64-pc-windows-msvc19.0.24215 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang -target x86_64-pc-windows-msvc19.0.24215 -fsanitize=address -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC + + +// WITHOUT-GC: "-mllvm" "-asan-globals-live-support=0" +// WITH-GC-NOT: -asan-globals-live-support=0 Index: lib/Driver/SanitizerArgs.cpp === --- lib/Driver/SanitizerArgs.cpp +++ lib/Driver/SanitizerArgs.cpp @@ -618,6 +618,29 @@ CmdArgs.push_back(Args.MakeArgString(LinkerOptionFlag)); } +// Check
[PATCH] D32043: [Driver] Load all necessary default sanitizer blacklists
eugenis added a comment. Looks fine. https://reviews.llvm.org/D32043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis added inline comments. Comment at: lib/Driver/SanitizerArgs.cpp:636 + case llvm::Triple::COFF: +return DataSections; + case llvm::Triple::ELF: rnk wrote: > We can return true for COFF here. By adding a comdat during asan > instrumentation, we effectively implement -fdata-sections ourselves. If the > user really wanted -fno-data-sections for some reason, they're out of luck > right now. What do you mean by "out of luck", will it break compilation? Because the point of this change is not to enable data-sections unless asked by the user. Data sections greatly inflate ELF object file size (not sure how big is the effect on COFF) and we should not do that by default. Repository: rL LLVM https://reviews.llvm.org/D32064 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis added a comment. Ping. I don't really have a preference. Repository: rL LLVM https://reviews.llvm.org/D32064 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29077: [lsan] Enable LSan for x86 Linux.
eugenis added a comment. A test would be nice. Repository: rL LLVM https://reviews.llvm.org/D29077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29077: [lsan] Enable LSan for x86 Linux.
eugenis accepted this revision. eugenis added a comment. This revision is now accepted and ready to land. LGTM Repository: rL LLVM https://reviews.llvm.org/D29077 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26764: [compiler-rt] [cmake] Remove i686 target that is duplicate to i386
eugenis added a comment. I think this is the right move together with https://reviews.llvm.org/D26796. Android build system will need to support both names for some time, depending on the toolchain version - looks doable. Technically, it can stick with the old name forever. https://reviews.llvm.org/D26764 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25928: [cfi] Enable cfi-icall on ARM and AArch64.
eugenis closed this revision. eugenis added a comment. Committed in r286613 Repository: rL LLVM https://reviews.llvm.org/D25928 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis added a comment. The ultimate solution would be a function attribute - if we want this thing to work correctly with LTO. But it sounds a bit like overkill, plus none of the settings it depends on (integrated-as, data-sections) work with LTO anway: the former is ignored and the second does not make sense. Repository: rL LLVM https://reviews.llvm.org/D32064 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis updated this revision to Diff 96227. eugenis added a comment. Reverted back to using pass constructor argument. 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 @@ -129,16 +129,20 @@ // that we add to the PassManagerBuilder. class PassManagerBuilderWrapper : public PassManagerBuilder { public: - PassManagerBuilderWrapper(const CodeGenOptions &CGOpts, + PassManagerBuilderWrapper(const Triple &TargetTriple, +const CodeGenOptions &CGOpts, const LangOptions &LangOpts) - : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {} + : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts), +LangOpts(LangOpts) {} + const Triple &getTargetTriple() const { return TargetTriple; } const CodeGenOptions &getCGOpts() const { return CGOpts; } const LangOptions &getLangOpts() const { return LangOpts; } + private: + const Triple &TargetTriple; const CodeGenOptions &CGOpts; const LangOptions &LangOpts; }; - } static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { @@ -185,16 +189,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 &T, const CodeGenOptions &CGOpts) { + 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 &Builder, legacy::PassManagerBase &PM) { const PassManagerBuilderWrapper &BuilderWrapper = static_cast(Builder); + const Triple &T = BuilderWrapper.getTargetTriple(); const CodeGenOptions &CGOpts = 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 &Builder, @@ -434,16 +458,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 @@ -129,16 +129,20 @@ // that we add to the PassManagerBuilder. class PassManagerBuilderWrapper : public PassManagerBuilder { public: - PassManagerBuilderWrapper(const CodeGenOptions &CGOpts, + PassManagerBuilderWrapper(const Triple &TargetTriple, +const CodeGenOptions &CGOpts, const LangOptions &LangOpts) - : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {} + : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts), +LangOpts(LangOpts) {} + const Triple &getTargetTriple() const { return TargetTriple; } const CodeGenOptions &getCGOpts() const { return CGOpts; } const LangOptions &getLangOpts() const { return LangOpts; } + private: + const Triple &TargetTriple; const CodeGenOptions &CGOpts; const LangOptions &LangOpts; }; - } static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { @@ -185,16 +189,36 @@ PM.add(createSanitizerCoverageModulePass(O
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis added a comment. what kind of test? Repository: rL LLVM https://reviews.llvm.org/D32064 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis updated this revision to Diff 96263. Repository: rL LLVM https://reviews.llvm.org/D32064 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/asan-globals-gc.cpp Index: test/CodeGen/asan-globals-gc.cpp === --- /dev/null +++ test/CodeGen/asan-globals-gc.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC + +int global; + +// WITH-GC-NOT: call void @__asan_register_globals +// WITHOUT-GC: call void @__asan_register_globals Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -129,16 +129,20 @@ // that we add to the PassManagerBuilder. class PassManagerBuilderWrapper : public PassManagerBuilder { public: - PassManagerBuilderWrapper(const CodeGenOptions &CGOpts, + PassManagerBuilderWrapper(const Triple &TargetTriple, +const CodeGenOptions &CGOpts, const LangOptions &LangOpts) - : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {} + : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts), +LangOpts(LangOpts) {} + const Triple &getTargetTriple() const { return TargetTriple; } const CodeGenOptions &getCGOpts() const { return CGOpts; } const LangOptions &getLangOpts() const { return LangOpts; } + private: + const Triple &TargetTriple; const CodeGenOptions &CGOpts; const LangOptions &LangOpts; }; - } static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { @@ -185,16 +189,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 &T, const CodeGenOptions &CGOpts) { + 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 &Builder, legacy::PassManagerBase &PM) { const PassManagerBuilderWrapper &BuilderWrapper = static_cast(Builder); + const Triple &T = BuilderWrapper.getTargetTriple(); const CodeGenOptions &CGOpts = 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 &Builder, @@ -434,16 +458,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: test/CodeGen/asan-globals-gc.cpp === --- /dev/null +++ test/CodeGen/asan-globals-gc.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC + +int global; + +// WITH-GC-NOT: call void @__asan_register_globals +// WITHOUT-GC: call void @__asan_register_globals Index: lib/CodeGen/BackendUtil.cpp ==
[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
eugenis added a comment. PTAL Repository: rL LLVM https://reviews.llvm.org/D32064 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32043: [Driver] Load all necessary default sanitizer blacklists
eugenis added a comment. We definitely want different blacklists for ASan and MSan. https://reviews.llvm.org/D32043 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32514: [asan] Unconditionally enable GC of globals on COFF
eugenis created this revision. This change restores pre-r301225 behavior, where linker GC compatible global instrumentation was used on COFF targets disregarding -f(no-)data-sections and/or /Gw flags. Repository: rL LLVM https://reviews.llvm.org/D32514 Files: lib/CodeGen/BackendUtil.cpp test/CodeGen/asan-globals-gc.cpp Index: test/CodeGen/asan-globals-gc.cpp === --- test/CodeGen/asan-globals-gc.cpp +++ test/CodeGen/asan-globals-gc.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITH-GC // RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC int global; Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -196,9 +196,8 @@ static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) { switch (T.getObjectFormat()) { case Triple::MachO: -return true; case Triple::COFF: -return CGOpts.DataSections; +return true; case Triple::ELF: return CGOpts.DataSections && !CGOpts.DisableIntegratedAS; default: Index: test/CodeGen/asan-globals-gc.cpp === --- test/CodeGen/asan-globals-gc.cpp +++ test/CodeGen/asan-globals-gc.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITHOUT-GC +// RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc %s | FileCheck %s --check-prefix=WITH-GC // RUN: %clang_cc1 -fsanitize=address -emit-llvm -o - -triple x86_64-windows-msvc -fdata-sections %s | FileCheck %s --check-prefix=WITH-GC int global; Index: lib/CodeGen/BackendUtil.cpp === --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -196,9 +196,8 @@ static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts) { switch (T.getObjectFormat()) { case Triple::MachO: -return true; case Triple::COFF: -return CGOpts.DataSections; +return true; case Triple::ELF: return CGOpts.DataSections && !CGOpts.DisableIntegratedAS; default: ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32514: [asan] Unconditionally enable GC of globals on COFF
eugenis added a comment. Apparently the ODR detector in Asan on Windows has issues with full data-sections. This way we can have limited GC for user globals. Repository: rL LLVM https://reviews.llvm.org/D32514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32514: [asan] Unconditionally enable GC of globals on COFF
eugenis added a comment. r301374 Repository: rL LLVM https://reviews.llvm.org/D32514 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits