[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
Fri Nov 22 17:12:01 PST 2024


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

>From da104df54f9bc9ab8acc609fba475ea867ed19aa 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 1/3] [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.

>From 05062663e3043054a68d3649f9d6bf8e094a877a Mon Sep 17 00:00:00 2001
From: funsafe-ptr <funsafe-ptr at proton.me>
Date: Sat, 23 Nov 2024 00:01:13 +0000
Subject: [PATCH 2/3] [compiler-rt] Add Android page size comment and
 formatting.

---
 compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 3be26e785b9647..cd67328498f3d2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -83,7 +83,8 @@
 #  endif
 
 # if SANITIZER_ANDROID && __ANDROID_API__ < 35
-// The weak strerrorname_np definition allows to check for the API level at runtime.
+// 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
 
@@ -1219,8 +1220,9 @@ uptr GetPageSize() {
   CHECK_EQ(rv, 0);
   return (uptr)pz;
 #    elif SANITIZER_USE_GETAUXVAL
-
 #      if SANITIZER_ANDROID && __ANDROID_API__ < 35
+  // The 16 KB page size was introduced in Android 15, while earlier versions 
+  // of Android used a 4 KB page size.
   if (!strerrorname_np)
     return 4096;
 #      endif

>From d7ce33f252b36542be71385b00ff8402142a7904 Mon Sep 17 00:00:00 2001
From: funsafe-ptr <funsafe-ptr at proton.me>
Date: Sat, 23 Nov 2024 00:23:19 +0000
Subject: [PATCH 3/3] [compiler-rt] Fix formatting.

Signed-off-by: funsafe-ptr <funsafe-ptr at proton.me>
---
 compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index cd67328498f3d2..d7fbee297f20a1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -82,11 +82,11 @@
 #    include <sys/personality.h>
 #  endif
 
-# if SANITIZER_ANDROID && __ANDROID_API__ < 35
+#  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
+extern "C" SANITIZER_WEAK_ATTRIBUTE const char *strerrorname_np(int);
+#  endif
 
 #  if SANITIZER_LINUX && defined(__loongarch__)
 #    include <sys/sysmacros.h>
@@ -1221,7 +1221,7 @@ uptr GetPageSize() {
   return (uptr)pz;
 #    elif SANITIZER_USE_GETAUXVAL
 #      if SANITIZER_ANDROID && __ANDROID_API__ < 35
-  // The 16 KB page size was introduced in Android 15, while earlier versions 
+  // The 16 KB page size was introduced in Android 15, while earlier versions
   // of Android used a 4 KB page size.
   if (!strerrorname_np)
     return 4096;



More information about the llvm-commits mailing list