Skip to content

Commit 1837ce1

Browse files
authored
Revert "[compiler-rt] Use getpagesize for Android."
This reverts commit 771698b.
1 parent 771698b commit 1837ce1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@
8282
# include <sys/personality.h>
8383
# endif
8484

85+
# if SANITIZER_ANDROID && __ANDROID_API__ < 35
86+
// The weak `strerrorname_np` (introduced in API level 35) definition,
87+
// allows for checking the API level at runtime.
88+
extern "C" SANITIZER_WEAK_ATTRIBUTE const char *strerrorname_np(int);
89+
# endif
90+
8591
# if SANITIZER_LINUX && defined(__loongarch__)
8692
# include <sys/sysmacros.h>
8793
# endif
@@ -1213,11 +1219,17 @@ uptr GetPageSize() {
12131219
int rv = internal_sysctl(mib, 2, &pz, &pzl, nullptr, 0);
12141220
CHECK_EQ(rv, 0);
12151221
return (uptr)pz;
1216-
# elif SANITIZER_ANDROID
1217-
// Using `getpagesize` because calling `getauxval` or `sysconf` from the
1218-
// `.preinit_array` can cause crashes on some older API levels.
1219-
return getpagesize();
12201222
# elif SANITIZER_USE_GETAUXVAL
1223+
# if SANITIZER_ANDROID && __ANDROID_API__ < 35
1224+
// The 16 KB page size was introduced in Android 15 (API level 35), while
1225+
// earlier versions of Android always used a 4 KB page size.
1226+
// We are checking the weak definition of `strerrorname_np` (introduced in API
1227+
// level 35) because some earlier API levels crashed when
1228+
// `getauxval(AT_PAGESZ)` was called from the `.preinit_array`.
1229+
if (!strerrorname_np)
1230+
return 4096;
1231+
# endif
1232+
12211233
return getauxval(AT_PAGESZ);
12221234
# else
12231235
return sysconf(_SC_PAGESIZE); // EXEC_PAGESIZE may not be trustworthy.

0 commit comments

Comments
 (0)