Apply clang-format for more src files and update spec test script (#775)
Apply clang-format for core/iwasm/include, core/iwasm/common and core/iwasm/aot files. Update spec cases test script: - Checkout latest commit of https://github.com/WebAssembly/spec - Checkout main branch but not master of https://github.com/WebAssembly/threads - Update wabt to latest version And update source debugging document. Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
@ -5,37 +5,39 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_AARCH64_MOVW_UABS_G0 263
|
||||
#define R_AARCH64_MOVW_UABS_G0_NC 264
|
||||
#define R_AARCH64_MOVW_UABS_G1 265
|
||||
#define R_AARCH64_MOVW_UABS_G1_NC 266
|
||||
#define R_AARCH64_MOVW_UABS_G2 267
|
||||
#define R_AARCH64_MOVW_UABS_G2_NC 268
|
||||
#define R_AARCH64_MOVW_UABS_G3 269
|
||||
#define R_AARCH64_MOVW_UABS_G0 263
|
||||
#define R_AARCH64_MOVW_UABS_G0_NC 264
|
||||
#define R_AARCH64_MOVW_UABS_G1 265
|
||||
#define R_AARCH64_MOVW_UABS_G1_NC 266
|
||||
#define R_AARCH64_MOVW_UABS_G2 267
|
||||
#define R_AARCH64_MOVW_UABS_G2_NC 268
|
||||
#define R_AARCH64_MOVW_UABS_G3 269
|
||||
|
||||
#define R_AARCH64_MOVW_SABS_G0 270
|
||||
#define R_AARCH64_MOVW_SABS_G1 271
|
||||
#define R_AARCH64_MOVW_SABS_G2 272
|
||||
#define R_AARCH64_MOVW_SABS_G0 270
|
||||
#define R_AARCH64_MOVW_SABS_G1 271
|
||||
#define R_AARCH64_MOVW_SABS_G2 272
|
||||
|
||||
#define R_AARCH64_ADR_PREL_LO19 273
|
||||
#define R_AARCH64_ADR_PREL_LO21 274
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21 275
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21_NC 276
|
||||
#define R_AARCH64_ADR_PREL_LO19 273
|
||||
#define R_AARCH64_ADR_PREL_LO21 274
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21 275
|
||||
#define R_AARCH64_ADR_PREL_PG_HI21_NC 276
|
||||
|
||||
#define R_AARCH64_ADD_ABS_LO12_NC 277
|
||||
#define R_AARCH64_ADD_ABS_LO12_NC 277
|
||||
|
||||
#define R_AARCH64_LDST8_ABS_LO12_NC 278
|
||||
#define R_AARCH64_LDST16_ABS_LO12_NC 284
|
||||
#define R_AARCH64_LDST32_ABS_LO12_NC 285
|
||||
#define R_AARCH64_LDST64_ABS_LO12_NC 286
|
||||
#define R_AARCH64_LDST128_ABS_LO12_NC 299
|
||||
#define R_AARCH64_LDST8_ABS_LO12_NC 278
|
||||
#define R_AARCH64_LDST16_ABS_LO12_NC 284
|
||||
#define R_AARCH64_LDST32_ABS_LO12_NC 285
|
||||
#define R_AARCH64_LDST64_ABS_LO12_NC 286
|
||||
#define R_AARCH64_LDST128_ABS_LO12_NC 299
|
||||
|
||||
#define R_AARCH64_JUMP26 282
|
||||
#define R_AARCH64_CALL26 283
|
||||
#define R_AARCH64_JUMP26 282
|
||||
#define R_AARCH64_CALL26 283
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -55,7 +57,7 @@ get_target_symbol_map(uint32 *sym_num)
|
||||
void
|
||||
get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
{
|
||||
const char * s = BUILD_TARGET;
|
||||
const char *s = BUILD_TARGET;
|
||||
size_t s_size = sizeof(BUILD_TARGET);
|
||||
char *d = target_buf;
|
||||
|
||||
@ -64,14 +66,14 @@ get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
s = BUILD_TARGET_AARCH64_DEFAULT;
|
||||
s_size = sizeof(BUILD_TARGET_AARCH64_DEFAULT);
|
||||
}
|
||||
if(target_buf_size < s_size){
|
||||
if (target_buf_size < s_size) {
|
||||
s_size = target_buf_size;
|
||||
}
|
||||
while (--s_size) {
|
||||
if (*s >= 'A' && *s <= 'Z')
|
||||
*d++ = *s++ + 'a' - 'A';
|
||||
else
|
||||
*d++ = *s++ ;
|
||||
*d++ = *s++;
|
||||
}
|
||||
/* Ensure the string is null byte ('\0') terminated */
|
||||
*d = '\0';
|
||||
@ -90,15 +92,16 @@ init_plt_table(uint8 *plt)
|
||||
{
|
||||
uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap);
|
||||
for (i = 0; i < num; i++) {
|
||||
uint32 *p = (uint32*)plt;
|
||||
uint32 *p = (uint32 *)plt;
|
||||
*p++ = 0xf81f0ffe; /* str x30, [sp, #-16]! */
|
||||
*p++ = 0x100000be; /* adr x30, #20 ;symbol addr is PC + 5 instructions below */
|
||||
*p++ = 0x100000be; /* adr x30, #20; symbol addr is PC + 5 instructions
|
||||
below */
|
||||
*p++ = 0xf94003de; /* ldr x30, [x30] */
|
||||
*p++ = 0xd63f03c0; /* blr x30 */
|
||||
*p++ = 0xf84107fe; /* ldr x30, [sp], #16 */
|
||||
*p++ = 0xd61f03c0; /* br x30 */
|
||||
/* symbol addr */
|
||||
*(uint64*)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
*(uint64 *)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
p += 2;
|
||||
plt += get_plt_item_size();
|
||||
}
|
||||
@ -110,17 +113,18 @@ get_plt_table_size()
|
||||
return get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
}
|
||||
|
||||
#define SIGN_EXTEND_TO_INT64(val, bits, val_ext) do { \
|
||||
int64 m = (int64)((uint64)1 << (bits - 1)); \
|
||||
val_ext = ((int64)val ^ m) - m; \
|
||||
} while (0)
|
||||
#define SIGN_EXTEND_TO_INT64(val, bits, val_ext) \
|
||||
do { \
|
||||
int64 m = (int64)((uint64)1 << (bits - 1)); \
|
||||
val_ext = ((int64)val ^ m) - m; \
|
||||
} while (0)
|
||||
|
||||
#define Page(expr) ((expr) & ~0xFFF)
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -132,22 +136,21 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_CALL26:
|
||||
{
|
||||
void *S, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S, *P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm26;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm26 = insn & 0x3FFFFFF;
|
||||
SIGN_EXTEND_TO_INT64(imm26 << 2, 28, initial_addend);
|
||||
A = initial_addend;
|
||||
@ -164,17 +167,18 @@ apply_relocation(AOTModule *module,
|
||||
else {
|
||||
uint8 *plt;
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
}
|
||||
/* Symbol address is not an AOT function,
|
||||
* but a function of runtime or native. Its address is
|
||||
* beyond of the +-128MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
S = plt = (uint8*)module->code + module->code_size
|
||||
S = plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
}
|
||||
@ -191,7 +195,7 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
|
||||
/* write the imm26 back to instruction */
|
||||
*(int32*)P = (insn & 0xFC000000) | ((int32)((X >> 2) & 0x3FFFFFF));
|
||||
*(int32 *)P = (insn & 0xFC000000) | ((int32)((X >> 2) & 0x3FFFFFF));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -203,13 +207,14 @@ apply_relocation(AOTModule *module,
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm16;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm16 = (insn >> 5) & 0xFFFF;
|
||||
|
||||
SIGN_EXTEND_TO_INT64(imm16, 16, initial_addend);
|
||||
@ -241,18 +246,22 @@ apply_relocation(AOTModule *module,
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_MOVW_UABS_G0:
|
||||
case R_AARCH64_MOVW_UABS_G0_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)((X & 0xFFFF) << 5));
|
||||
*(int32 *)P =
|
||||
(insn & 0xFFE0001F) | ((int32)((X & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G1:
|
||||
case R_AARCH64_MOVW_UABS_G1_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 16) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 16) & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G2:
|
||||
case R_AARCH64_MOVW_UABS_G2_NC:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 32) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 32) & 0xFFFF) << 5));
|
||||
break;
|
||||
case R_AARCH64_MOVW_UABS_G3:
|
||||
*(int32*)P = (insn & 0xFFE0001F) | ((int32)(((X >> 48) & 0xFFFF) << 5));
|
||||
*(int32 *)P = (insn & 0xFFE0001F)
|
||||
| ((int32)(((X >> 48) & 0xFFFF) << 5));
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
@ -264,13 +273,14 @@ apply_relocation(AOTModule *module,
|
||||
case R_AARCH64_ADR_PREL_PG_HI21:
|
||||
case R_AARCH64_ADR_PREL_PG_HI21_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, immhi19, immlo2, imm21;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
immhi19 = (insn >> 5) & 0x7FFFF;
|
||||
immlo2 = (insn >> 29) & 0x3;
|
||||
imm21 = (immhi19 << 2) | immlo2;
|
||||
@ -290,20 +300,21 @@ apply_relocation(AOTModule *module,
|
||||
/* write the imm21 back to instruction */
|
||||
immhi19 = (int32)(((X >> 12) >> 2) & 0x7FFFF);
|
||||
immlo2 = (int32)((X >> 12) & 0x3);
|
||||
*(int32*)P = (insn & 0x9F00001F) | (immlo2 << 29) | (immhi19 << 5);
|
||||
*(int32 *)P = (insn & 0x9F00001F) | (immlo2 << 29) | (immhi19 << 5);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case R_AARCH64_ADD_ABS_LO12_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm12;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm12 = (insn >> 10) & 0xFFF;
|
||||
|
||||
SIGN_EXTEND_TO_INT64(imm12, 12, initial_addend);
|
||||
@ -316,7 +327,7 @@ apply_relocation(AOTModule *module,
|
||||
/* No need to check overflow for this reloction type */
|
||||
|
||||
/* write the imm12 back to instruction */
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -326,13 +337,14 @@ apply_relocation(AOTModule *module,
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
{
|
||||
void *S = symbol_addr, *P = (void*)(target_section_addr + reloc_offset);
|
||||
void *S = symbol_addr,
|
||||
*P = (void *)(target_section_addr + reloc_offset);
|
||||
int64 X, A, initial_addend;
|
||||
int32 insn, imm12;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
insn = *(int32*)P;
|
||||
insn = *(int32 *)P;
|
||||
imm12 = (insn >> 10) & 0xFFF;
|
||||
|
||||
SIGN_EXTEND_TO_INT64(imm12, 12, initial_addend);
|
||||
@ -347,19 +359,24 @@ apply_relocation(AOTModule *module,
|
||||
/* write the imm12 back to instruction */
|
||||
switch (reloc_type) {
|
||||
case R_AARCH64_LDST8_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
*(int32 *)P =
|
||||
(insn & 0xFFC003FF) | ((int32)((X & 0xFFF) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST16_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 1) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 1) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST32_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 2) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 2) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST64_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 3) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 3) << 10));
|
||||
break;
|
||||
case R_AARCH64_LDST128_ABS_LO12_NC:
|
||||
*(int32*)P = (insn & 0xFFC003FF) | ((int32)(((X & 0xFFF) >> 4) << 10));
|
||||
*(int32 *)P = (insn & 0xFFC003FF)
|
||||
| ((int32)(((X & 0xFFF) >> 4) << 10));
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
|
||||
@ -5,13 +5,14 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_ARC_S21H_PCREL 14
|
||||
#define R_ARC_S21W_PCREL 15
|
||||
#define R_ARC_S25H_PCREL 16
|
||||
#define R_ARC_S25W_PCREL 17
|
||||
#define R_ARC_32 4
|
||||
#define R_ARC_32_ME 27
|
||||
#define R_ARC_S21H_PCREL 14
|
||||
#define R_ARC_S21W_PCREL 15
|
||||
#define R_ARC_S25H_PCREL 16
|
||||
#define R_ARC_S25W_PCREL 17
|
||||
#define R_ARC_32 4
|
||||
#define R_ARC_32_ME 27
|
||||
|
||||
/* clang-format off */
|
||||
void __st_r13_to_r15();
|
||||
void __st_r13_to_r16();
|
||||
void __st_r13_to_r17();
|
||||
@ -56,10 +57,13 @@ void __subdf3();
|
||||
void __subsf3();
|
||||
void __truncdfsf2();
|
||||
void __unorddf2();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
REG_SYM(__st_r13_to_r15),
|
||||
/* clang-format on */
|
||||
REG_SYM(__st_r13_to_r16),
|
||||
REG_SYM(__st_r13_to_r17),
|
||||
REG_SYM(__st_r13_to_r18),
|
||||
@ -81,29 +85,28 @@ static SymbolMap target_sym_map[] = {
|
||||
REG_SYM(__ld_r13_to_r23),
|
||||
REG_SYM(__ld_r13_to_r24),
|
||||
REG_SYM(__ld_r13_to_r25),
|
||||
REG_SYM (__adddf3),
|
||||
REG_SYM (__addsf3),
|
||||
REG_SYM (__divdf3),
|
||||
REG_SYM (__divdi3),
|
||||
REG_SYM (__divsf3),
|
||||
REG_SYM (__divsi3),
|
||||
REG_SYM (__eqsf2),
|
||||
REG_SYM (__extendsfdf2),
|
||||
REG_SYM (__fixdfsi),
|
||||
REG_SYM (__floatsidf),
|
||||
REG_SYM (__floatsisf),
|
||||
REG_SYM (__gedf2),
|
||||
REG_SYM (__gtdf2),
|
||||
REG_SYM (__ledf2),
|
||||
REG_SYM (__lesf2),
|
||||
REG_SYM (__ltdf2),
|
||||
REG_SYM (__muldf3),
|
||||
REG_SYM (__mulsf3),
|
||||
REG_SYM (__subdf3),
|
||||
REG_SYM (__subsf3),
|
||||
REG_SYM (__truncdfsf2),
|
||||
REG_SYM (__unorddf2),
|
||||
|
||||
REG_SYM(__adddf3),
|
||||
REG_SYM(__addsf3),
|
||||
REG_SYM(__divdf3),
|
||||
REG_SYM(__divdi3),
|
||||
REG_SYM(__divsf3),
|
||||
REG_SYM(__divsi3),
|
||||
REG_SYM(__eqsf2),
|
||||
REG_SYM(__extendsfdf2),
|
||||
REG_SYM(__fixdfsi),
|
||||
REG_SYM(__floatsidf),
|
||||
REG_SYM(__floatsisf),
|
||||
REG_SYM(__gedf2),
|
||||
REG_SYM(__gtdf2),
|
||||
REG_SYM(__ledf2),
|
||||
REG_SYM(__lesf2),
|
||||
REG_SYM(__ltdf2),
|
||||
REG_SYM(__muldf3),
|
||||
REG_SYM(__mulsf3),
|
||||
REG_SYM(__subdf3),
|
||||
REG_SYM(__subsf3),
|
||||
REG_SYM(__truncdfsf2),
|
||||
REG_SYM(__unorddf2),
|
||||
};
|
||||
|
||||
static void
|
||||
@ -139,9 +142,9 @@ init_plt_table(uint8 *plt)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -159,11 +162,10 @@ middle_endian_convert(uint32 insn)
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARC_S25W_PCREL:
|
||||
@ -172,7 +174,7 @@ apply_relocation(AOTModule *module,
|
||||
int32 addend, value;
|
||||
uintptr_t S, A, P;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
|
||||
/* Convert from middle endian */
|
||||
insn = middle_endian_convert(insn);
|
||||
@ -187,7 +189,7 @@ apply_relocation(AOTModule *module,
|
||||
addend = addend << 2;
|
||||
|
||||
/* (S + A) - P */
|
||||
S = (uintptr_t)(uint8*)symbol_addr;
|
||||
S = (uintptr_t)(uint8 *)symbol_addr;
|
||||
A = (uintptr_t)reloc_addend;
|
||||
P = (uintptr_t)(target_section_addr + reloc_offset);
|
||||
P &= (uintptr_t)~3;
|
||||
@ -209,11 +211,10 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
uint32 insn;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
|
||||
/* (S + A) */
|
||||
insn = (uint32)(uintptr_t)
|
||||
((uint8*)symbol_addr + reloc_addend);
|
||||
insn = (uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
if (reloc_type == R_ARC_32_ME)
|
||||
/* Convert to middle endian */
|
||||
@ -234,4 +235,3 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,10 +5,11 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_ARM_CALL 28 /* PC relative 24 bit (BL, BLX). */
|
||||
#define R_ARM_JMP24 29 /* PC relative 24 bit (B/BL<cond>). */
|
||||
#define R_ARM_ABS32 2 /* Direct 32 bit */
|
||||
#define R_ARM_CALL 28 /* PC relative 24 bit (BL, BLX). */
|
||||
#define R_ARM_JMP24 29 /* PC relative 24 bit (B/BL<cond>). */
|
||||
#define R_ARM_ABS32 2 /* Direct 32 bit */
|
||||
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __udivdi3();
|
||||
void __moddi3();
|
||||
@ -54,11 +55,14 @@ void __aeabi_fcmple();
|
||||
void __aeabi_fcmpge();
|
||||
void __aeabi_f2iz();
|
||||
void __aeabi_f2d();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
REG_SYM(__divdi3),
|
||||
/* clang-format on */
|
||||
REG_SYM(__udivdi3),
|
||||
REG_SYM(__umoddi3),
|
||||
REG_SYM(__divsi3),
|
||||
@ -122,7 +126,7 @@ get_target_symbol_map(uint32 *sym_num)
|
||||
void
|
||||
get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
{
|
||||
const char * s = BUILD_TARGET;
|
||||
const char *s = BUILD_TARGET;
|
||||
size_t s_size = sizeof(BUILD_TARGET);
|
||||
char *d = target_buf;
|
||||
|
||||
@ -131,14 +135,14 @@ get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
s = BUILD_TARGET_ARM_DEFAULT;
|
||||
s_size = sizeof(BUILD_TARGET_ARM_DEFAULT);
|
||||
}
|
||||
if(target_buf_size < s_size){
|
||||
if (target_buf_size < s_size) {
|
||||
s_size = target_buf_size;
|
||||
}
|
||||
while (--s_size) {
|
||||
if (*s >= 'A' && *s <= 'Z')
|
||||
*d++ = *s++ + 'a' - 'A';
|
||||
else
|
||||
*d++ = *s++ ;
|
||||
*d++ = *s++;
|
||||
}
|
||||
/* Ensure the string is null byte ('\0') terminated */
|
||||
*d = '\0';
|
||||
@ -163,7 +167,7 @@ init_plt_table(uint8 *plt)
|
||||
{
|
||||
uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap);
|
||||
for (i = 0; i < num; i++) {
|
||||
uint32 *p = (uint32*)plt;
|
||||
uint32 *p = (uint32 *)plt;
|
||||
/* ldr pc, [pc] */
|
||||
*p++ = 0xe59ff000;
|
||||
/* nop */
|
||||
@ -175,9 +179,9 @@ init_plt_table(uint8 *plt)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -189,11 +193,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_CALL:
|
||||
@ -201,10 +204,10 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
intptr_t result;
|
||||
int32 RESULT_MASK = 0x03FFFFFE;
|
||||
int32 insn = *(int32*)(target_section_addr + reloc_offset);
|
||||
int32 insn = *(int32 *)(target_section_addr + reloc_offset);
|
||||
/* Initial addend: sign_extend(insn[23:0] << 2) */
|
||||
int32 initial_addend = ((insn & 0xFFFFFF) << 2)
|
||||
| ((insn & 0x800000) ? 0xFC000000 : 0);
|
||||
int32 initial_addend =
|
||||
((insn & 0xFFFFFF) << 2) | ((insn & 0x800000) ? 0xFC000000 : 0);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
@ -214,17 +217,18 @@ apply_relocation(AOTModule *module,
|
||||
* Suppose the symbol address is in +-32MB relative
|
||||
* to the relocation address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T is 0 */
|
||||
result = (intptr_t)
|
||||
((uint8*)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T
|
||||
* is 0 */
|
||||
result = (intptr_t)((uint8 *)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Symbol address is not an AOT function,
|
||||
@ -232,12 +236,13 @@ apply_relocation(AOTModule *module,
|
||||
* beyond of the +-32MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is 0 */
|
||||
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is
|
||||
* 0 */
|
||||
uint8 *plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
result = (intptr_t)
|
||||
(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
result = (intptr_t)(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
result += initial_addend;
|
||||
@ -250,20 +255,20 @@ apply_relocation(AOTModule *module,
|
||||
return false;
|
||||
}
|
||||
|
||||
*(int32*)(target_section_addr + reloc_offset) =
|
||||
(int32)
|
||||
((insn & 0xff000000)
|
||||
| (((int32)result & RESULT_MASK) >> 2));
|
||||
*(int32 *)(target_section_addr + reloc_offset) =
|
||||
(int32)((insn & 0xff000000)
|
||||
| (((int32)result & RESULT_MASK) >> 2));
|
||||
break;
|
||||
}
|
||||
case R_ARM_ABS32:
|
||||
{
|
||||
intptr_t initial_addend;
|
||||
/* (S + A) | T where T is 0 */
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
initial_addend = *(intptr_t*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + initial_addend + reloc_addend;
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
initial_addend =
|
||||
*(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + initial_addend + reloc_addend;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -278,4 +283,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,12 +5,14 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_MIPS_32 2 /* Direct 32 bit */
|
||||
#define R_MIPS_26 4 /* Direct 26 bit shifted */
|
||||
#define R_MIPS_32 2 /* Direct 32 bit */
|
||||
#define R_MIPS_26 4 /* Direct 26 bit shifted */
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
SymbolMap *
|
||||
get_target_symbol_map(uint32 *sym_num)
|
||||
@ -44,11 +46,10 @@ get_plt_table_size()
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
/* TODO: implement relocation for mips */
|
||||
@ -66,4 +67,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,25 +5,29 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_RISCV_32 1
|
||||
#define R_RISCV_64 2
|
||||
#define R_RISCV_CALL 18
|
||||
#define R_RISCV_32 1
|
||||
#define R_RISCV_64 2
|
||||
#define R_RISCV_CALL 18
|
||||
#define R_RISCV_CALL_PLT 19
|
||||
#define R_RISCV_HI20 26
|
||||
#define R_RISCV_LO12_I 27
|
||||
#define R_RISCV_LO12_S 28
|
||||
#define R_RISCV_HI20 26
|
||||
#define R_RISCV_LO12_I 27
|
||||
#define R_RISCV_LO12_S 28
|
||||
|
||||
#define RV_OPCODE_SW 0x23
|
||||
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __moddi3();
|
||||
void __muldi3();
|
||||
void __udivdi3();
|
||||
void __umoddi3();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
REG_SYM(__divdi3),
|
||||
/* clang-format on */
|
||||
REG_SYM(__moddi3),
|
||||
REG_SYM(__muldi3),
|
||||
REG_SYM(__udivdi3),
|
||||
@ -132,20 +136,20 @@ init_plt_table(uint8 *plt)
|
||||
for (i = 0; i < num; i++) {
|
||||
p = plt;
|
||||
/* auipc t1, 0 */
|
||||
*(uint16*)p = 0x0317;
|
||||
*(uint16 *)p = 0x0317;
|
||||
p += 2;
|
||||
*(uint16*)p = 0x0000;
|
||||
*(uint16 *)p = 0x0000;
|
||||
p += 2;
|
||||
/* ld t1, 8(t1) */
|
||||
*(uint16*)p = 0x3303;
|
||||
*(uint16 *)p = 0x3303;
|
||||
p += 2;
|
||||
*(uint16*)p = 0x00C3;
|
||||
*(uint16 *)p = 0x00C3;
|
||||
p += 2;
|
||||
/* jr t1 */
|
||||
*(uint16*)p = 0x8302;
|
||||
*(uint16 *)p = 0x8302;
|
||||
p += 2;
|
||||
/* nop */
|
||||
*(uint16*)p = 0x0001;
|
||||
*(uint16 *)p = 0x0001;
|
||||
p += 2;
|
||||
bh_memcpy_s(p, 8, &target_sym_map[i].symbol_addr, 8);
|
||||
p += 8;
|
||||
@ -159,15 +163,15 @@ typedef struct RelocTypeStrMap {
|
||||
char *reloc_str;
|
||||
} RelocTypeStrMap;
|
||||
|
||||
#define RELOC_TYPE_MAP(reloc_type) { reloc_type, #reloc_type }
|
||||
#define RELOC_TYPE_MAP(reloc_type) \
|
||||
{ \
|
||||
reloc_type, #reloc_type \
|
||||
}
|
||||
|
||||
static RelocTypeStrMap reloc_type_str_maps[] = {
|
||||
RELOC_TYPE_MAP(R_RISCV_32),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL_PLT),
|
||||
RELOC_TYPE_MAP(R_RISCV_HI20),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_I),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_S),
|
||||
RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_CALL),
|
||||
RELOC_TYPE_MAP(R_RISCV_CALL_PLT), RELOC_TYPE_MAP(R_RISCV_HI20),
|
||||
RELOC_TYPE_MAP(R_RISCV_LO12_I), RELOC_TYPE_MAP(R_RISCV_LO12_S),
|
||||
};
|
||||
|
||||
static const char *
|
||||
@ -175,7 +179,8 @@ reloc_type_to_str(uint32 reloc_type)
|
||||
{
|
||||
uint32 i;
|
||||
|
||||
for (i = 0; i < sizeof(reloc_type_str_maps) / sizeof(RelocTypeStrMap); i++) {
|
||||
for (i = 0; i < sizeof(reloc_type_str_maps) / sizeof(RelocTypeStrMap);
|
||||
i++) {
|
||||
if (reloc_type_str_maps[i].reloc_type == reloc_type)
|
||||
return reloc_type_str_maps[i].reloc_str;
|
||||
}
|
||||
@ -184,9 +189,9 @@ reloc_type_to_str(uint32 reloc_type)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -198,11 +203,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend, uint32 reloc_type,
|
||||
void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
int32 val, imm_hi, imm_lo, insn;
|
||||
uint8 *addr = target_section_addr + reloc_offset;
|
||||
@ -211,7 +215,8 @@ apply_relocation(AOTModule *module,
|
||||
switch (reloc_type) {
|
||||
case R_RISCV_32:
|
||||
{
|
||||
uint32 val_32 = (uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
uint32 val_32 =
|
||||
(uint32)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(uint32));
|
||||
if (val_32 != (uintptr_t)((uint8 *)symbol_addr + reloc_addend)) {
|
||||
@ -223,7 +228,8 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
case R_RISCV_64:
|
||||
{
|
||||
uint64 val_64 = (uint64)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
uint64 val_64 =
|
||||
(uint64)(uintptr_t)((uint8 *)symbol_addr + reloc_addend);
|
||||
CHECK_RELOC_OFFSET(sizeof(uint64));
|
||||
bh_memcpy_s(addr, 8, &val_64, 8);
|
||||
break;
|
||||
@ -237,10 +243,10 @@ apply_relocation(AOTModule *module,
|
||||
if (val != (intptr_t)((uint8 *)symbol_addr - addr)) {
|
||||
if (symbol_index >= 0) {
|
||||
/* Call runtime function by plt code */
|
||||
symbol_addr = (uint8*)module->code + module->code_size
|
||||
symbol_addr = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
val = (int32)(intptr_t)((uint8*)symbol_addr - addr);
|
||||
val = (int32)(intptr_t)((uint8 *)symbol_addr - addr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,8 +259,8 @@ apply_relocation(AOTModule *module,
|
||||
rv_add_val((uint16 *)addr, (imm_hi << 12));
|
||||
if ((rv_get_val((uint16 *)(addr + 4)) & 0x7f) == RV_OPCODE_SW) {
|
||||
/* Adjust imm for SW : S-type */
|
||||
val =
|
||||
(((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
val = (((int32)imm_lo >> 5) << 25)
|
||||
+ (((int32)imm_lo & 0x1f) << 7);
|
||||
|
||||
rv_add_val((uint16 *)(addr + 4), val);
|
||||
}
|
||||
@ -310,8 +316,7 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
addr = target_section_addr + reloc_offset;
|
||||
rv_calc_imm(val, &imm_hi, &imm_lo);
|
||||
val =
|
||||
(((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
val = (((int32)imm_lo >> 5) << 25) + (((int32)imm_lo & 0x1f) << 7);
|
||||
rv_add_val((uint16 *)addr, val);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -5,9 +5,10 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_ARM_THM_CALL 10 /* PC relative (Thumb BL and ARMv5 Thumb BLX). */
|
||||
#define R_ARM_THM_JMP24 30 /* B.W */
|
||||
#define R_ARM_THM_CALL 10 /* PC relative (Thumb BL and ARMv5 Thumb BLX). */
|
||||
#define R_ARM_THM_JMP24 30 /* B.W */
|
||||
|
||||
/* clang-format off */
|
||||
void __ltdf2();
|
||||
void __adddf3();
|
||||
void __eqdf2();
|
||||
@ -69,11 +70,14 @@ void __aeabi_fcmple();
|
||||
void __aeabi_fcmpge();
|
||||
void __aeabi_f2iz();
|
||||
void __aeabi_f2d();
|
||||
/* clang-format on */
|
||||
|
||||
static SymbolMap target_sym_map[] = {
|
||||
/* clang-format off */
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
REG_SYM(__ltdf2),
|
||||
/* clang-format on */
|
||||
REG_SYM(__adddf3),
|
||||
REG_SYM(__eqdf2),
|
||||
REG_SYM(__unorddf2),
|
||||
@ -162,14 +166,14 @@ get_current_target(char *target_buf, uint32 target_buf_size)
|
||||
s = BUILD_TARGET_THUMB_V4T;
|
||||
s_size = sizeof(BUILD_TARGET_THUMB_V4T);
|
||||
}
|
||||
if(target_buf_size < s_size){
|
||||
if (target_buf_size < s_size) {
|
||||
s_size = target_buf_size;
|
||||
}
|
||||
while (--s_size) {
|
||||
if (*s >= 'A' && *s <= 'Z')
|
||||
*d++ = *s++ + 'a' - 'A';
|
||||
else
|
||||
*d++ = *s++ ;
|
||||
*d++ = *s++;
|
||||
}
|
||||
/* Ensure the string is null byte ('\0') terminated */
|
||||
*d = '\0';
|
||||
@ -194,7 +198,7 @@ init_plt_table(uint8 *plt)
|
||||
{
|
||||
uint32 i, num = sizeof(target_sym_map) / sizeof(SymbolMap);
|
||||
for (i = 0; i < num; i++) {
|
||||
uint16 *p = (uint16*)plt;
|
||||
uint16 *p = (uint16 *)plt;
|
||||
/* nop */
|
||||
*p++ = 0xbf00;
|
||||
/* push {r4} */
|
||||
@ -212,15 +216,15 @@ init_plt_table(uint8 *plt)
|
||||
/* nop */
|
||||
*p++ = 0xbf00;
|
||||
/* symbol addr */
|
||||
*(uint32*)p = (uint32)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
*(uint32 *)p = (uint32)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
plt += get_plt_item_size();
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -232,11 +236,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_ARM_THM_CALL:
|
||||
@ -250,7 +253,7 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
reloc_addr = (int16*)(target_section_addr + reloc_offset);
|
||||
reloc_addr = (int16 *)(target_section_addr + reloc_offset);
|
||||
initial_addend_0 = (*reloc_addr) & 0x7FF;
|
||||
initial_addend_1 = (*(reloc_addr + 1)) & 0x7FF;
|
||||
sign = (initial_addend_0 & 0x400) ? true : false;
|
||||
@ -263,16 +266,20 @@ apply_relocation(AOTModule *module,
|
||||
* Suppose the symbol address is in +-4MB relative
|
||||
* to the relocation address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is symbol address and T is 1 */
|
||||
result = (int32)(((intptr_t)((uint8*)symbol_addr + reloc_addend) | 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
/* operation: ((S + A) | T) - P where S is symbol address
|
||||
and T is 1 */
|
||||
result =
|
||||
(int32)(((intptr_t)((uint8 *)symbol_addr + reloc_addend)
|
||||
| 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
if (reloc_addend > 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: relocate to plt table "
|
||||
"with reloc addend larger than 0 is unsupported.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Symbol address is not an AOT function,
|
||||
@ -280,11 +287,14 @@ apply_relocation(AOTModule *module,
|
||||
* beyond of the +-4MB space. Apply relocation with
|
||||
* the PLT which branch to the target symbol address.
|
||||
*/
|
||||
/* operation: ((S + A) | T) - P where S is PLT address and T is 1 */
|
||||
uint8 *plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
/* operation: ((S + A) | T) - P where S is PLT address
|
||||
and T is 1 */
|
||||
uint8 *plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index + 1;
|
||||
result = (int32)(((intptr_t)plt | 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
result =
|
||||
(int32)(((intptr_t)plt | 1)
|
||||
- (intptr_t)(target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
result += initial_addend;
|
||||
@ -316,4 +326,3 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,17 +5,19 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_386_32 1 /* Direct 32 bit */
|
||||
#define R_386_PC32 2 /* PC relative 32 bit */
|
||||
#define R_386_32 1 /* Direct 32 bit */
|
||||
#define R_386_PC32 2 /* PC relative 32 bit */
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN32_)
|
||||
/* clang-format off */
|
||||
void __divdi3();
|
||||
void __udivdi3();
|
||||
void __moddi3();
|
||||
void __umoddi3();
|
||||
/* clang-format on */
|
||||
#else
|
||||
#pragma function (floor)
|
||||
#pragma function (ceil)
|
||||
#pragma function(floor)
|
||||
#pragma function(ceil)
|
||||
|
||||
static int64
|
||||
__divdi3(int64 a, int64 b)
|
||||
@ -42,6 +44,7 @@ __umoddi3(uint64 a, uint64 b)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
/* compiler-rt symbols that come from compiler(e.g. gcc) */
|
||||
@ -50,6 +53,7 @@ static SymbolMap target_sym_map[] = {
|
||||
REG_SYM(__moddi3),
|
||||
REG_SYM(__umoddi3)
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -84,9 +88,9 @@ init_plt_table(uint8 *plt)
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -98,21 +102,20 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_386_32:
|
||||
{
|
||||
intptr_t value;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
value = *(intptr_t*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + reloc_addend + value; /* S + A */
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + reloc_addend + value; /* S + A */
|
||||
break;
|
||||
}
|
||||
|
||||
@ -120,12 +123,12 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
int32 value;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
value = *(int32*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint32*)(target_section_addr + (uint32)reloc_offset) = (uint32)
|
||||
((uint8*)symbol_addr + (uint32)reloc_addend
|
||||
- (uint8*)(target_section_addr + (uint32)reloc_offset)
|
||||
+ value); /* S + A - P */
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(int32 *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint32 *)(target_section_addr + (uint32)reloc_offset) =
|
||||
(uint32)((uint8 *)symbol_addr + (uint32)reloc_addend
|
||||
- (uint8 *)(target_section_addr + (uint32)reloc_offset)
|
||||
+ value); /* S + A - P */
|
||||
break;
|
||||
}
|
||||
|
||||
@ -139,4 +142,3 @@ apply_relocation(AOTModule *module,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -6,30 +6,34 @@
|
||||
#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_32 10 /* Direct 32 bit zero extended */
|
||||
#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
|
||||
#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
|
||||
#ifndef IMAGE_REL_AMD64_ADDR64
|
||||
#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 */
|
||||
/* clang-format off */
|
||||
#define IMAGE_REL_AMD64_REL32 4 /* The 32-bit relative address from
|
||||
the byte following the relocation*/
|
||||
/* clang-format on */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
#pragma function (floor)
|
||||
#pragma function (ceil)
|
||||
#pragma function (floorf)
|
||||
#pragma function (ceilf)
|
||||
#pragma function(floor)
|
||||
#pragma function(ceil)
|
||||
#pragma function(floorf)
|
||||
#pragma function(ceilf)
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
static SymbolMap target_sym_map[] = {
|
||||
REG_COMMON_SYMBOLS
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -61,8 +65,8 @@ get_plt_item_size()
|
||||
uint32
|
||||
get_plt_table_size()
|
||||
{
|
||||
uint32 size = get_plt_item_size()
|
||||
* (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
uint32 size =
|
||||
get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap));
|
||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
|
||||
size += get_plt_item_size() + sizeof(AOTUnwindInfo);
|
||||
#endif
|
||||
@ -80,7 +84,7 @@ init_plt_table(uint8 *plt)
|
||||
/* mov symbol_addr, rax */
|
||||
*p++ = 0x48;
|
||||
*p++ = 0xB8;
|
||||
*(uint64*)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
*(uint64 *)p = (uint64)(uintptr_t)target_sym_map[i].symbol_addr;
|
||||
p += sizeof(uint64);
|
||||
/* jmp rax */
|
||||
*p++ = 0xFF;
|
||||
@ -92,19 +96,19 @@ init_plt_table(uint8 *plt)
|
||||
p = plt;
|
||||
/* mov exception_handler, rax */
|
||||
*p++ = 0x48;
|
||||
*p++ = 0xB8;
|
||||
*(uint64*)p = 0;/*(uint64)(uintptr_t)aot_exception_handler;*/
|
||||
*p++ = 0xB8;
|
||||
*(uint64 *)p = 0; /*(uint64)(uintptr_t)aot_exception_handler;*/
|
||||
p += sizeof(uint64);
|
||||
/* jmp rax */
|
||||
*p++ = 0xFF;
|
||||
*p++ = 0xE0;
|
||||
*p++ = 0xFF;
|
||||
*p++ = 0xE0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -116,11 +120,10 @@ check_reloc_offset(uint32 target_section_size,
|
||||
}
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
#if !defined(BH_PLATFORM_WINDOWS)
|
||||
@ -131,10 +134,10 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
intptr_t value;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void*));
|
||||
value = *(intptr_t*)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8**)(target_section_addr + reloc_offset)
|
||||
= (uint8*)symbol_addr + reloc_addend + value; /* S + A */
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(intptr_t *)(target_section_addr + (uint32)reloc_offset);
|
||||
*(uint8 **)(target_section_addr + reloc_offset) =
|
||||
(uint8 *)symbol_addr + reloc_addend + value; /* S + A */
|
||||
break;
|
||||
}
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
@ -144,14 +147,14 @@ apply_relocation(AOTModule *module,
|
||||
uintptr_t target_addr;
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(void *));
|
||||
value = *(int32*)(target_section_addr + (uint32)reloc_offset);
|
||||
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.");
|
||||
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;
|
||||
}
|
||||
|
||||
@ -162,20 +165,21 @@ apply_relocation(AOTModule *module,
|
||||
#if !defined(BH_PLATFORM_WINDOWS)
|
||||
case R_X86_64_PC32:
|
||||
{
|
||||
intptr_t target_addr = (intptr_t) /* S + A - P */
|
||||
((uint8*)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
intptr_t target_addr = (intptr_t) /* S + A - P */
|
||||
((uint8 *)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
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. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
set_error_buf(
|
||||
error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit R_X86_64_PC32 failed. "
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
return false;
|
||||
}
|
||||
|
||||
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
break;
|
||||
}
|
||||
case R_X86_64_32:
|
||||
@ -183,7 +187,7 @@ apply_relocation(AOTModule *module,
|
||||
{
|
||||
char buf[128];
|
||||
uintptr_t target_addr = (uintptr_t) /* S + A */
|
||||
((uint8*)symbol_addr + reloc_addend);
|
||||
((uint8 *)symbol_addr + reloc_addend);
|
||||
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
@ -192,16 +196,16 @@ apply_relocation(AOTModule *module,
|
||||
|| (reloc_type == R_X86_64_32S
|
||||
&& (int32)target_addr != (int64)target_addr)) {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit %s failed. "
|
||||
"Try using wamrc with --size-level=1 option.",
|
||||
reloc_type == R_X86_64_32
|
||||
? "R_X86_64_32" : "R_X86_64_32S");
|
||||
"AOT module load failed: "
|
||||
"relocation truncated to fit %s failed. "
|
||||
"Try using wamrc with --size-level=1 option.",
|
||||
reloc_type == R_X86_64_32 ? "R_X86_64_32"
|
||||
: "R_X86_64_32S");
|
||||
set_error_buf(error_buf, error_buf_size, buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@ -217,16 +221,16 @@ apply_relocation(AOTModule *module,
|
||||
CHECK_RELOC_OFFSET(sizeof(int32));
|
||||
|
||||
if (symbol_index >= 0) {
|
||||
plt = (uint8*)module->code + module->code_size - get_plt_table_size()
|
||||
plt = (uint8 *)module->code + module->code_size
|
||||
- get_plt_table_size()
|
||||
+ get_plt_item_size() * symbol_index;
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
(plt + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
(plt + reloc_addend - (target_section_addr + reloc_offset));
|
||||
}
|
||||
else {
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
((uint8*)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
target_addr = (intptr_t) /* L + A - P */
|
||||
((uint8 *)symbol_addr + reloc_addend
|
||||
- (target_section_addr + reloc_offset));
|
||||
}
|
||||
|
||||
#if defined(BH_PLATFORM_WINDOWS)
|
||||
@ -244,7 +248,7 @@ apply_relocation(AOTModule *module,
|
||||
"Try using wamrc with --size-level=1 option.");
|
||||
return false;
|
||||
}
|
||||
*(int32*)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
*(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -259,4 +263,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,10 @@
|
||||
|
||||
#include "aot_reloc.h"
|
||||
|
||||
#define R_XTENSA_32 1 /* Direct 32 bit */
|
||||
#define R_XTENSA_SLOT0_OP 20 /* PC relative */
|
||||
#define R_XTENSA_32 1 /* Direct 32 bit */
|
||||
#define R_XTENSA_SLOT0_OP 20 /* PC relative */
|
||||
|
||||
/* clang-format off */
|
||||
/* for soft-float */
|
||||
void __floatsidf();
|
||||
void __divdf3();
|
||||
@ -38,9 +39,9 @@ static SymbolMap target_sym_map[] = {
|
||||
REG_SYM(__muldi3),
|
||||
|
||||
REG_SYM(__modsi3),
|
||||
|
||||
REG_SYM(__divdi3),
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static void
|
||||
set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
@ -81,9 +82,9 @@ get_plt_table_size()
|
||||
}
|
||||
|
||||
static bool
|
||||
check_reloc_offset(uint32 target_section_size,
|
||||
uint64 reloc_offset, uint32 reloc_data_size,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
check_reloc_offset(uint32 target_section_size, uint64 reloc_offset,
|
||||
uint32 reloc_data_size, char *error_buf,
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
if (!(reloc_offset < (uint64)target_section_size
|
||||
&& reloc_offset + reloc_data_size <= (uint64)target_section_size)) {
|
||||
@ -106,18 +107,18 @@ put_imm16_to_addr(int16 imm16, int16 *addr)
|
||||
int8 bytes[8];
|
||||
int32 *addr_aligned1, *addr_aligned2;
|
||||
|
||||
addr_aligned1 = (int32*)((intptr_t)addr & ~3);
|
||||
addr_aligned1 = (int32 *)((intptr_t)addr & ~3);
|
||||
|
||||
if ((intptr_t)addr % 4 != 3) {
|
||||
*(int32*)bytes = *addr_aligned1;
|
||||
*(int16*)(bytes + ((intptr_t)addr % 4)) = imm16;
|
||||
*(int32 *)bytes = *addr_aligned1;
|
||||
*(int16 *)(bytes + ((intptr_t)addr % 4)) = imm16;
|
||||
memcpy(addr_aligned1, bytes, 4);
|
||||
}
|
||||
else {
|
||||
addr_aligned2 = (int32*)(((intptr_t)addr + 3) & ~3);
|
||||
*(int32*)bytes = *addr_aligned1;
|
||||
*(int32*)(bytes + 4) = *addr_aligned2;
|
||||
*(int16*)(bytes + 3) = imm16;
|
||||
addr_aligned2 = (int32 *)(((intptr_t)addr + 3) & ~3);
|
||||
*(int32 *)bytes = *addr_aligned1;
|
||||
*(int32 *)(bytes + 4) = *addr_aligned2;
|
||||
*(int16 *)(bytes + 3) = imm16;
|
||||
memcpy(addr_aligned1, bytes, 8);
|
||||
}
|
||||
}
|
||||
@ -142,11 +143,10 @@ typedef union {
|
||||
} l32r_insn_t;
|
||||
|
||||
bool
|
||||
apply_relocation(AOTModule *module,
|
||||
uint8 *target_section_addr, uint32 target_section_size,
|
||||
uint64 reloc_offset, uint64 reloc_addend,
|
||||
uint32 reloc_type, void *symbol_addr, int32 symbol_index,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
apply_relocation(AOTModule *module, uint8 *target_section_addr,
|
||||
uint32 target_section_size, uint64 reloc_offset,
|
||||
uint64 reloc_addend, uint32 reloc_type, void *symbol_addr,
|
||||
int32 symbol_index, char *error_buf, uint32 error_buf_size)
|
||||
{
|
||||
switch (reloc_type) {
|
||||
case R_XTENSA_32:
|
||||
@ -161,19 +161,20 @@ apply_relocation(AOTModule *module,
|
||||
return false;
|
||||
}
|
||||
CHECK_RELOC_OFFSET(4);
|
||||
initial_addend = *(int32*)insn_addr;
|
||||
*(uint8**)insn_addr
|
||||
= (uint8*)symbol_addr + initial_addend + reloc_addend;
|
||||
initial_addend = *(int32 *)insn_addr;
|
||||
*(uint8 **)insn_addr =
|
||||
(uint8 *)symbol_addr + initial_addend + reloc_addend;
|
||||
break;
|
||||
}
|
||||
|
||||
case R_XTENSA_SLOT0_OP:
|
||||
{
|
||||
uint8 *insn_addr = target_section_addr + reloc_offset;
|
||||
/* Currently only l32r instruction generates R_XTENSA_SLOT0_OP relocation */
|
||||
/* Currently only l32r instruction generates R_XTENSA_SLOT0_OP
|
||||
* relocation */
|
||||
l32r_insn_t *l32r_insn = (l32r_insn_t *)insn_addr;
|
||||
uint8 *reloc_addr;
|
||||
int32 relative_offset/*, initial_addend */;
|
||||
int32 relative_offset /*, initial_addend */;
|
||||
int16 imm16;
|
||||
|
||||
CHECK_RELOC_OFFSET(3); /* size of l32r instruction */
|
||||
@ -184,7 +185,7 @@ apply_relocation(AOTModule *module,
|
||||
initial_addend = (int32)imm16 << 2;
|
||||
*/
|
||||
|
||||
reloc_addr = (uint8*)symbol_addr + reloc_addend;
|
||||
reloc_addr = (uint8 *)symbol_addr + reloc_addend;
|
||||
|
||||
if ((intptr_t)reloc_addr & 3) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
@ -193,9 +194,9 @@ apply_relocation(AOTModule *module,
|
||||
return false;
|
||||
}
|
||||
|
||||
relative_offset = (int32)
|
||||
((intptr_t)reloc_addr -
|
||||
(((intptr_t)insn_addr + 3) & ~(intptr_t)3));
|
||||
relative_offset =
|
||||
(int32)((intptr_t)reloc_addr
|
||||
- (((intptr_t)insn_addr + 3) & ~(intptr_t)3));
|
||||
/* relative_offset += initial_addend; */
|
||||
|
||||
/* check relative offset boundary */
|
||||
@ -228,4 +229,3 @@ apply_relocation(AOTModule *module,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user