[clang] ANDROID: x86_64: Set default max-page-size to 16kB (PR #87413)

Kalesh Singh via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 11 17:07:14 PDT 2024


https://github.com/Kalesh-Singh updated https://github.com/llvm/llvm-project/pull/87413

>From ae55bb33871fc840c93ad59aed6016fc39998888 Mon Sep 17 00:00:00 2001
From: Kalesh Singh <kaleshsingh at google.com>
Date: Tue, 2 Apr 2024 11:26:11 -0700
Subject: [PATCH 1/3] ANDROID: x86_64: Set default max-page-size to 16kB

Android now supports both 4kB and 16kB page sizes. The vast majority
of android apps developed on x86_64 machines. In order to provide
emulators that support larger page sizes, Android emulates the page-size
in x86_64 to support testing apps for large page size support.

For this reason, update Android x86_64 ELFs default max-page-size to
16384 to support both 4kB and 16kB page-size devices.

It raises the concern of increased disk space and extra VMA slab memory.

In Android, RO partitions use sparse images, so that the holes on ELFs
don't allocate blocks on disk; and PackageManger ensures to punch
holes in ELF-paddings on the /data partition when an app is installed.

Extra VMA slab memory is addressed by the bionic loader, which extends
segment VMAs to cover the gaps between consecutive segment mappings, to
avoid the extra VMAs needed for the gap PROT_NONE mappings (---p). This
optimization is done in the crt_pad_segment note [1] is present in the ELF.

[1] https://cs.android.com/android/platform/superproject/main/+/189e480390ef13199d59e1fb54078e8b78ea6f79:bionic/libc/arch-common/bionic/crt_pad_segment.S

Signed-off-by: Kalesh Singh <kaleshsingh at google.com>
---
 clang/lib/Driver/ToolChains/Linux.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 6c2f23e57bce05..fb65881061effc 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -244,8 +244,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
       // Android ARM uses max-page-size=4096 to reduce VMA usage.
       ExtraOpts.push_back("-z");
       ExtraOpts.push_back("max-page-size=4096");
-    } else if (Triple.isAArch64()) {
+    } else if (Triple.isAArch64() || Triple.getArch() == llvm::Triple::x86_64) {
       // Android AArch64 uses max-page-size=16384 to support 4k/16k page sizes.
+      // Android emulates a 16k page size for app testing on x86_64 machines.
       ExtraOpts.push_back("-z");
       ExtraOpts.push_back("max-page-size=16384");
     }

>From acaf36c06b8cb35d05a2193d71aa17f738f25cd5 Mon Sep 17 00:00:00 2001
From: Kalesh Singh <kaleshsingh at google.com>
Date: Thu, 11 Apr 2024 11:34:32 -0700
Subject: [PATCH 2/3] Add max-page-size test for x86_64/i386

---
 clang/test/Driver/android-link.cpp | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/clang/test/Driver/android-link.cpp b/clang/test/Driver/android-link.cpp
index f9bdd00507d7bc..241d2b89ca5f3a 100644
--- a/clang/test/Driver/android-link.cpp
+++ b/clang/test/Driver/android-link.cpp
@@ -1,7 +1,7 @@
-// Check that we add relevant linker flags for Android ARM/AArch64.
+// Check that we add relevant linker flags for Android ARM/AArch64/i386/x86_64.
 
 // RUN: %clang -### -target arm-linux-androideabi %s 2>&1 | \
-// RUN:   FileCheck --check-prefix=MAX-PAGE-SIZE %s
+// RUN:   FileCheck --check-prefix=MAX-PAGE-SIZE-4KB %s
 
 // RUN: %clang -target aarch64-none-linux-android \
 // RUN:   -### -v %s 2> %t
@@ -17,10 +17,20 @@
 //
 // RUN: %clang -target aarch64-none-linux-android \
 // RUN:   -### -v %s 2> %t
-// RUN: FileCheck -check-prefix=MAX-PAGE-SIZE-AARCH64 < %t %s
+// RUN: FileCheck -check-prefix=MAX-PAGE-SIZE-16KB < %t %s
+//
+// RUN: %clang -### -target i386-none-linux-android %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=NO-MAX-PAGE-SIZE-16KB %s
+//
+// RUN: %clang -### -target x86_64-none-linux-gnu %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=NO-MAX-PAGE-SIZE-16KB %s
+//
+// RUN: %clang -### -target x86_64-none-linux-android %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=MAX-PAGE-SIZE-16KB %s
 //
 // GENERIC-ARM: --fix-cortex-a53-843419
 // CORTEX-A53: --fix-cortex-a53-843419
 // CORTEX-A57-NOT: --fix-cortex-a53-843419
-// MAX-PAGE-SIZE: "-z" "max-page-size=4096"
-// MAX-PAGE-SIZE-AARCH64: "-z" "max-page-size=16384"
+// MAX-PAGE-SIZE-4KB: "-z" "max-page-size=4096"
+// MAX-PAGE-SIZE-16KB: "-z" "max-page-size=16384"
+// NO-MAX-PAGE-SIZE-16KB-NOT: "-z" "max-page-size=16384"

>From 675ad73659434df84a09a99de959b8634a2d3c25 Mon Sep 17 00:00:00 2001
From: Kalesh Singh <kaleshsingh at google.com>
Date: Thu, 11 Apr 2024 17:02:33 -0700
Subject: [PATCH 3/3] Refactor clang/test/Driver/android-link.cpp

Remove ^//$ lines and use --target= instead of -target which has been
deprecated.

Signed-off-by: Kalesh Singh <kaleshsingh at google.com>
---
 clang/test/Driver/android-link.cpp | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/clang/test/Driver/android-link.cpp b/clang/test/Driver/android-link.cpp
index 241d2b89ca5f3a..ab7dae54055873 100644
--- a/clang/test/Driver/android-link.cpp
+++ b/clang/test/Driver/android-link.cpp
@@ -1,33 +1,33 @@
 // Check that we add relevant linker flags for Android ARM/AArch64/i386/x86_64.
 
-// RUN: %clang -### -target arm-linux-androideabi %s 2>&1 | \
+// RUN: %clang -### --target=arm-linux-androideabi %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=MAX-PAGE-SIZE-4KB %s
 
-// RUN: %clang -target aarch64-none-linux-android \
+// RUN: %clang --target=aarch64-none-linux-android \
 // RUN:   -### -v %s 2> %t
 // RUN: FileCheck -check-prefix=GENERIC-ARM < %t %s
-//
-// RUN: %clang -target aarch64-none-linux-android \
+
+// RUN: %clang --target=aarch64-none-linux-android \
 // RUN:   -mcpu=cortex-a53 -### -v %s 2> %t
 // RUN: FileCheck -check-prefix=CORTEX-A53 < %t %s
-//
-// RUN: %clang -target aarch64-none-linux-android \
+
+// RUN: %clang --target=aarch64-none-linux-android \
 // RUN:   -mcpu=cortex-a57 -### -v %s 2> %t
 // RUN: FileCheck -check-prefix=CORTEX-A57 < %t %s
-//
-// RUN: %clang -target aarch64-none-linux-android \
+
+// RUN: %clang --target=aarch64-none-linux-android \
 // RUN:   -### -v %s 2> %t
 // RUN: FileCheck -check-prefix=MAX-PAGE-SIZE-16KB < %t %s
-//
-// RUN: %clang -### -target i386-none-linux-android %s 2>&1 | \
+
+// RUN: %clang -### --target=i386-none-linux-android %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NO-MAX-PAGE-SIZE-16KB %s
-//
-// RUN: %clang -### -target x86_64-none-linux-gnu %s 2>&1 | \
+
+// RUN: %clang -### --target=x86_64-none-linux-gnu %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NO-MAX-PAGE-SIZE-16KB %s
-//
-// RUN: %clang -### -target x86_64-none-linux-android %s 2>&1 | \
+
+// RUN: %clang -### --target=x86_64-none-linux-android %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=MAX-PAGE-SIZE-16KB %s
-//
+
 // GENERIC-ARM: --fix-cortex-a53-843419
 // CORTEX-A53: --fix-cortex-a53-843419
 // CORTEX-A57-NOT: --fix-cortex-a53-843419



More information about the cfe-commits mailing list