[compiler-rt] [compiler-rt] Fixed Android 8.1 `getauxval(AT_PAGESZ)` crashes if called from `.preinit_array`. #113427 (PR #116121)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 15:37:33 PST 2024


https://github.com/funsafe-ptr created https://github.com/llvm/llvm-project/pull/116121

None

>From 79e7f6ccfe6162ae1aef9d1c5baf79a58d41f28d Mon Sep 17 00:00:00 2001
From: funsafe-ptr <funsafe-ptr at proton.me>
Date: Wed, 13 Nov 2024 23:30:07 +0000
Subject: [PATCH] [compiler-rt] Fixed Android 8.1 `getauxval(AT_PAGESZ)`
 crashes if called from `.preinit_array`. (#113427)

---
 compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 8b1850f85010cf..3be26e785b9647 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -82,6 +82,11 @@
 #    include <sys/personality.h>
 #  endif
 
+# if SANITIZER_ANDROID && __ANDROID_API__ < 35
+// The weak strerrorname_np definition allows to check for the API level at runtime.
+extern "C" SANITIZER_WEAK_ATTRIBUTE const char* strerrorname_np(int);
+# endif
+
 #  if SANITIZER_LINUX && defined(__loongarch__)
 #    include <sys/sysmacros.h>
 #  endif
@@ -1214,6 +1219,12 @@ uptr GetPageSize() {
   CHECK_EQ(rv, 0);
   return (uptr)pz;
 #    elif SANITIZER_USE_GETAUXVAL
+
+#      if SANITIZER_ANDROID && __ANDROID_API__ < 35
+  if (!strerrorname_np)
+    return 4096;
+#      endif
+
   return getauxval(AT_PAGESZ);
 #    else
   return sysconf(_SC_PAGESIZE);  // EXEC_PAGESIZE may not be trustworthy.



More information about the llvm-commits mailing list