Fix aot large model (--size-level=0) with LLVM 18 (#3057)

The recent versions LLVM uses ".ltext" section for X86 large model.

cf. d8a04398f9

This fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3034
This commit is contained in:
YAMAMOTO Takashi
2024-01-19 20:43:41 +09:00
committed by GitHub
parent ec6d9cb6be
commit bc35602004
3 changed files with 63 additions and 16 deletions

View File

@ -1975,6 +1975,12 @@ str2uint64(const char *buf, uint64 *p_res)
#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */
static bool
is_text_section(const char *section_name)
{
return !strcmp(section_name, ".text") || !strcmp(section_name, ".ltext");
}
static bool
do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
char *error_buf, uint32 error_buf_size)
@ -2063,7 +2069,7 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
symbol_addr = module->func_ptrs[func_index];
}
#endif
else if (!strcmp(symbol, ".text")) {
else if (is_text_section(symbol)) {
symbol_addr = module->code;
}
else if (!strcmp(symbol, ".data") || !strcmp(symbol, ".sdata")
@ -2235,7 +2241,7 @@ do_data_relocation(AOTModule *module, AOTRelocationGroup *group,
for (i = 0; i < group->relocation_count; i++, relocation++) {
symbol = relocation->symbol_name;
if (!strcmp(symbol, ".text")) {
if (is_text_section(symbol)) {
symbol_addr = module->code;
}
#if WASM_ENABLE_STATIC_PGO != 0
@ -2696,6 +2702,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
if (!strcmp(group->section_name, ".rel.text")
|| !strcmp(group->section_name, ".rela.text")
|| !strcmp(group->section_name, ".rel.ltext")
|| !strcmp(group->section_name, ".rela.ltext")
|| !strcmp(group->section_name, ".rela.literal")
#ifdef BH_PLATFORM_WINDOWS
|| !strcmp(group->section_name, ".text")

View File

@ -100,6 +100,12 @@ get_section64(Elf64_Ehdr *eh, Elf64_Shdr *section_header)
return buf + section_header->sh_offset;
}
static bool
is_text_section(const char *section_name)
{
return !strcmp(section_name, ".text") || !strcmp(section_name, ".ltext");
}
bool
get_text_section(void *buf, uint64_t *offset, uint64_t *size)
{
@ -107,6 +113,7 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
uint32 i;
char *sh_str;
/* Assumption: Only one of .text or .ltext is non-empty. */
if (is64Bit(buf)) {
Elf64_Ehdr *eh = (Elf64_Ehdr *)buf;
Elf64_Shdr **sh_table =
@ -115,14 +122,16 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
read_section_header_table64(eh, sh_table);
sh_str = get_section64(eh, sh_table[eh->e_shstrndx]);
for (i = 0; i < eh->e_shnum; i++) {
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
if (is_text_section(sh_str + sh_table[i]->sh_name)) {
*offset = sh_table[i]->sh_offset;
*size = sh_table[i]->sh_size;
sh_table[i]->sh_addr =
(Elf64_Addr)(uintptr_t)((char *)buf
+ sh_table[i]->sh_offset);
ret = true;
break;
if (*size > 0) {
break;
}
}
}
wasm_runtime_free(sh_table);
@ -136,14 +145,16 @@ get_text_section(void *buf, uint64_t *offset, uint64_t *size)
read_section_header_table(eh, sh_table);
sh_str = get_section(eh, sh_table[eh->e_shstrndx]);
for (i = 0; i < eh->e_shnum; i++) {
if (!strcmp(sh_str + sh_table[i]->sh_name, ".text")) {
if (is_text_section(sh_str + sh_table[i]->sh_name)) {
*offset = sh_table[i]->sh_offset;
*size = sh_table[i]->sh_size;
sh_table[i]->sh_addr =
(Elf32_Addr)(uintptr_t)((char *)buf
+ sh_table[i]->sh_offset);
ret = true;
break;
if (*size > 0) {
break;
}
}
}
wasm_runtime_free(sh_table);