From d95b0e3d46da8e88f484f236cb4222f5a6dc5926 Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Mon, 11 Aug 2025 09:09:33 +0200 Subject: [PATCH] add new relocation type (#4500) --- core/iwasm/aot/aot_loader.c | 12 +++++++++--- core/iwasm/aot/arch/aot_reloc_x86_64.c | 18 +++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 388d9ffdf..5fdd34ed1 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -3173,7 +3173,9 @@ str2uint64(const char *buf, uint64 *p_res) return true; } -#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */ +#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */ +#define R_X86_64_GOTPCRELX 41 /* relaxable GOTPCREL */ +#define R_X86_64_REX_GOTPCRELX 42 /* relaxable GOTPCREL with REX prefix */ static bool is_text_section(const char *section_name) @@ -3236,7 +3238,9 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group, } #if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \ && !defined(BH_PLATFORM_WINDOWS) - if (relocation->relocation_type == R_X86_64_GOTPCREL) { + if (relocation->relocation_type == R_X86_64_GOTPCREL + || relocation->relocation_type == R_X86_64_GOTPCRELX + || relocation->relocation_type == R_X86_64_REX_GOTPCRELX) { GOTItem *got_item = module->got_item_list; uint32 got_item_idx = 0; @@ -3743,7 +3747,9 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, bh_memcpy_s(symbol_name_buf, (uint32)sizeof(symbol_name_buf), symbol_name, symbol_name_len); - if (relocation.relocation_type == R_X86_64_GOTPCREL + if ((relocation.relocation_type == R_X86_64_GOTPCREL + || relocation.relocation_type == R_X86_64_GOTPCRELX + || relocation.relocation_type == R_X86_64_REX_GOTPCRELX) && !strncmp(symbol_name_buf, AOT_FUNC_PREFIX, strlen(AOT_FUNC_PREFIX))) { uint32 func_idx = diff --git a/core/iwasm/aot/arch/aot_reloc_x86_64.c b/core/iwasm/aot/arch/aot_reloc_x86_64.c index fe18d79c6..2f36c4c3b 100644 --- a/core/iwasm/aot/arch/aot_reloc_x86_64.c +++ b/core/iwasm/aot/arch/aot_reloc_x86_64.c @@ -6,13 +6,15 @@ #include "aot_reloc.h" #if !defined(BH_PLATFORM_WINDOWS) -#define R_X86_64_64 1 /* Direct 64 bit */ -#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ -#define R_X86_64_PLT32 4 /* 32 bit PLT address */ -#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */ -#define R_X86_64_32 10 /* Direct 32 bit zero extended */ -#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ -#define R_X86_64_PC64 24 /* PC relative 64 bit */ +#define R_X86_64_64 1 /* Direct 64 bit */ +#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ +#define R_X86_64_PLT32 4 /* 32 bit PLT address */ +#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */ +#define R_X86_64_32 10 /* Direct 32 bit zero extended */ +#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ +#define R_X86_64_PC64 24 /* PC relative 64 bit */ +#define R_X86_64_GOTPCRELX 41 /* relaxable GOTPCREL */ +#define R_X86_64_REX_GOTPCRELX 42 /* relaxable GOTPCREL with REX prefix */ #else #ifndef IMAGE_REL_AMD64_ADDR64 #define IMAGE_REL_AMD64_ADDR64 1 /* The 64-bit VA of the relocation target */ @@ -152,6 +154,8 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, #if !defined(BH_PLATFORM_WINDOWS) case R_X86_64_PC32: case R_X86_64_GOTPCREL: /* GOT + G has been calculated as symbol_addr */ + case R_X86_64_GOTPCRELX: + case R_X86_64_REX_GOTPCRELX: { intptr_t target_addr = (intptr_t) /* S + A - P */ ((uintptr_t)symbol_addr + reloc_addend