From efbe9367db777cb93b17de2e64b4c3df6d607fd4 Mon Sep 17 00:00:00 2001 From: Mike Aizatsky Date: Mon, 14 Dec 2015 23:55:04 +0000 Subject: sancov: coverage can be reported by multiple functions. Differential Revision: http://reviews.llvm.org/D15430 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255582 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/sancov/sancov.cc | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/sancov/sancov.cc b/tools/sancov/sancov.cc index 450c21bd169..94d8c4c7aab 100644 --- a/tools/sancov/sancov.cc +++ b/tools/sancov/sancov.cc @@ -207,21 +207,30 @@ std::set computeFunctionLocs(const std::set &Addrs) { return result; } -// Locate __sanitizer_cov function address. -static uint64_t findSanitizerCovFunction(const object::ObjectFile &O) { +// Locate __sanitizer_cov* function addresses that are used for coverage +// reporting. +static std::set +findSanitizerCovFunctions(const object::ObjectFile &O) { + std::set Result; + for (const object::SymbolRef &Symbol : O.symbols()) { ErrorOr AddressOrErr = Symbol.getAddress(); FailIfError(AddressOrErr); - ErrorOr Name = Symbol.getName(); - FailIfError(Name); + ErrorOr NameOrErr = Symbol.getName(); + FailIfError(NameOrErr); + StringRef Name = NameOrErr.get(); - if (Name.get() == "__sanitizer_cov") { - return AddressOrErr.get(); + if (Name == "__sanitizer_cov" || Name == "__sanitizer_cov_with_check" || + Name == "__sanitizer_cov_trace_func_enter") { + Result.insert(AddressOrErr.get()); } } - FailIfNotEmpty("__sanitizer_cov not found"); - return 0; // not reachable. + + if (Result.empty()) + FailIfNotEmpty("__sanitizer_cov* functions not found"); + + return Result; } // Locate addresses of all coverage points in a file. Coverage point @@ -262,7 +271,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O, TheTarget->createMCInstrAnalysis(MII.get())); FailIfEmpty(MIA, "no instruction analysis info for target " + TripleName); - uint64_t SanCovAddr = findSanitizerCovFunction(O); + auto SanCovAddrs = findSanitizerCovFunctions(O); for (const auto Section : O.sections()) { if (Section.isVirtual() || !Section.isText()) // llvm-objdump does the same. @@ -292,7 +301,7 @@ static void getObjectCoveragePoints(const object::ObjectFile &O, uint64_t Target; if (MIA->isCall(Inst) && MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target)) { - if (Target == SanCovAddr) { + if (SanCovAddrs.find(Target) != SanCovAddrs.end()) { // Sanitizer coverage uses the address of the next instruction - 1. Addrs->insert(Index + SectionAddr + Size - 1); } -- cgit v1.2.3