[llvm] r293733 - SanitizerCoverage: Support sanitizer guard section on darwin
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 17 11:52:01 PDT 2017
Hi,
I think it should have been cherry-picked in 4.0. I’d like to nominate this for 4.0.1.
—
Mehdi
> On Jan 31, 2017, at 6:38 PM, Justin Bogner via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> Author: bogner
> Date: Tue Jan 31 20:38:39 2017
> New Revision: 293733
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293733&view=rev
> Log:
> SanitizerCoverage: Support sanitizer guard section on darwin
>
> MachO's sections need a segment as well as a section name, and the
> section start and end symbols are spelled differently than on ELF.
>
> Modified:
> llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
> llvm/trunk/test/Instrumentation/SanitizerCoverage/tracing.ll
>
> Modified: llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp?rev=293733&r1=293732&r2=293733&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (original)
> +++ llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp Tue Jan 31 20:38:39 2017
> @@ -78,7 +78,6 @@ static const char *const SanCovTraceSwit
> static const char *const SanCovModuleCtorName = "sancov.module_ctor";
> static const uint64_t SanCtorAndDtorPriority = 2;
>
> -static const char *const SanCovTracePCGuardSection = "__sancov_guards";
> static const char *const SanCovTracePCGuardName =
> "__sanitizer_cov_trace_pc_guard";
> static const char *const SanCovTracePCGuardInitName =
> @@ -139,6 +138,24 @@ static cl::opt<bool> ClUse8bitCounters("
> cl::desc("Experimental 8-bit counters"),
> cl::Hidden, cl::init(false));
>
> +static StringRef getSanCovTracePCGuardSection(const Module &M) {
> + return Triple(M.getTargetTriple()).isOSBinFormatMachO()
> + ? "__DATA,__sancov_guards"
> + : "__sancov_guards";
> +}
> +
> +static StringRef getSanCovTracePCGuardSectionStart(const Module &M) {
> + return Triple(M.getTargetTriple()).isOSBinFormatMachO()
> + ? "\1section$start$__DATA$__sancov_guards"
> + : "__start___sancov_guards";
> +}
> +
> +static StringRef getSanCovTracePCGuardSectionEnd(const Module &M) {
> + return Triple(M.getTargetTriple()).isOSBinFormatMachO()
> + ? "\1section$end$__DATA$__sancov_guards"
> + : "__stop___sancov_guards";
> +}
> +
> namespace {
>
> SanitizerCoverageOptions getOptions(int LegacyCoverageLevel) {
> @@ -363,20 +380,20 @@ bool SanitizerCoverageModule::runOnModul
> if (Options.TracePCGuard) {
> if (HasSancovGuardsSection) {
> Function *CtorFunc;
> - std::string SectionName(SanCovTracePCGuardSection);
> - GlobalVariable *Bounds[2];
> - const char *Prefix[2] = {"__start_", "__stop_"};
> - for (int i = 0; i < 2; i++) {
> - Bounds[i] = new GlobalVariable(M, Int32PtrTy, false,
> - GlobalVariable::ExternalLinkage, nullptr,
> - Prefix[i] + SectionName);
> - Bounds[i]->setVisibility(GlobalValue::HiddenVisibility);
> - }
> + GlobalVariable *SecStart = new GlobalVariable(
> + M, Int32PtrTy, false, GlobalVariable::ExternalLinkage, nullptr,
> + getSanCovTracePCGuardSectionStart(*CurModule));
> + SecStart->setVisibility(GlobalValue::HiddenVisibility);
> + GlobalVariable *SecEnd = new GlobalVariable(
> + M, Int32PtrTy, false, GlobalVariable::ExternalLinkage, nullptr,
> + getSanCovTracePCGuardSectionEnd(*CurModule));
> + SecEnd->setVisibility(GlobalValue::HiddenVisibility);
> +
> std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions(
> M, SanCovModuleCtorName, SanCovTracePCGuardInitName,
> {Int32PtrTy, Int32PtrTy},
> - {IRB.CreatePointerCast(Bounds[0], Int32PtrTy),
> - IRB.CreatePointerCast(Bounds[1], Int32PtrTy)});
> + {IRB.CreatePointerCast(SecStart, Int32PtrTy),
> + IRB.CreatePointerCast(SecEnd, Int32PtrTy)});
>
> appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority);
> }
> @@ -517,7 +534,7 @@ void SanitizerCoverageModule::CreateFunc
> Constant::getNullValue(ArrayOfInt32Ty), "__sancov_gen_");
> if (auto Comdat = F.getComdat())
> FunctionGuardArray->setComdat(Comdat);
> - FunctionGuardArray->setSection(SanCovTracePCGuardSection);
> + FunctionGuardArray->setSection(getSanCovTracePCGuardSection(*CurModule));
> }
>
> bool SanitizerCoverageModule::InjectCoverage(Function &F,
>
> Modified: llvm/trunk/test/Instrumentation/SanitizerCoverage/tracing.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/SanitizerCoverage/tracing.ll?rev=293733&r1=293732&r2=293733&view=diff
> ==============================================================================
> --- llvm/trunk/test/Instrumentation/SanitizerCoverage/tracing.ll (original)
> +++ llvm/trunk/test/Instrumentation/SanitizerCoverage/tracing.ll Tue Jan 31 20:38:39 2017
> @@ -3,6 +3,7 @@
> ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-experimental-tracing -S | FileCheck %s --check-prefix=CHECK3
> ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK_PC
> ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s --check-prefix=CHECK_PC_GUARD
> +; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S -mtriple=x86_64-apple-macosx | FileCheck %s --check-prefix=CHECK_PC_GUARD_DARWIN
>
> target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
> target triple = "x86_64-unknown-linux-gnu"
> @@ -47,3 +48,11 @@ entry:
> ; CHECK_PC_GUARD-NOT: call void @__sanitizer_cov_trace_pc
> ; CHECK_PC_GUARD: ret void
> ; CHECK_PC_GUARD: call void @__sanitizer_cov_trace_pc_guard_init(i32* bitcast (i32** @__start___sancov_guards to i32*), i32* bitcast (i32** @__stop___sancov_guards to i32*))
> +
> +; CHECK_PC_GUARD_DARWIN-LABEL: define void @foo
> +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard
> +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard
> +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard
> +; CHECK_PC_GUARD_DARWIN-NOT: call void @__sanitizer_cov_trace_pc
> +; CHECK_PC_GUARD_DARWIN: ret void
> +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard_init(i32* bitcast (i32** @"\01section$start$__DATA$__sancov_guards" to i32*), i32* bitcast (i32** @"\01section$end$__DATA$__sancov_guards" to i32*))
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list