[compiler-rt] [tsan] Calibrate jmp_buf pointer mangling (PR #216558)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 16 03:49:39 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index e4299020c..2cb34792e 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -78,27 +78,27 @@ extern "C" void *__libc_stack_end;
void *__libc_stack_end = 0;
#endif
-#if SANITIZER_LINUX && !SANITIZER_GO
-# define CALIBRATE_LONGJMP_SP 1
-#else
-# define CALIBRATE_LONGJMP_SP 0
-#endif
+# if SANITIZER_LINUX && !SANITIZER_GO
+# define CALIBRATE_LONGJMP_SP 1
+# else
+# define CALIBRATE_LONGJMP_SP 0
+# endif
-#if CALIBRATE_LONGJMP_SP
-#include "interception/interception.h"
+# if CALIBRATE_LONGJMP_SP
+# include "interception/interception.h"
// Must be declared outside of other namespaces.
DECLARE_REAL(int, _setjmp, void *env)
#endif
namespace __tsan {
-#if CALIBRATE_LONGJMP_SP
+# if CALIBRATE_LONGJMP_SP
static void InitializeLongjmpSpMangling();
// libc stores rotl(sp ^ longjmp_xor_key, longjmp_rot) in jmp_buf.
// Both values are zero when the stack pointer is stored unchanged.
static uptr longjmp_xor_key;
static uptr longjmp_rot;
-#endif
+# endif
// Runtime detected VMA size.
uptr vmaSize;
@@ -566,36 +566,36 @@ uptr ExtractLongJmpSp(uptr *env) {
return UnmangleLongJmpSp(mangled_sp);
}
-#if CALIBRATE_LONGJMP_SP
+# if CALIBRATE_LONGJMP_SP
// Read the SP immediately after _setjmp returns. This is the value libc saves.
-NOINLINE static void ProbeLongJmpSp(uptr *sp, uptr *mangled_sp) {
+NOINLINE static void ProbeLongJmpSp(uptr* sp, uptr* mangled_sp) {
jmp_buf env;
REAL(_setjmp)(env);
uptr v;
-#if defined(__x86_64__)
- asm volatile("mov %%rsp, %0" : "=r" (v));
-#elif defined(__aarch64__)
- asm volatile("mov %0, sp" : "=r" (v));
-#elif defined(__loongarch__)
- asm volatile("move %0, $sp" : "=r" (v));
-#elif defined(__powerpc64__)
- asm volatile("mr %0, 1" : "=r" (v));
-#elif defined(__s390x__)
- asm volatile("lgr %0, %%r15" : "=r" (v));
-#elif defined(__mips__)
- asm volatile("move %0, $sp" : "=r" (v));
-#elif SANITIZER_RISCV64
- asm volatile("mv %0, sp" : "=r" (v));
-#else
-#error "Unknown platform"
-#endif
+# if defined(__x86_64__)
+ asm volatile("mov %%rsp, %0" : "=r"(v));
+# elif defined(__aarch64__)
+ asm volatile("mov %0, sp" : "=r"(v));
+# elif defined(__loongarch__)
+ asm volatile("move %0, $sp" : "=r"(v));
+# elif defined(__powerpc64__)
+ asm volatile("mr %0, 1" : "=r"(v));
+# elif defined(__s390x__)
+ asm volatile("lgr %0, %%r15" : "=r"(v));
+# elif defined(__mips__)
+ asm volatile("move %0, $sp" : "=r"(v));
+# elif SANITIZER_RISCV64
+ asm volatile("mv %0, sp" : "=r"(v));
+# else
+# error "Unknown platform"
+# endif
*sp = v;
- *mangled_sp = ((uptr *)&env)[LONG_JMP_SP_ENV_SLOT];
+ *mangled_sp = ((uptr*)&env)[LONG_JMP_SP_ENV_SLOT];
}
// Run the probe in another frame. Consuming its result after the call prevents
// tail-call elimination.
-NOINLINE static void ProbeLongJmpSpDeep(uptr *sp, uptr *mangled_sp) {
+NOINLINE static void ProbeLongJmpSpDeep(uptr* sp, uptr* mangled_sp) {
ProbeLongJmpSp(sp, mangled_sp);
asm volatile("" : : "r"(*sp));
}
@@ -629,7 +629,7 @@ static void InitializeLongjmpSpMangling() {
CHECK(0);
}
}
-#endif
+# endif
extern "C" void __tsan_tls_initialization() {}
``````````
</details>
https://github.com/llvm/llvm-project/pull/216558
More information about the llvm-commits
mailing list