Skip to content

Commit

Permalink
[vm] Support 16k page size on Android.
Browse files Browse the repository at this point in the history
 - Increase the size of the FFI trampoline template.
 - Increase alignment of ELF binaries generated by the VM.
 - Pass flags for binaries generated by the NDK's linker increase alignment.
 - Runtime allocation already either rounds up to the runtime-queried page size or assumes it is no more than 512k.

TEST=ci, readelf
Bug: go/16k-app-guide
Change-Id: I4fdb2a47534a6a24875e205c3a357b5415ca18b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321302
Commit-Queue: Ryan Macnak <[email protected]>
Reviewed-by: Liam Appelbe <[email protected]>
Reviewed-by: Slava Egorov <[email protected]>
  • Loading branch information
rmacnak-google authored and Commit Queue committed Aug 17, 2023
1 parent edaea9b commit 6dcbc9f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ config("compiler") {
"-Wl,--exclude-libs=libc++_static.a",

"-fuse-ld=lld",

# Currently defaults to 4k, but Android will be moving to 16k page size,
# and for future-proofing, 64k boundaries will be required.
"-Wl,-z,max-page-size=65536",
]

if (is_clang) {
Expand Down
1 change: 1 addition & 0 deletions pkg/test_runner/lib/src/compiler_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration
"$host-x86_64/bin/$abiTriple-gcc";
shared = '-shared';
ldFlags.add('-Wl,--no-undefined');
ldFlags.add('-Wl,-z,max-page-size=65536');
} else if (Platform.isLinux) {
if (_isSimArm || (_isArm && _configuration.useQemu)) {
cc = 'arm-linux-gnueabihf-gcc';
Expand Down
2 changes: 2 additions & 0 deletions runtime/vm/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace dart {
// Follow LLVM (https://reviews.llvm.org/D25079) and set maximum page size
// to 64 KB for ARM64 Linux builds.
static constexpr intptr_t kElfPageSize = 64 * KB;
#elif defined(DART_TARGET_OS_ANDROID) && defined(TARGET_ARCH_IS_64_BIT)
static constexpr intptr_t kElfPageSize = 64 * KB;
#else
static constexpr intptr_t kElfPageSize = 16 * KB;
#endif
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/ffi_callback_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void FfiCallbackMetadata::EnsureStubPageLocked() {
const Code& trampoline_code = StubCode::FfiCallbackTrampoline();
const uword code_start = trampoline_code.EntryPoint();
const uword code_end = code_start + trampoline_code.Size();
const uword page_start = code_start & kPageMask;
const uword page_start = code_start & ~(VirtualMemory::PageSize() - 1);

ASSERT_LESS_OR_EQUAL((code_start - page_start) + trampoline_code.Size(),
RXMappingSize());
Expand Down
2 changes: 2 additions & 0 deletions runtime/vm/ffi_callback_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class FfiCallbackMetadata {
// get it as close as possible to avoid wasting memory.
#if defined(DART_TARGET_OS_LINUX) && defined(TARGET_ARCH_ARM64)
static constexpr intptr_t kPageSize = 64 * KB;
#elif defined(DART_TARGET_OS_ANDROID) && defined(TARGET_ARCH_IS_64_BIT)
static constexpr intptr_t kPageSize = 64 * KB;
#elif defined(DART_TARGET_OS_MACOS) && defined(TARGET_ARCH_ARM64)
static constexpr intptr_t kPageSize = 16 * KB;
#elif defined(DART_TARGET_OS_FUCHSIA)
Expand Down

0 comments on commit 6dcbc9f

Please sign in to comment.