Support emit specified custom sections into AoT file (#1207)

And add API to get the content of custom section with
section name for both wasm file and aot file.
This commit is contained in:
Xu Jun
2022-06-10 21:51:13 +08:00
committed by GitHub
parent d404107d85
commit 77595c9560
22 changed files with 420 additions and 31 deletions

View File

@ -12,8 +12,12 @@
#include "../compilation/aot.h"
#if WASM_ENABLE_JIT != 0
#include "../compilation/aot_llvm.h"
#endif
#if (WASM_ENABLE_JIT != 0) || (WASM_ENABLE_LOAD_CUSTOM_SECTION != 0)
#include "../interpreter/wasm_loader.h"
#endif
#if WASM_ENABLE_DEBUG_AOT != 0
#include "debug/elf_parser.h"
#include "debug/jit_debug.h"
@ -674,6 +678,36 @@ load_custom_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
error_buf, error_buf_size))
goto fail;
break;
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
case AOT_CUSTOM_SECTION_RAW:
{
const char *section_name;
WASMCustomSection *section;
if (p >= p_end) {
set_error_buf(error_buf, error_buf_size, "unexpected end");
goto fail;
}
read_string(p, p_end, section_name);
section = loader_malloc(sizeof(WASMCustomSection), error_buf,
error_buf_size);
if (!section) {
goto fail;
}
section->name_addr = (char *)section_name;
section->name_len = strlen(section_name);
section->content_addr = (uint8 *)p;
section->content_len = p_end - p;
section->next = module->custom_section_list;
module->custom_section_list = section;
LOG_VERBOSE("Load custom section [%s] success.", section_name);
break;
}
#endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION != 0 */
default:
break;
}
@ -3261,6 +3295,10 @@ aot_unload(AOTModule *module)
}
#endif
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
wasm_loader_destroy_custom_sections(module->custom_section_list);
#endif
wasm_runtime_free(module);
}
@ -3269,3 +3307,24 @@ aot_get_plt_table_size()
{
return get_plt_table_size();
}
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
const uint8 *
aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len)
{
WASMCustomSection *section = module->custom_section_list;
while (section) {
if (strcmp(section->name_addr, name) == 0) {
if (len) {
*len = section->content_len;
}
return section->content_addr;
}
section = section->next;
}
return NULL;
}
#endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION */

View File

@ -50,6 +50,7 @@ typedef enum AOTSectionType {
} AOTSectionType;
typedef enum AOTCustomSectionType {
AOT_CUSTOM_SECTION_RAW = 0,
AOT_CUSTOM_SECTION_NATIVE_SYMBOL = 1,
AOT_CUSTOM_SECTION_ACCESS_CONTROL = 2,
AOT_CUSTOM_SECTION_NAME = 3,
@ -268,6 +269,9 @@ typedef struct AOTModule {
uint32 *aux_func_indexes;
uint32 aux_func_name_count;
#endif
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
WASMCustomSection *custom_section_list;
#endif
} AOTModule;
typedef union {
@ -733,6 +737,9 @@ aot_dump_call_stack(WASMExecEnv *exec_env);
void
aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
const uint8 *
aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len);
#ifdef __cplusplus
} /* end of extern "C" */
#endif