From 306718fe1e9ce5daf6fd688c9c69a4db5ebf4368 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 22 Sep 2021 17:11:36 +0000 Subject: [PATCH] [vm, compiler] Fix FFI callbacks on ARM64C. HEAP_BITS must be initialized before any variant of LoadCompressed is used. TEST=ci Bug: https://github.com/dart-lang/sdk/issues/47259 Change-Id: I01ebb4e6c2eee1e61e15c1d8cc2913d0db27c2bf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214124 Commit-Queue: Ryan Macnak Reviewed-by: Daco Harkes --- runtime/vm/compiler/stub_code_compiler.h | 2 +- runtime/vm/compiler/stub_code_compiler_arm64.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/runtime/vm/compiler/stub_code_compiler.h b/runtime/vm/compiler/stub_code_compiler.h index a425e9700e9..58f52ce0ef8 100644 --- a/runtime/vm/compiler/stub_code_compiler.h +++ b/runtime/vm/compiler/stub_code_compiler.h @@ -128,7 +128,7 @@ class StubCodeCompiler : public AllStatic { #elif defined(TARGET_ARCH_ARM64) static constexpr intptr_t kNativeCallbackTrampolineSize = 12; #if defined(DART_COMPRESSED_POINTERS) - static constexpr intptr_t kNativeCallbackSharedStubSize = 276; + static constexpr intptr_t kNativeCallbackSharedStubSize = 292; #else static constexpr intptr_t kNativeCallbackSharedStubSize = 268; #endif diff --git a/runtime/vm/compiler/stub_code_compiler_arm64.cc b/runtime/vm/compiler/stub_code_compiler_arm64.cc index 0eeef85ca81..54196b7a7bc 100644 --- a/runtime/vm/compiler/stub_code_compiler_arm64.cc +++ b/runtime/vm/compiler/stub_code_compiler_arm64.cc @@ -415,6 +415,13 @@ void StubCodeCompiler::GenerateJITCallbackTrampolines( // Load the code object. __ LoadFromOffset(R10, THR, compiler::target::Thread::callback_code_offset()); +#if defined(DART_COMPRESSED_POINTERS) + // Partially setup HEAP_BITS for LoadCompressed[FieldFromOffset]. + ASSERT(IsAbiPreservedRegister(HEAP_BITS)); // Need to save and restore. + __ Push(HEAP_BITS); + __ ldr(HEAP_BITS, compiler::Address(THR, target::Thread::heap_base_offset())); + __ LsrImmediate(HEAP_BITS, HEAP_BITS, 32); +#endif __ LoadCompressedFieldFromOffset( R10, R10, compiler::target::GrowableObjectArray::data_offset()); __ LoadCompressed( @@ -427,6 +434,9 @@ void StubCodeCompiler::GenerateJITCallbackTrampolines( /*array=*/R10, /*index=*/R9, /*temp=*/TMP)); +#if defined(DART_COMPRESSED_POINTERS) + __ Pop(HEAP_BITS); +#endif __ LoadFieldFromOffset(R10, R10, compiler::target::Code::entry_point_offset());