xip: Lookup float constants from table to reduce relocations (#894)

Lookup float/double constants from exec_env->native_symbol table
but not construct them with LLVMBuildConst if XIP mode is enabled,
these constants are introduced by f32/f64.const opcodes and some
float/double conversion opcodes, and make wamrc generate some
relocations in text section of AOT XIP file. This patch eliminates such
relocations when "--enable-indirect-mode" is added to wamrc.
This commit is contained in:
Wenyong Huang
2021-12-16 21:39:23 +08:00
committed by GitHub
parent f2d87ec02e
commit 5be427bfa2
6 changed files with 287 additions and 45 deletions

View File

@ -465,6 +465,12 @@ get_native_symbol_by_name(const char *name)
return func;
}
static bool
str2uint32(const char *buf, uint32 *p_res);
static bool
str2uint64(const char *buf, uint64 *p_res);
static bool
load_native_symbol_section(const uint8 *buf, const uint8 *buf_end,
AOTModule *module, bool is_load_from_file_buf,
@ -487,11 +493,39 @@ load_native_symbol_section(const uint8 *buf, const uint8 *buf_end,
for (i = cnt - 1; i >= 0; i--) {
read_string(p, p_end, symbol);
module->native_symbol_list[i] = get_native_symbol_by_name(symbol);
if (module->native_symbol_list[i] == NULL) {
set_error_buf_v(error_buf, error_buf_size,
"missing native symbol: %s", symbol);
goto fail;
if (!strncmp(symbol, "f32#", 4)) {
uint32 u32;
/* Resolve the raw int bits of f32 const */
if (!str2uint32(symbol + 4, &u32)) {
set_error_buf_v(error_buf, error_buf_size,
"resolve symbol %s failed", symbol);
goto fail;
}
*(uint32 *)(&module->native_symbol_list[i]) = u32;
}
else if (!strncmp(symbol, "f64#", 4)) {
uint64 u64;
/* Resolve the raw int bits of f64 const */
if (!str2uint64(symbol + 4, &u64)) {
set_error_buf_v(error_buf, error_buf_size,
"resolve symbol %s failed", symbol);
goto fail;
}
*(uint64 *)(&module->native_symbol_list[i]) = u64;
}
else if (!strncmp(symbol, "__ignore", 8)) {
/* Padding bytes to make f64 on 8-byte aligned address,
or it is the second 32-bit slot in 32-bit system */
continue;
}
else {
module->native_symbol_list[i] =
get_native_symbol_by_name(symbol);
if (module->native_symbol_list[i] == NULL) {
set_error_buf_v(error_buf, error_buf_size,
"missing native symbol: %s", symbol);
goto fail;
}
}
}
}
@ -1711,7 +1745,6 @@ is_literal_relocation(const char *reloc_sec_name)
return !strcmp(reloc_sec_name, ".rela.literal");
}
#if defined(BH_PLATFORM_WINDOWS)
static bool
str2uint32(const char *buf, uint32 *p_res)
{
@ -1757,7 +1790,6 @@ str2uint64(const char *buf, uint64 *p_res)
*p_res = res;
return true;
}
#endif
static bool
do_text_relocation(AOTModule *module, AOTRelocationGroup *group,