Skip to content

Commit 2620ccc

Browse files
Kalesh-SinghKalesh Singh
and
Kalesh Singh
authored
ANDROID: x86_64: Set default max-page-size to 16kB (llvm#87413)
Android now supports both 4kB and 16kB page sizes. The vast majority of android apps are 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. Increase max-page-size raises concerns 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 PackageManager ensures to punch holes in ELF-paddings on the /data partition when apps are 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 <[email protected]> Co-authored-by: Kalesh Singh <[email protected]>
1 parent a11a432 commit 2620ccc

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
244244
// Android ARM uses max-page-size=4096 to reduce VMA usage.
245245
ExtraOpts.push_back("-z");
246246
ExtraOpts.push_back("max-page-size=4096");
247-
} else if (Triple.isAArch64()) {
247+
} else if (Triple.isAArch64() || Triple.getArch() == llvm::Triple::x86_64) {
248248
// Android AArch64 uses max-page-size=16384 to support 4k/16k page sizes.
249+
// Android emulates a 16k page size for app testing on x86_64 machines.
249250
ExtraOpts.push_back("-z");
250251
ExtraOpts.push_back("max-page-size=16384");
251252
}

clang/test/Driver/android-link.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
// Check that we add relevant linker flags for Android ARM/AArch64.
1+
// Check that we add relevant linker flags for Android ARM/AArch64/i386/x86_64.
22

3-
// RUN: %clang -### -target arm-linux-androideabi %s 2>&1 | \
4-
// RUN: FileCheck --check-prefix=MAX-PAGE-SIZE %s
3+
// RUN: %clang -### --target=arm-linux-androideabi %s 2>&1 | \
4+
// RUN: FileCheck --check-prefix=MAX-PAGE-SIZE-4KB %s
55

6-
// RUN: %clang -target aarch64-none-linux-android \
6+
// RUN: %clang --target=aarch64-none-linux-android \
77
// RUN: -### -v %s 2> %t
88
// RUN: FileCheck -check-prefix=GENERIC-ARM < %t %s
9-
//
10-
// RUN: %clang -target aarch64-none-linux-android \
9+
10+
// RUN: %clang --target=aarch64-none-linux-android \
1111
// RUN: -mcpu=cortex-a53 -### -v %s 2> %t
1212
// RUN: FileCheck -check-prefix=CORTEX-A53 < %t %s
13-
//
14-
// RUN: %clang -target aarch64-none-linux-android \
13+
14+
// RUN: %clang --target=aarch64-none-linux-android \
1515
// RUN: -mcpu=cortex-a57 -### -v %s 2> %t
1616
// RUN: FileCheck -check-prefix=CORTEX-A57 < %t %s
17-
//
18-
// RUN: %clang -target aarch64-none-linux-android \
17+
18+
// RUN: %clang --target=aarch64-none-linux-android \
1919
// RUN: -### -v %s 2> %t
20-
// RUN: FileCheck -check-prefix=MAX-PAGE-SIZE-AARCH64 < %t %s
21-
//
20+
// RUN: FileCheck -check-prefix=MAX-PAGE-SIZE-16KB < %t %s
21+
22+
// RUN: %clang -### --target=i386-none-linux-android %s 2>&1 | \
23+
// RUN: FileCheck --check-prefix=NO-MAX-PAGE-SIZE-16KB %s
24+
25+
// RUN: %clang -### --target=x86_64-none-linux-gnu %s 2>&1 | \
26+
// RUN: FileCheck --check-prefix=NO-MAX-PAGE-SIZE-16KB %s
27+
28+
// RUN: %clang -### --target=x86_64-none-linux-android %s 2>&1 | \
29+
// RUN: FileCheck --check-prefix=MAX-PAGE-SIZE-16KB %s
30+
2231
// GENERIC-ARM: --fix-cortex-a53-843419
2332
// CORTEX-A53: --fix-cortex-a53-843419
2433
// CORTEX-A57-NOT: --fix-cortex-a53-843419
25-
// MAX-PAGE-SIZE: "-z" "max-page-size=4096"
26-
// MAX-PAGE-SIZE-AARCH64: "-z" "max-page-size=16384"
34+
// MAX-PAGE-SIZE-4KB: "-z" "max-page-size=4096"
35+
// MAX-PAGE-SIZE-16KB: "-z" "max-page-size=16384"
36+
// NO-MAX-PAGE-SIZE-16KB-NOT: "-z" "max-page-size=16384"

0 commit comments

Comments
 (0)