From 82f97d33d14c2fce3b7989f3063a98dbd09c103e Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 25 Sep 2024 05:31:48 +0300 Subject: [PATCH] aarch64: Correctly implement the null function trap --- Utilities/JITLLVM.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Utilities/JITLLVM.cpp b/Utilities/JITLLVM.cpp index 0a1038f61e..c88be65938 100644 --- a/Utilities/JITLLVM.cpp +++ b/Utilities/JITLLVM.cpp @@ -110,18 +110,21 @@ static u64 make_null_function(const std::string& name) c.align(AlignMode::kData, 16); #else // AArch64 implementation - Label jmp_address = c.newLabel(); Label data = c.newLabel(); - // Force absolute jump to prevent out of bounds PC-rel jmp - c.ldr(args[0], arm::ptr(jmp_address)); - c.br(args[0]); - c.align(AlignMode::kCode, 16); + Label jump_address = c.newLabel(); + c.ldr(args[0], arm::ptr(data, 0)); + c.ldr(a64::x14, arm::ptr(jump_address, 0)); + c.br(a64::x14); + // Data frame + c.align(AlignMode::kCode, 16); + c.bind(jump_address); + c.embedUInt64(reinterpret_cast(&null)); + + c.align(AlignMode::kData, 16); c.bind(data); c.embed(name.c_str(), name.size()); c.embedUInt8(0U); - c.bind(jmp_address); - c.embedUInt64(reinterpret_cast(&null)); c.align(AlignMode::kData, 16); #endif });