TianlongLiang 5 месяцев назад
Родитель
Сommit
d95b0e3d46
2 измененных файлов с 20 добавлено и 10 удалено
  1. 9 3
      core/iwasm/aot/aot_loader.c
  2. 11 7
      core/iwasm/aot/arch/aot_reloc_x86_64.c

+ 9 - 3
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 =

+ 11 - 7
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