Skip to content

Commit d95b0e3

Browse files
add new relocation type (#4500)
1 parent a4f3077 commit d95b0e3

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,9 @@ str2uint64(const char *buf, uint64 *p_res)
31733173
return true;
31743174
}
31753175

3176-
#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
3176+
#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
3177+
#define R_X86_64_GOTPCRELX 41 /* relaxable GOTPCREL */
3178+
#define R_X86_64_REX_GOTPCRELX 42 /* relaxable GOTPCREL with REX prefix */
31773179

31783180
static bool
31793181
is_text_section(const char *section_name)
@@ -3236,7 +3238,9 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
32363238
}
32373239
#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \
32383240
&& !defined(BH_PLATFORM_WINDOWS)
3239-
if (relocation->relocation_type == R_X86_64_GOTPCREL) {
3241+
if (relocation->relocation_type == R_X86_64_GOTPCREL
3242+
|| relocation->relocation_type == R_X86_64_GOTPCRELX
3243+
|| relocation->relocation_type == R_X86_64_REX_GOTPCRELX) {
32403244
GOTItem *got_item = module->got_item_list;
32413245
uint32 got_item_idx = 0;
32423246

@@ -3743,7 +3747,9 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
37433747
bh_memcpy_s(symbol_name_buf, (uint32)sizeof(symbol_name_buf),
37443748
symbol_name, symbol_name_len);
37453749

3746-
if (relocation.relocation_type == R_X86_64_GOTPCREL
3750+
if ((relocation.relocation_type == R_X86_64_GOTPCREL
3751+
|| relocation.relocation_type == R_X86_64_GOTPCRELX
3752+
|| relocation.relocation_type == R_X86_64_REX_GOTPCRELX)
37473753
&& !strncmp(symbol_name_buf, AOT_FUNC_PREFIX,
37483754
strlen(AOT_FUNC_PREFIX))) {
37493755
uint32 func_idx =

core/iwasm/aot/arch/aot_reloc_x86_64.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#include "aot_reloc.h"
77

88
#if !defined(BH_PLATFORM_WINDOWS)
9-
#define R_X86_64_64 1 /* Direct 64 bit */
10-
#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
11-
#define R_X86_64_PLT32 4 /* 32 bit PLT address */
12-
#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
13-
#define R_X86_64_32 10 /* Direct 32 bit zero extended */
14-
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
15-
#define R_X86_64_PC64 24 /* PC relative 64 bit */
9+
#define R_X86_64_64 1 /* Direct 64 bit */
10+
#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
11+
#define R_X86_64_PLT32 4 /* 32 bit PLT address */
12+
#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
13+
#define R_X86_64_32 10 /* Direct 32 bit zero extended */
14+
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
15+
#define R_X86_64_PC64 24 /* PC relative 64 bit */
16+
#define R_X86_64_GOTPCRELX 41 /* relaxable GOTPCREL */
17+
#define R_X86_64_REX_GOTPCRELX 42 /* relaxable GOTPCREL with REX prefix */
1618
#else
1719
#ifndef IMAGE_REL_AMD64_ADDR64
1820
#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,
152154
#if !defined(BH_PLATFORM_WINDOWS)
153155
case R_X86_64_PC32:
154156
case R_X86_64_GOTPCREL: /* GOT + G has been calculated as symbol_addr */
157+
case R_X86_64_GOTPCRELX:
158+
case R_X86_64_REX_GOTPCRELX:
155159
{
156160
intptr_t target_addr = (intptr_t) /* S + A - P */
157161
((uintptr_t)symbol_addr + reloc_addend

0 commit comments

Comments
 (0)