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:
@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user