aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2018-10-10 00:57:24 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2018-10-10 00:57:24 +0000
commitea13613572db918380b21c34a755abc3531a39a4 (patch)
treed156e2ef3d7b830c52968ba8eb2e7e840ea0a51d
parent285ae0c07b20b25725963e11f65fbb53b5110edc (diff)
downloadllvm-ea13613572db918380b21c34a755abc3531a39a4.zip
llvm-ea13613572db918380b21c34a755abc3531a39a4.tar.gz
llvm-ea13613572db918380b21c34a755abc3531a39a4.tar.bz2
[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 llvm-svn: 344103
-rw-r--r--llvm/tools/sancov/sancov.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/tools/sancov/sancov.cpp b/llvm/tools/sancov/sancov.cpp
index 0bddd35..e8935d1 100644
--- a/llvm/tools/sancov/sancov.cpp
+++ b/llvm/tools/sancov/sancov.cpp
@@ -766,6 +766,19 @@ findSanitizerCovFunctions(const object::ObjectFile &O) {
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(const object::ObjectFile &O,
}
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) &&