Fix some relocation type issues in windows (#574)

Implement Windows PE file relocation type IMAGE_REL_AMD64_ADDR64/ADDR32/REL32, implement relocation for symbol "__xmm@xxx"/"__plt@xxx"/".rdata", implement Windows invokeNative simd asm code and enable SIMD by default for windows platform. Also update wamrc tool.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Wenyong Huang
2021-03-16 03:59:16 -05:00
committed by GitHub
parent afa1feb1a8
commit fda3a26903
7 changed files with 385 additions and 30 deletions

View File

@ -5,16 +5,20 @@
#include "aot_reloc.h"
#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_32 10 /* Direct 32 bit zero extended */
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
#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_32 10 /* Direct 32 bit zero extended */
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
#else
#define IMAGE_REL_AMD64_ADDR64 1 /* The 64-bit VA of the relocation target */
#define IMAGE_REL_AMD64_ADDR32 2 /* The 32-bit VA of the relocation target */
#define IMAGE_REL_AMD64_REL32 4 /* The 32-bit relative address from
the byte following the relocation*/
#endif
#define IMAGE_REL_AMD64_REL32 4 /* The 32-bit relative address from
the byte following the relocation */
#if defined(_WIN64) || defined(_WIN64_)
#if defined(BH_PLATFORM_WINDOWS)
#pragma function (floor)
#pragma function (ceil)
#pragma function (floorf)
@ -98,7 +102,11 @@ apply_relocation(AOTModule *module,
char *error_buf, uint32 error_buf_size)
{
switch (reloc_type) {
#if !defined(BH_PLATFORM_WINDOWS)
case R_X86_64_64:
#else
case IMAGE_REL_AMD64_ADDR64:
#endif
{
intptr_t value;
@ -108,6 +116,29 @@ apply_relocation(AOTModule *module,
= (uint8*)symbol_addr + reloc_addend + value; /* S + A */
break;
}
#if defined(BH_PLATFORM_WINDOWS)
case IMAGE_REL_AMD64_ADDR32:
{
int32 value;
uintptr_t target_addr;
CHECK_RELOC_OFFSET(sizeof(void *));
value = *(int32*)(target_section_addr + (uint32)reloc_offset);
target_addr = (uintptr_t)symbol_addr + reloc_addend + value;
if ((int32)target_addr != target_addr) {
set_error_buf(
error_buf, error_buf_size,
"AOT module load failed: "
"relocation truncated to fit IMAGE_REL_AMD64_ADDR32 failed. "
"Try using wamrc with --size-level=1 option.");
return false;
}
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
break;
}
#endif
#if !defined(BH_PLATFORM_WINDOWS)
case R_X86_64_PC32:
{
intptr_t target_addr = (intptr_t) /* S + A - P */
@ -152,7 +183,12 @@ apply_relocation(AOTModule *module,
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
break;
}
#endif
#if !defined(BH_PLATFORM_WINDOWS)
case R_X86_64_PLT32:
#else
case IMAGE_REL_AMD64_REL32:
#endif
{
uint8 *plt;
intptr_t target_addr = 0;
@ -172,16 +208,21 @@ apply_relocation(AOTModule *module,
- (target_section_addr + reloc_offset));
}
#if defined(BH_PLATFORM_WINDOWS)
target_addr -= sizeof(int32);
#endif
if ((int32)target_addr != target_addr) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"relocation truncated to fit R_X86_64_PC32 failed. "
"relocation truncated to fit "
#if !defined(BH_PLATFORM_WINDOWS)
"R_X86_64_PLT32 failed. "
#else
"IMAGE_REL_AMD64_32 failed."
#endif
"Try using wamrc with --size-level=1 option.");
return false;
}
#ifdef BH_PLATFORM_WINDOWS
target_addr -= sizeof(int32);
#endif
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
break;
}