Author: kcc Date: Tue Sep 13 20:39:49 2016 New Revision: 281432 URL: http://llvm.org/viewvc/llvm-project?rev=281432&view=rev Log: [sanitizer-coverage] add yet another flavour of coverage instrumentation: trace-pc-guard. The intent is to eventually replace all of {bool coverage, 8bit-counters, trace-pc} with just this one. Clang part
Modified: cfe/trunk/docs/SanitizerCoverage.rst cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/include/clang/Frontend/CodeGenOptions.def cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/Driver/SanitizerArgs.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/Driver/fsanitize-coverage.c Modified: cfe/trunk/docs/SanitizerCoverage.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SanitizerCoverage.rst?rev=281432&r1=281431&r2=281432&view=diff ============================================================================== --- cfe/trunk/docs/SanitizerCoverage.rst (original) +++ cfe/trunk/docs/SanitizerCoverage.rst Tue Sep 13 20:39:49 2016 @@ -321,6 +321,32 @@ by the user. So, these flags do not requ This mechanism is used for fuzzing the Linux kernel (https://github.com/google/syzkaller) and can be used with `AFL <http://lcamtuf.coredump.cx/afl>`__. +Tracing PCs with guards +======================= +Another *experimental* feature that tries to combine `trace-pc`, +`8bit-counters` and boolean coverage + +With ``-fsanitize-coverage=trace-pc-guard`` the compiler will insert the following code +on every edge: + +.. code-block:: none + + if (guard_variable != 0xff) + __sanitizer_cov_trace_pc_guard(&guard_variable) + +Every edge will have its own 1-byte `guard_variable`. +All such guard variables will reside in a dedicated section +(i.e. they essentially form an array). + +The compler will also insert a module constructor that will call + +.. code-block:: c++ + + // The guard section is the address range [start, stop). + __sanitizer_cov_trace_pc_guard_init(void *start, void *stop); + +The functions `__sanitizer_cov_trace_pc_guard[_init]` should be defined by the user. + Tracing data flow ================= Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=281432&r1=281431&r2=281432&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Sep 13 20:39:49 2016 @@ -289,6 +289,9 @@ def fsanitize_coverage_8bit_counters def fsanitize_coverage_trace_pc : Flag<["-"], "fsanitize-coverage-trace-pc">, HelpText<"Enable PC tracing in sanitizer coverage">; +def fsanitize_coverage_trace_pc_guard + : Flag<["-"], "fsanitize-coverage-trace-pc-guard">, + HelpText<"Enable PC tracing with guard in sanitizer coverage">; def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">, HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, " "or none">; Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=281432&r1=281431&r2=281432&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original) +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Sep 13 20:39:49 2016 @@ -160,6 +160,8 @@ CODEGENOPT(SanitizeCoverage8bitCounters, ///< in sanitizer coverage. CODEGENOPT(SanitizeCoverageTracePC, 1, 0) ///< Enable PC tracing ///< in sanitizer coverage. +CODEGENOPT(SanitizeCoverageTracePCGuard, 1, 0) ///< Enable PC tracing with guard + ///< in sanitizer coverage. CODEGENOPT(SanitizeStats , 1, 0) ///< Collect statistics for sanitizers. CODEGENOPT(SimplifyLibCalls , 1, 1) ///< Set when -fbuiltin is enabled. CODEGENOPT(SoftFloat , 1, 0) ///< -soft-float. Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=281432&r1=281431&r2=281432&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Sep 13 20:39:49 2016 @@ -180,6 +180,7 @@ static void addSanitizerCoveragePass(con Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep; Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters; Opts.TracePC = CGOpts.SanitizeCoverageTracePC; + Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard; PM.add(createSanitizerCoverageModulePass(Opts)); } Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=281432&r1=281431&r2=281432&view=diff ============================================================================== --- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original) +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Sep 13 20:39:49 2016 @@ -53,6 +53,7 @@ enum CoverageFeature { CoverageTraceGep = 1 << 7, Coverage8bitCounters = 1 << 8, CoverageTracePC = 1 << 9, + CoverageTracePCGuard = 1 << 10, }; /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any @@ -526,7 +527,7 @@ SanitizerArgs::SanitizerArgs(const ToolC << "-fsanitize-coverage=8bit-counters" << "-fsanitize-coverage=(func|bb|edge)"; // trace-pc w/o func/bb/edge implies edge. - if ((CoverageFeatures & CoverageTracePC) && + if ((CoverageFeatures & (CoverageTracePC | CoverageTracePCGuard)) && !(CoverageFeatures & CoverageTypes)) CoverageFeatures |= CoverageEdge; @@ -620,7 +621,8 @@ void SanitizerArgs::addArgs(const ToolCh std::make_pair(CoverageTraceDiv, "-fsanitize-coverage-trace-div"), std::make_pair(CoverageTraceGep, "-fsanitize-coverage-trace-gep"), std::make_pair(Coverage8bitCounters, "-fsanitize-coverage-8bit-counters"), - std::make_pair(CoverageTracePC, "-fsanitize-coverage-trace-pc")}; + std::make_pair(CoverageTracePC, "-fsanitize-coverage-trace-pc"), + std::make_pair(CoverageTracePCGuard, "-fsanitize-coverage-trace-pc-guard")}; for (auto F : CoverageFlags) { if (CoverageFeatures & F.first) CmdArgs.push_back(Args.MakeArgString(F.second)); @@ -760,6 +762,7 @@ int parseCoverageFeatures(const Driver & .Case("trace-gep", CoverageTraceGep) .Case("8bit-counters", Coverage8bitCounters) .Case("trace-pc", CoverageTracePC) + .Case("trace-pc-guard", CoverageTracePCGuard) .Default(0); if (F == 0) D.Diag(clang::diag::err_drv_unsupported_option_argument) Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=281432&r1=281431&r2=281432&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Sep 13 20:39:49 2016 @@ -724,6 +724,8 @@ static bool ParseCodeGenArgs(CodeGenOpti Opts.SanitizeCoverage8bitCounters = Args.hasArg(OPT_fsanitize_coverage_8bit_counters); Opts.SanitizeCoverageTracePC = Args.hasArg(OPT_fsanitize_coverage_trace_pc); + Opts.SanitizeCoverageTracePCGuard = + Args.hasArg(OPT_fsanitize_coverage_trace_pc_guard); Opts.SanitizeMemoryTrackOrigins = getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, Diags); Opts.SanitizeMemoryUseAfterDtor = Modified: cfe/trunk/test/Driver/fsanitize-coverage.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-coverage.c?rev=281432&r1=281431&r2=281432&view=diff ============================================================================== --- cfe/trunk/test/Driver/fsanitize-coverage.c (original) +++ cfe/trunk/test/Driver/fsanitize-coverage.c Tue Sep 13 20:39:49 2016 @@ -72,6 +72,14 @@ // CHECK-TRACE_PC_FUNC: -fsanitize-coverage-type=1 // CHECK-TRACE_PC_FUNC: -fsanitize-coverage-trace-pc +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACE_PC_GUARD_EDGE +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=edge,trace-pc-guard %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACE_PC_GUARD_EDGE +// CHECK-TRACE_PC_GUARD_EDGE: -fsanitize-coverage-type=3 +// CHECK-TRACE_PC_GUARD_EDGE: -fsanitize-coverage-trace-pc-guard +// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=func,trace-pc-guard %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACE_PC_GUARD_FUNC +// CHECK-TRACE_PC_GUARD_FUNC: -fsanitize-coverage-type=1 +// CHECK-TRACE_PC_GUARD_FUNC: -fsanitize-coverage-trace-pc-guard + // RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-coverage=trace-cmp,indirect-calls %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-TYPE-NECESSARY // CHECK-NO-TYPE-NECESSARY-NOT: error: // CHECK-NO-TYPE-NECESSARY: -fsanitize-coverage-indirect-calls _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits