[PATCH] D53040: [libFuzzer] Generalize the code for getting the previous offset for different architectures
George Karpenkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 9 13:55:48 PDT 2018
george.karpenkov created this revision.
george.karpenkov added reviewers: kubamracek, kcc, morehouse.
george.karpenkov added a project: Sanitizers.
Herald added subscribers: Sanitizers, fedor.sergeev.
Without this change, tests in coverage.test and dump_coverage.test are failing on non-x86_64 platforms.
The diff is copied from sanitizer_common library, an alternative would be to link it together with libFuzzer.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D53040
Files:
compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
Index: compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
===================================================================
--- compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
+++ compiler-rt/lib/fuzzer/FuzzerTracePC.cpp
@@ -239,15 +239,30 @@
}
inline ALWAYS_INLINE uintptr_t GetPreviousInstructionPc(uintptr_t PC) {
- // TODO: this implementation is x86 only.
- // see sanitizer_common GetPreviousInstructionPc for full implementation.
+#if defined(__arm__)
+ // T32 (Thumb) branch instructions might be 16 or 32 bit long,
+ // so we return (pc-2) in that case in order to be safe.
+ // For A32 mode we return (pc-4) because all instructions are 32 bit long.
+ return (PC - 3) & (~1);
+#elif defined(__powerpc__) || defined(__powerpc64__) || defined(__aarch64__)
+ // PCs are always 4 byte aligned.
+ return PC - 4;
+#elif defined(__sparc__) || defined(__mips__)
+ return PC - 8;
+#else
return PC - 1;
+#endif
}
inline ALWAYS_INLINE uintptr_t GetNextInstructionPc(uintptr_t PC) {
- // TODO: this implementation is x86 only.
- // see sanitizer_common GetPreviousInstructionPc for full implementation.
+#if defined(__mips__)
+ return PC + 8;
+#elif defined(__powerpc__) || defined(__sparc__) || defined(__arm__) || \
+ defined(__aarch64__)
+ return PC + 4;
+#else
return PC + 1;
+#endif
}
static std::string GetModuleName(uintptr_t PC) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53040.168866.patch
Type: text/x-patch
Size: 1356 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181009/31d70bb3/attachment.bin>
More information about the llvm-commits
mailing list