Fix aot relocation symbols not found on windows 32-bit (#3231)

The symbols in windows 32-bit may start with '_' and can not be found
when resolving the relocations to them. This PR ignores the underscore
when handling the relocation name of AOT_FUNC_INTERNAL_PREFIX, and
redirect the relocation with name "_aot_stack_sizes" to the relocation with
name ".aot_stack_sizes" (the name of the data section created).

ps.
https://github.com/bytecodealliance/wasm-micro-runtime/issues/3216
This commit is contained in:
Wenyong Huang 2024-03-18 09:51:38 +08:00 committed by GitHub
parent 5e2011ca1d
commit ff296c1a62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -2917,6 +2917,17 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
}
symbol_addr = module->func_ptrs[func_index];
}
else if (!strncmp(symbol, "_" AOT_FUNC_INTERNAL_PREFIX,
strlen("_" AOT_FUNC_INTERNAL_PREFIX))) {
p = symbol + strlen("_" AOT_FUNC_INTERNAL_PREFIX);
if (*p == '\0'
|| (func_index = (uint32)atoi(p)) > module->func_count) {
set_error_buf_v(error_buf, error_buf_size, "invalid symbol %s",
symbol);
goto check_symbol_fail;
}
symbol_addr = module->func_ptrs[func_index];
}
#endif
else if (is_text_section(symbol)) {
symbol_addr = module->code;

View File

@ -3947,7 +3947,12 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
* Note: aot_stack_sizes_section_name section only contains
* stack_sizes table.
*/
if (!strcmp(relocation->symbol_name, aot_stack_sizes_name)) {
if (!strcmp(relocation->symbol_name, aot_stack_sizes_name)
/* in windows 32, the symbol name may start with '_' */
|| (strlen(relocation->symbol_name) > 0
&& relocation->symbol_name[0] == '_'
&& !strcmp(relocation->symbol_name + 1,
aot_stack_sizes_name))) {
/* discard const */
relocation->symbol_name = (char *)aot_stack_sizes_section_name;
}