Skip to content

Commit 76c6653

Browse files
authored
[DeviceSanitizers] Adjust backtrace addresses to call instruction (#17404)
`backtrace()` would return buffers with return addresses, which is one instruction past the call. If that instruction belongs to other source lines, then the llvm-symbolizer would give out wrong result. Test will be added internally. It is hard to write test for this using SYCL as SYCL does not generate code with that pattern.
1 parent 1627f30 commit 76c6653

File tree

1 file changed

+9
-2
lines changed
  • unified-runtime/source/loader/layers/sanitizer/sanitizer_common/linux

1 file changed

+9
-2
lines changed

unified-runtime/source/loader/layers/sanitizer/sanitizer_common/linux/backtrace.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "sanitizer_common/sanitizer_stacktrace.hpp"
1414

1515
#include <execinfo.h>
16+
#include <stdint.h>
1617
#include <string>
1718

1819
namespace ur_sanitizer_layer {
@@ -21,9 +22,15 @@ StackTrace GetCurrentBacktrace() {
2122
BacktraceFrame Frames[MAX_BACKTRACE_FRAMES];
2223
int FrameCount = backtrace(Frames, MAX_BACKTRACE_FRAMES);
2324

25+
// The Frames contain the return addresses, which is one instruction after the
26+
// call instruction. Adjust the addresses so that symbolizer would give more
27+
// precise result.
28+
for (int I = 0; I < FrameCount; I++) {
29+
Frames[I] = (void *)((uintptr_t)Frames[I] - 1);
30+
}
31+
2432
StackTrace Stack;
25-
Stack.stack =
26-
std::vector<BacktraceFrame>(&Frames[0], &Frames[FrameCount - 1]);
33+
Stack.stack = std::vector<BacktraceFrame>(&Frames[0], &Frames[FrameCount]);
2734

2835
return Stack;
2936
}

0 commit comments

Comments
 (0)