Skip to content

Conversation

pcc
Copy link
Contributor

@pcc pcc commented Aug 15, 2025

This makes the tests pass on my AArch64 machine with 16K pages.

Not sure why some of the AArch64-specific test failures don't seem to
occur on sanitizer-aarch64-linux. I could also reproduce them by running
buildbot_cmake.sh on my machine.

Created using spr 1.3.6-beta.1
@pcc pcc requested review from vitalybuka and fmayer August 15, 2025 19:38
@llvmbot
Copy link
Member

llvmbot commented Aug 15, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Peter Collingbourne (pcc)

Changes

This makes the tests pass on my AArch64 machine with 16K pages.

Not sure why some of the AArch64-specific test failures don't seem to
occur on sanitizer-aarch64-linux. I could also reproduce them by running
buildbot_cmake.sh on my machine.


Full diff: https://github.com/llvm/llvm-project/pull/153860.diff

11 Files Affected:

  • (modified) compiler-rt/lib/gwp_asan/tests/basic.cpp (+6-5)
  • (modified) compiler-rt/lib/gwp_asan/tests/never_allocated.cpp (+6-4)
  • (modified) compiler-rt/test/asan/TestCases/Linux/release_to_os_test.cpp (+1)
  • (modified) compiler-rt/test/cfi/cross-dso/lit.local.cfg.py (+4)
  • (modified) compiler-rt/test/dfsan/atomic.cpp (+5-2)
  • (modified) compiler-rt/test/lit.common.cfg.py (+10)
  • (modified) compiler-rt/test/msan/dtls_test.c (+1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp (+1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Linux/release_to_os_test.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Linux/tls_get_addr.c (+3)
diff --git a/compiler-rt/lib/gwp_asan/tests/basic.cpp b/compiler-rt/lib/gwp_asan/tests/basic.cpp
index 88e7ed14a5c2f..7d36a2ee1f947 100644
--- a/compiler-rt/lib/gwp_asan/tests/basic.cpp
+++ b/compiler-rt/lib/gwp_asan/tests/basic.cpp
@@ -65,11 +65,12 @@ TEST_F(DefaultGuardedPoolAllocator, NonPowerOfTwoAlignment) {
 
 // Added multi-page slots? You'll need to expand this test.
 TEST_F(DefaultGuardedPoolAllocator, TooBigForSinglePageSlots) {
-  EXPECT_EQ(nullptr, GPA.allocate(0x1001, 0));
-  EXPECT_EQ(nullptr, GPA.allocate(0x1001, 1));
-  EXPECT_EQ(nullptr, GPA.allocate(0x1001, 0x1000));
-  EXPECT_EQ(nullptr, GPA.allocate(1, 0x2000));
-  EXPECT_EQ(nullptr, GPA.allocate(0, 0x2000));
+  size_t PageSize = sysconf(_SC_PAGESIZE);
+  EXPECT_EQ(nullptr, GPA.allocate(PageSize + 1, 0));
+  EXPECT_EQ(nullptr, GPA.allocate(PageSize + 1, 1));
+  EXPECT_EQ(nullptr, GPA.allocate(PageSize + 1, PageSize));
+  EXPECT_EQ(nullptr, GPA.allocate(1, 2 * PageSize));
+  EXPECT_EQ(nullptr, GPA.allocate(0, 2 * PageSize));
 }
 
 TEST_F(CustomGuardedPoolAllocator, AllocAllSlots) {
diff --git a/compiler-rt/lib/gwp_asan/tests/never_allocated.cpp b/compiler-rt/lib/gwp_asan/tests/never_allocated.cpp
index 2f695b4379861..37a4b384e4ac0 100644
--- a/compiler-rt/lib/gwp_asan/tests/never_allocated.cpp
+++ b/compiler-rt/lib/gwp_asan/tests/never_allocated.cpp
@@ -13,8 +13,10 @@
 #include "gwp_asan/tests/harness.h"
 
 TEST_P(BacktraceGuardedPoolAllocatorDeathTest, NeverAllocated) {
+  size_t PageSize = sysconf(_SC_PAGESIZE);
+
   SCOPED_TRACE("");
-  void *Ptr = GPA.allocate(0x1000);
+  void *Ptr = GPA.allocate(PageSize);
   GPA.deallocate(Ptr);
 
   std::string DeathNeedle =
@@ -23,7 +25,7 @@ TEST_P(BacktraceGuardedPoolAllocatorDeathTest, NeverAllocated) {
   // Trigger a guard page in a completely different slot that's never allocated.
   // Previously, there was a bug that this would result in nullptr-dereference
   // in the posix crash handler.
-  char *volatile NeverAllocatedPtr = static_cast<char *>(Ptr) + 0x3000;
+  char *volatile NeverAllocatedPtr = static_cast<char *>(Ptr) + 3 * PageSize;
   if (!Recoverable) {
     EXPECT_DEATH(*NeverAllocatedPtr = 0, DeathNeedle);
     return;
@@ -37,8 +39,8 @@ TEST_P(BacktraceGuardedPoolAllocatorDeathTest, NeverAllocated) {
   GetOutputBuffer().clear();
   for (size_t i = 0; i < 100; ++i) {
     *NeverAllocatedPtr = 0;
-    *(NeverAllocatedPtr + 0x2000) = 0;
-    *(NeverAllocatedPtr + 0x3000) = 0;
+    *(NeverAllocatedPtr + 2 * PageSize) = 0;
+    *(NeverAllocatedPtr + 3 * PageSize) = 0;
     ASSERT_TRUE(GetOutputBuffer().empty());
   }
 
diff --git a/compiler-rt/test/asan/TestCases/Linux/release_to_os_test.cpp b/compiler-rt/test/asan/TestCases/Linux/release_to_os_test.cpp
index 3e28ffde46ab6..dc3ead9e8436c 100644
--- a/compiler-rt/test/asan/TestCases/Linux/release_to_os_test.cpp
+++ b/compiler-rt/test/asan/TestCases/Linux/release_to_os_test.cpp
@@ -6,6 +6,7 @@
 // RUN: %env_asan_opts=allocator_release_to_os_interval_ms=-1 %run %t force 2>&1 | FileCheck %s --check-prefix=FORCE_RELEASE
 
 // REQUIRES: x86_64-target-arch
+// REQUIRES: page-size-4096
 
 #include <algorithm>
 #include <assert.h>
diff --git a/compiler-rt/test/cfi/cross-dso/lit.local.cfg.py b/compiler-rt/test/cfi/cross-dso/lit.local.cfg.py
index 2778d8c995fd1..bd0fabd1f26df 100644
--- a/compiler-rt/test/cfi/cross-dso/lit.local.cfg.py
+++ b/compiler-rt/test/cfi/cross-dso/lit.local.cfg.py
@@ -12,3 +12,7 @@ def getRoot(config):
 # Android O (API level 26) has support for cross-dso cfi in libdl.so.
 if config.android and "android-26" not in config.available_features:
     config.unsupported = True
+
+# The runtime library only supports 4K pages.
+if "page-size-4096" not in config.available_features:
+    config.unsupported = True
diff --git a/compiler-rt/test/dfsan/atomic.cpp b/compiler-rt/test/dfsan/atomic.cpp
index 22ee323c752f8..1bcccf3875b54 100644
--- a/compiler-rt/test/dfsan/atomic.cpp
+++ b/compiler-rt/test/dfsan/atomic.cpp
@@ -1,9 +1,12 @@
-// RUN: %clangxx_dfsan %s -fno-exceptions -o %t && %run %t
-// RUN: %clangxx_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -fno-exceptions -o %t && %run %t
+// RUN: %clangxx_dfsan %s -fno-exceptions -D_GLIBCXX_NO_ASSERTIONS -o %t && %run %t
+// RUN: %clangxx_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -fno-exceptions -D_GLIBCXX_NO_ASSERTIONS -o %t && %run %t
 //
 // Use -fno-exceptions to turn off exceptions to avoid instrumenting
 // __cxa_begin_catch, std::terminate and __gxx_personality_v0.
 //
+// Use -D_GLIBCXX_NO_ASSERTIONS to avoid depending on
+// std::__glibcxx_assert_fail.
+//
 // TODO: Support builtin atomics. For example, https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
 // DFSan instrumentation pass cannot identify builtin callsites yet.
 
diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 8328b407dcc36..f0c97aaefe536 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -965,6 +965,16 @@ def is_windows_lto_supported():
 else:
     config.available_features.add("memprof-shadow-scale-3")
 
+def target_page_size():
+    try:
+        proc = subprocess.Popen(f"{emulator or ""} python3", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+        out, err = proc.communicate(b'import os; print(os.sysconf("SC_PAGESIZE"))')
+        return int(out)
+    except:
+        return 4096
+
+config.available_features.add(f"page-size-{target_page_size()}")
+
 if config.expensive_checks:
     config.available_features.add("expensive_checks")
 
diff --git a/compiler-rt/test/msan/dtls_test.c b/compiler-rt/test/msan/dtls_test.c
index 3c384256147a0..0e49ac9feb9fe 100644
--- a/compiler-rt/test/msan/dtls_test.c
+++ b/compiler-rt/test/msan/dtls_test.c
@@ -11,6 +11,7 @@
 
    // Reports use-of-uninitialized-value, not analyzed
    XFAIL: target={{.*netbsd.*}}
+   XFAIL: aarch64-target-arch
 
 */
 
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp
index 9d7d46b462a88..cc76804aed210 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp
@@ -1,4 +1,5 @@
 // RUN: %clangxx -O1 %s -o %t && %run %t
+// REQUIRES: page-size-4096
 // UNSUPPORTED: android
 
 // Fail on powerpc64 bots with:
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/release_to_os_test.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/release_to_os_test.cpp
index 0fa77200bf1cc..c7a5534696361 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/release_to_os_test.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/release_to_os_test.cpp
@@ -11,6 +11,9 @@
 // FIXME: This mode uses 32bit allocator without purge.
 // UNSUPPORTED: hwasan-aliasing
 
+// Page size is hardcoded below, but test still fails even if not hardcoded.
+// REQUIRES: page-size-4096
+
 #include <algorithm>
 #include <assert.h>
 #include <fcntl.h>
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
index c288e1d69baf9..3e9ff924a3c4a 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/resize_tls_dynamic.cpp
@@ -11,6 +11,9 @@
 // FIXME: Investigate
 // UNSUPPORTED: target=powerpc64{{.*}}
 
+// Fails because AArch64 uses TLSDESC instead of __tls_get_addr.
+// UNSUPPORTED: aarch64-target-arch
+
 #include <string.h>
 
 #ifndef BUILD_DSO
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/tls_get_addr.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/tls_get_addr.c
index 0aff6039ac4e8..a4a4f64ed3706 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/tls_get_addr.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/tls_get_addr.c
@@ -13,6 +13,9 @@
 // FIXME: Fails for unknown reasons.
 // UNSUPPORTED: powerpc64le-target-arch
 
+// Fails because AArch64 uses TLSDESC instead of __tls_get_addr.
+// UNSUPPORTED: aarch64-target-arch
+
 #ifndef BUILD_SO
 #  include <assert.h>
 #  include <dlfcn.h>

@@ -1,9 +1,12 @@
// RUN: %clangxx_dfsan %s -fno-exceptions -o %t && %run %t
// RUN: %clangxx_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -fno-exceptions -o %t && %run %t
// RUN: %clangxx_dfsan %s -fno-exceptions -D_GLIBCXX_NO_ASSERTIONS -o %t && %run %t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to the rest of the change? This doesn't work on aarch64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked closer and it's got nothing to do with the architecture, it's because my aarch64 machine has a newer gcc with this change: gcc-mirror/gcc@361d230

I'll split this into a separate commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -965,6 +965,16 @@ def is_windows_lto_supported():
else:
config.available_features.add("memprof-shadow-scale-3")

def target_page_size():
try:
proc = subprocess.Popen(f"{emulator or ""} python3", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need shell? And, can we use check_output instead?

return int(subprocess.check_output(([emulator] if emulator else []) + ['python3', '-c', 'import os; print(os.sysconf("SC_PAGESIZE"))']))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's some flexibility in what emulator is allowed to be. It could be something like ssh foo which means that the shell needs to split ssh and foo. And then in that case the shell quoting rules end up messing up arguments with spaces (the arguments to ssh get joined together with " " and passed as a single argument to sh -c so part of the Python script is interpreted by the shell as a shell command). If we want something that works with and without ssh it seemed the simplest way was to pass the script via stdin.

Created using spr 1.3.6-beta.1
pcc added 2 commits August 15, 2025 14:13
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
pcc added a commit that referenced this pull request Aug 15, 2025
This makes the tests pass on my AArch64 machine with 16K pages.

Not sure why some of the AArch64-specific test failures don't seem to
occur on sanitizer-aarch64-linux. I could also reproduce them by running
buildbot_cmake.sh on my machine.

Pull Request: #153860
@pcc
Copy link
Contributor Author

pcc commented Aug 15, 2025

Pushed manually, spr land was giving me an error for some reason

ac2ae3e compiler-rt: Make the tests pass on AArch64 and with page size != 4096.
  #️⃣   Pull Request #153860
  🛫  Getting started...
  ❌  GitHub Pull Request merge failed
  🛑  GitHub: Unable to determine if workflow can be created or updated due to timeout; `workflows` scope may be
      required.
      Documentation URL: https://docs.github.com/rest/pulls/pulls#merge-a-pull-request

@pcc pcc closed this Aug 15, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Aug 15, 2025
…size != 4096.

This makes the tests pass on my AArch64 machine with 16K pages.

Not sure why some of the AArch64-specific test failures don't seem to
occur on sanitizer-aarch64-linux. I could also reproduce them by running
buildbot_cmake.sh on my machine.

Pull Request: llvm/llvm-project#153860
@gulfemsavrun
Copy link
Contributor

I think we started seeing a test failure after this patch:

XPASS: MemorySanitizer-AARCH64 :: dtls_test.c (1948 of 16545)
******************** TEST 'MemorySanitizer-AARCH64 :: dtls_test.c' FAILED ********************
Exit Code: 0

Command Output (stdout):
--
stack: 0xffff979f58f8 dtls: 0xffff970e8000
stack: 0xffff979f5900 dtls: 0xffff970e8000

--
Command Output (stderr):
--
/b/s/w/ir/x/w/llvm_build/./bin/clang  -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls   -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp # RUN: at line 1
+ /b/s/w/ir/x/w/llvm_build/./bin/clang -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp
/b/s/w/ir/x/w/llvm_build/./bin/clang  -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls   -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -DBUILD_SO -fPIC -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp-so.so -shared # RUN: at line 2
+ /b/s/w/ir/x/w/llvm_build/./bin/clang -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -DBUILD_SO -fPIC -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp-so.so -shared
/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp 2>&1 # RUN: at line 3
+ /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp

--

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8706433832179882497/overview

@pcc
Copy link
Contributor Author

pcc commented Aug 15, 2025

I think we started seeing a test failure after this patch:

XPASS: MemorySanitizer-AARCH64 :: dtls_test.c (1948 of 16545)
******************** TEST 'MemorySanitizer-AARCH64 :: dtls_test.c' FAILED ********************
Exit Code: 0

Command Output (stdout):
--
stack: 0xffff979f58f8 dtls: 0xffff970e8000
stack: 0xffff979f5900 dtls: 0xffff970e8000

--
Command Output (stderr):
--
/b/s/w/ir/x/w/llvm_build/./bin/clang  -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls   -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp # RUN: at line 1
+ /b/s/w/ir/x/w/llvm_build/./bin/clang -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp
/b/s/w/ir/x/w/llvm_build/./bin/clang  -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls   -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -DBUILD_SO -fPIC -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp-so.so -shared # RUN: at line 2
+ /b/s/w/ir/x/w/llvm_build/./bin/clang -fsanitize=memory -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -gline-tables-only -g /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/msan/dtls_test.c -DBUILD_SO -fPIC -o /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp-so.so -shared
/b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp 2>&1 # RUN: at line 3
+ /b/s/w/ir/x/w/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/msan/AARCH64/Output/dtls_test.c.tmp

--

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8706433832179882497/overview

Thanks, looking

@pcc
Copy link
Contributor Author

pcc commented Aug 15, 2025

Should be fixed by 4485a3f

@gulfemsavrun
Copy link
Contributor

Should be fixed by 4485a3f

Thanks for the quick fix!

fabio-d added a commit that referenced this pull request Aug 26, 2025
This fixes build failures on Fuchsia that started with #153860
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants