[compiler-rt] [tsan] Change personality CHECK to Printf() + Die() (PR #142821)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 4 10:42:09 PDT 2025
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/142821
>From 388b83e745815fe839cd329c2c7a6ea7ddd2248d Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Wed, 4 Jun 2025 17:37:09 +0000
Subject: [PATCH 1/3] [tsan] Change personality CHECK to Printf() + Die()
Currently, if TSan needs to disable ASLR but is unable to do so, it
aborts with a cryptic message:
ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:290 "((personality(old_personality | ADDR_NO_RANDOMIZE))) != ((-1))"
and a segfault (https://github.com/google/sanitizers/issues/837#issuecomment-2939267531).
This patch replaces the CHECK with more user-friendly diagnostics and
suggestions via printf, followed by Die().
---
.../lib/tsan/rtl/tsan_platform_linux.cpp | 20 +++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index 373acd3d95d01..a20c83ab37159 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -259,7 +259,14 @@ static void ReExecIfNeeded(bool ignore_heap) {
"WARNING: Program is run with randomized virtual address "
"space, which wouldn't work with ThreadSanitizer on Android.\n"
"Re-execing with fixed virtual address space.\n");
- CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
+
+ if (personality(old_personality | ADDR_NO_RANDOMIZE) == -1) {
+ Printf("FATAL: ThreadSanitizer: unable to disable ASLR (perhaps "
+ "sandboxing is enabled?).\n");
+ Printf("FATAL: Please rerun without sandboxing or ASLR.\n");
+ Die();
+ }
+
reexec = true;
}
# endif
@@ -287,7 +294,16 @@ static void ReExecIfNeeded(bool ignore_heap) {
"possibly due to high-entropy ASLR.\n"
"Re-execing with fixed virtual address space.\n"
"N.B. reducing ASLR entropy is preferable.\n");
- CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
+
+ if (personality(old_personality | ADDR_NO_RANDOMIZE) == -1) {
+ Printf("FATAL: ThreadSanitizer: encountered an incompatible memory "
+ "but was unable to disable ASLR (perhaps sandboxing is "
+ "enabled?).\n");
+ Printf("FATAL: Please rerun with lower ASLR entropy, ASLR disabled, "
+ "and/or sandboxing disabled.\n");
+ Die();
+ }
+
reexec = true;
} else {
Printf(
>From a601f6cec759fb22af2561ea17108d05127b6ca2 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Wed, 4 Jun 2025 17:41:17 +0000
Subject: [PATCH 2/3] Clarify and/or
---
compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index a20c83ab37159..331ec6e39de89 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -263,7 +263,7 @@ static void ReExecIfNeeded(bool ignore_heap) {
if (personality(old_personality | ADDR_NO_RANDOMIZE) == -1) {
Printf("FATAL: ThreadSanitizer: unable to disable ASLR (perhaps "
"sandboxing is enabled?).\n");
- Printf("FATAL: Please rerun without sandboxing or ASLR.\n");
+ Printf("FATAL: Please rerun without sandboxing and/or ASLR.\n");
Die();
}
>From 0f4f8cd2aed692bd91e44b6de8f8f5c5336479fe Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Wed, 4 Jun 2025 17:41:33 +0000
Subject: [PATCH 3/3] clang-format
---
.../lib/tsan/rtl/tsan_platform_linux.cpp | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index 331ec6e39de89..469525ac41cf8 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -261,8 +261,9 @@ static void ReExecIfNeeded(bool ignore_heap) {
"Re-execing with fixed virtual address space.\n");
if (personality(old_personality | ADDR_NO_RANDOMIZE) == -1) {
- Printf("FATAL: ThreadSanitizer: unable to disable ASLR (perhaps "
- "sandboxing is enabled?).\n");
+ Printf(
+ "FATAL: ThreadSanitizer: unable to disable ASLR (perhaps "
+ "sandboxing is enabled?).\n");
Printf("FATAL: Please rerun without sandboxing and/or ASLR.\n");
Die();
}
@@ -296,11 +297,13 @@ static void ReExecIfNeeded(bool ignore_heap) {
"N.B. reducing ASLR entropy is preferable.\n");
if (personality(old_personality | ADDR_NO_RANDOMIZE) == -1) {
- Printf("FATAL: ThreadSanitizer: encountered an incompatible memory "
- "but was unable to disable ASLR (perhaps sandboxing is "
- "enabled?).\n");
- Printf("FATAL: Please rerun with lower ASLR entropy, ASLR disabled, "
- "and/or sandboxing disabled.\n");
+ Printf(
+ "FATAL: ThreadSanitizer: encountered an incompatible memory "
+ "but was unable to disable ASLR (perhaps sandboxing is "
+ "enabled?).\n");
+ Printf(
+ "FATAL: Please rerun with lower ASLR entropy, ASLR disabled, "
+ "and/or sandboxing disabled.\n");
Die();
}
More information about the llvm-commits
mailing list