[sancov] Refactor getPreviousInstructionPc

Note: on some architectures lik AArch64, the PC does not match
compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp:`__sanitizer_cov_trace_pc_guard`
This commit is contained in:
Fangrui Song 2022-02-22 16:30:02 -08:00
parent 939d62c185
commit 1ec9dd3aae
1 changed files with 9 additions and 6 deletions

View File

@ -687,17 +687,20 @@ findSanitizerCovFunctions(const object::ObjectFile &O) {
return Result;
}
// Ported from
// compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h:GetPreviousInstructionPc
// GetPreviousInstructionPc.
static uint64_t getPreviousInstructionPc(uint64_t PC,
Triple TheTriple) {
if (TheTriple.isARM()) {
if (TheTriple.isARM())
return (PC - 3) & (~1);
} else if (TheTriple.isAArch64()) {
return PC - 4;
} else if (TheTriple.isMIPS()) {
if (TheTriple.isMIPS())
return PC - 8;
} else {
if (TheTriple.isRISCV())
return PC - 2;
if (TheTriple.isX86())
return PC - 1;
}
return PC - 4;
}
// Locate addresses of all coverage points in a file. Coverage point