[llvm] r344103 - [sancov] Generalize the code to get the previous instruction to multiple architectures

George Karpenkov via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 9 17:57:25 PDT 2018


Author: george.karpenkov
Date: Tue Oct  9 17:57:24 2018
New Revision: 344103

URL: http://llvm.org/viewvc/llvm-project?rev=344103&view=rev
Log:
[sancov] Generalize the code to get the previous instruction to multiple architectures

sancov subtracts one from the address to get the previous instruction,
which makes sense on x86_64, but not on other platforms.
This change ensures that the offset is correct for different platforms.
The logic for computing the offset is copied from sanitizer_common.

Differential Revision: https://reviews.llvm.org/D53039

Modified:
    llvm/trunk/tools/sancov/sancov.cpp

Modified: llvm/trunk/tools/sancov/sancov.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cpp?rev=344103&r1=344102&r2=344103&view=diff
==============================================================================
--- llvm/trunk/tools/sancov/sancov.cpp (original)
+++ llvm/trunk/tools/sancov/sancov.cpp Tue Oct  9 17:57:24 2018
@@ -766,6 +766,19 @@ findSanitizerCovFunctions(const object::
   return Result;
 }
 
+static uint64_t getPreviousInstructionPc(uint64_t PC,
+                                         Triple TheTriple) {
+  if (TheTriple.isARM()) {
+    return (PC - 3) & (~1);
+  } else if (TheTriple.isAArch64()) {
+    return PC - 4;
+  } else if (TheTriple.isMIPS()) {
+    return PC - 8;
+  } else {
+    return PC - 1;
+  }
+}
+
 // Locate addresses of all coverage points in a file. Coverage point
 // is defined as the 'address of instruction following __sanitizer_cov
 // call - 1'.
@@ -832,7 +845,7 @@ static void getObjectCoveragePoints(cons
       }
       uint64_t Addr = Index + SectionAddr;
       // Sanitizer coverage uses the address of the next instruction - 1.
-      uint64_t CovPoint = Addr + Size - 1;
+      uint64_t CovPoint = getPreviousInstructionPc(Addr + Size, TheTriple);
       uint64_t Target;
       if (MIA->isCall(Inst) &&
           MIA->evaluateBranch(Inst, SectionAddr + Index, Size, Target) &&




More information about the llvm-commits mailing list