[compiler-rt] [Asan] Ensure minimum stack size 128KB in ThreadedStressStackReuseTest (PR #165198)
Riyaz Ahmad via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 11 05:45:08 PST 2025
https://github.com/riyaz86a updated https://github.com/llvm/llvm-project/pull/165198
>From 1409e63de8e6b5237350389a1423d4eb65d3c125 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad <riyaz.ahmad at ibm.com>
Date: Fri, 24 Oct 2025 10:00:16 +0000
Subject: [PATCH 1/3] [Asan] Ensure minimum stack size 128KB in
ThreadedStressStackReuseTest
This test fails on AIX due to smaller default thread stack size.
Set thread stack size to a minimum of 128KB to ensure reliable test
behavior across platforms.
---
compiler-rt/lib/asan/tests/asan_test.cpp | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp
index 2d23a12cc6ae2..4fc5c978f82a5 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_test.cpp
@@ -1115,15 +1115,30 @@ TEST(AddressSanitizer, StressStackReuseTest) {
LotsOfStackReuse();
}
+// On some platform (ex: AIX), the default thread stack size (~96 KB) is
+// insufficient for this test and can lead to stack overflows. The test
+// has been updated to accomodate platforms with smaller default thread
+// stack sizes.
+#define MIN_STACK_SIZE (128 * 1024) // Minimum stack size to use: 128 KB
TEST(AddressSanitizer, ThreadedStressStackReuseTest) {
const int kNumThreads = 20;
pthread_t t[kNumThreads];
+ size_t curStackSize = 0;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ // Get the current (default) thread stack size
+ pthread_attr_getstacksize(&attr, &curStackSize);
+ if (curStackSize < MIN_STACK_SIZE) {
+ int rc = pthread_attr_setstacksize(&attr, MIN_STACK_SIZE);
+ ASSERT_EQ(0, rc);
+ }
for (int i = 0; i < kNumThreads; i++) {
- PTHREAD_CREATE(&t[i], 0, (void* (*)(void *x))LotsOfStackReuse, 0);
+ PTHREAD_CREATE(&t[i], &attr, (void* (*)(void *x))LotsOfStackReuse, 0);
}
for (int i = 0; i < kNumThreads; i++) {
PTHREAD_JOIN(t[i], 0);
}
+ pthread_attr_destroy(&attr);
}
// pthread_exit tries to perform unwinding stuff that leads to dlopen'ing
>From 4ed65d61fa630043e868abf8122131842ffbafc4 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad <riyaz.ahmad at ibm.com>
Date: Tue, 28 Oct 2025 14:22:19 +0000
Subject: [PATCH 2/3] clang-format modification
---
compiler-rt/lib/asan/tests/asan_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp
index 4fc5c978f82a5..c96cbaef4c0c5 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_test.cpp
@@ -1133,7 +1133,7 @@ TEST(AddressSanitizer, ThreadedStressStackReuseTest) {
ASSERT_EQ(0, rc);
}
for (int i = 0; i < kNumThreads; i++) {
- PTHREAD_CREATE(&t[i], &attr, (void* (*)(void *x))LotsOfStackReuse, 0);
+ PTHREAD_CREATE(&t[i], &attr, (void* (*)(void* x))LotsOfStackReuse, 0);
}
for (int i = 0; i < kNumThreads; i++) {
PTHREAD_JOIN(t[i], 0);
>From 9e2f29c56dafd2c5d620f4959de7e7c0e5303a69 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad <riyaz.ahmad at ibm.com>
Date: Tue, 11 Nov 2025 13:51:30 +0000
Subject: [PATCH 3/3] Update comment per review feedback
---
compiler-rt/lib/asan/tests/asan_test.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp
index c96cbaef4c0c5..59d64ac4753ca 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_test.cpp
@@ -1116,10 +1116,8 @@ TEST(AddressSanitizer, StressStackReuseTest) {
}
// On some platform (ex: AIX), the default thread stack size (~96 KB) is
-// insufficient for this test and can lead to stack overflows. The test
-// has been updated to accomodate platforms with smaller default thread
-// stack sizes.
-#define MIN_STACK_SIZE (128 * 1024) // Minimum stack size to use: 128 KB
+// insufficient for this test and can lead to stack overflows.
+#define MIN_STACK_SIZE (128 * 1024) // 128 KB
TEST(AddressSanitizer, ThreadedStressStackReuseTest) {
const int kNumThreads = 20;
pthread_t t[kNumThreads];
More information about the llvm-commits
mailing list