Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

funsafe-ptr
Copy link

No description provided.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@funsafe-ptr funsafe-ptr changed the title [compiler-rt] Fixed Android 8.1 getauxval(AT_PAGESZ) crashes if called from .preinit_array. #113427 [compiler-rt] Fixed Android 8.1 getauxval(AT_PAGESZ) crashes if called from .preinit_array. (#113427) Nov 13, 2024
@funsafe-ptr
Copy link
Author

@fmayer

Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

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

Please change status of PR from "Draft"

@@ -1237,6 +1242,12 @@ uptr GetPageSize() {
CHECK_EQ(rv, 0);
return (uptr)pz;
# elif SANITIZER_USE_GETAUXVAL

# if SANITIZER_ANDROID && __ANDROID_API__ < 35
if (!strerrorname_np)
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave comment about the API level this was introduced by, and also add the fact that before that API level, the page size was always 4096

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

github-actions bot commented Nov 22, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -1237,6 +1242,12 @@ uptr GetPageSize() {
CHECK_EQ(rv, 0);
return (uptr)pz;
# elif SANITIZER_USE_GETAUXVAL

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: drop the blank line

@fmayer
Copy link
Contributor

fmayer commented Nov 23, 2024

@DanAlbert does this LGTY from NDK perspective to use a weak symbol to runtime detect API level?

@llvmbot
Copy link
Member

llvmbot commented Nov 23, 2024

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

Author: None (funsafe-ptr)

Changes

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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp (+13)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 04b095dca904ab..344b16be4a96e0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -82,6 +82,12 @@
 #    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
@@ -1237,6 +1243,13 @@ 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
+
   return getauxval(AT_PAGESZ);
 #    else
   return sysconf(_SC_PAGESIZE);  // EXEC_PAGESIZE may not be trustworthy.

@fmayer
Copy link
Contributor

fmayer commented Nov 23, 2024

FYI: "This commit is not signed, but one or more authors requires that any commit attributed to them is signed."

@funsafe-ptr
Copy link
Author

I tested it on Termux using Android 8.1. termux/termux-packages#22369 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants