[vm] Support 16k page size on Android.

- 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 <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
Ryan Macnak 2023-08-17 17:38:48 +00:00 committed by Commit Queue
parent edaea9b489
commit 6dcbc9fc14
5 changed files with 10 additions and 1 deletions

View file

@ -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) {

View file

@ -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';

View file

@ -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

View file

@ -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());

View file

@ -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)