mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-15 16:58:34 +00:00
address PR comments
This commit is contained in:
parent
7c0ea13ebf
commit
79c4fd9a1e
|
@ -681,10 +681,7 @@ load_custom_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
|
||||||
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
|
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
|
||||||
case AOT_CUSTOM_SECTION_RAW:
|
case AOT_CUSTOM_SECTION_RAW:
|
||||||
{
|
{
|
||||||
const uint8 *p_orig = p;
|
|
||||||
char section_name_buf[32];
|
|
||||||
const char *section_name;
|
const char *section_name;
|
||||||
uint32 name_len, buffer_len;
|
|
||||||
WASMCustomSection *section;
|
WASMCustomSection *section;
|
||||||
|
|
||||||
if (p >= p_end) {
|
if (p >= p_end) {
|
||||||
|
@ -694,20 +691,6 @@ load_custom_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
|
||||||
|
|
||||||
read_string(p, p_end, section_name);
|
read_string(p, p_end, section_name);
|
||||||
|
|
||||||
name_len = p - p_orig;
|
|
||||||
|
|
||||||
buffer_len = sizeof(section_name_buf);
|
|
||||||
memset(section_name_buf, 0, buffer_len);
|
|
||||||
if (name_len < buffer_len) {
|
|
||||||
bh_memcpy_s(section_name_buf, buffer_len, section_name,
|
|
||||||
name_len);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bh_memcpy_s(section_name_buf, buffer_len, section_name,
|
|
||||||
buffer_len - 4);
|
|
||||||
memset(section_name_buf + buffer_len - 4, '.', 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
section = loader_malloc(sizeof(WASMCustomSection), error_buf,
|
section = loader_malloc(sizeof(WASMCustomSection), error_buf,
|
||||||
error_buf_size);
|
error_buf_size);
|
||||||
if (!section) {
|
if (!section) {
|
||||||
|
@ -715,13 +698,13 @@ load_custom_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
|
||||||
}
|
}
|
||||||
|
|
||||||
section->name_addr = (char *)section_name;
|
section->name_addr = (char *)section_name;
|
||||||
section->name_len = name_len;
|
section->name_len = strlen(section_name);
|
||||||
section->content_addr = (uint8 *)p;
|
section->content_addr = (uint8 *)p;
|
||||||
section->content_len = p_end - p;
|
section->content_len = p_end - p;
|
||||||
|
|
||||||
section->next = module->custom_section_list;
|
section->next = module->custom_section_list;
|
||||||
module->custom_section_list = section;
|
module->custom_section_list = section;
|
||||||
LOG_VERBOSE("Load custom section [%s] success.", section_name_buf);
|
LOG_VERBOSE("Load custom section [%s] success.", section_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION != 0 */
|
#endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION != 0 */
|
||||||
|
@ -3327,13 +3310,12 @@ aot_get_plt_table_size()
|
||||||
|
|
||||||
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
|
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
|
||||||
const uint8 *
|
const uint8 *
|
||||||
aot_get_custom_section(AOTModule *module, const char *name, uint32 *len)
|
aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len)
|
||||||
{
|
{
|
||||||
WASMCustomSection *section = module->custom_section_list;
|
WASMCustomSection *section = module->custom_section_list;
|
||||||
|
|
||||||
while (section) {
|
while (section) {
|
||||||
if ((section->name_len == strlen(name))
|
if (strcmp(section->name_addr, name)) {
|
||||||
&& (memcmp(section->name_addr, name, section->name_len) == 0)) {
|
|
||||||
if (len) {
|
if (len) {
|
||||||
*len = section->content_len;
|
*len = section->content_len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -738,7 +738,7 @@ void
|
||||||
aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
|
aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
|
||||||
|
|
||||||
const uint8 *
|
const uint8 *
|
||||||
aot_get_custom_section(AOTModule *module, const char *name, uint32 *len);
|
aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* end of extern "C" */
|
} /* end of extern "C" */
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "aot.h"
|
#include "aot.h"
|
||||||
#include "../interpreter/wasm_loader.h"
|
|
||||||
|
|
||||||
static char aot_error[128];
|
static char aot_error[128];
|
||||||
|
|
||||||
|
|
|
@ -885,6 +885,7 @@ get_aot_file_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
|
||||||
AOTObjectData *obj_data)
|
AOTObjectData *obj_data)
|
||||||
{
|
{
|
||||||
uint32 size = 0;
|
uint32 size = 0;
|
||||||
|
uint32 size_custom_section = 0;
|
||||||
|
|
||||||
/* aot file header */
|
/* aot file header */
|
||||||
size += get_file_header_size();
|
size += get_file_header_size();
|
||||||
|
@ -942,10 +943,10 @@ get_aot_file_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
|
||||||
get_name_section_size(comp_data));
|
get_name_section_size(comp_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comp_ctx->custom_sections_wp) {
|
size_custom_section = get_custom_sections_size(comp_ctx, comp_data);
|
||||||
/* custom sections */
|
if (size_custom_section > 0) {
|
||||||
size = align_uint(size, 4);
|
size = align_uint(size, 4);
|
||||||
size += get_custom_sections_size(comp_ctx, comp_data);
|
size += size_custom_section;
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
|
@ -1941,8 +1942,7 @@ aot_emit_custom_sections(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||||
AOTCompData *comp_data, AOTCompContext *comp_ctx)
|
AOTCompData *comp_data, AOTCompContext *comp_ctx)
|
||||||
{
|
{
|
||||||
uint32 offset = *p_offset, i;
|
uint32 offset = *p_offset, i;
|
||||||
|
bool emitted = false;
|
||||||
*p_offset = offset = align_uint(offset, 4);
|
|
||||||
|
|
||||||
for (i = 0; i < comp_ctx->custom_sections_count; i++) {
|
for (i = 0; i < comp_ctx->custom_sections_count; i++) {
|
||||||
const char *section_name = comp_ctx->custom_sections_wp[i];
|
const char *section_name = comp_ctx->custom_sections_wp[i];
|
||||||
|
@ -1956,6 +1956,11 @@ aot_emit_custom_sections(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!emitted) {
|
||||||
|
emitted = true;
|
||||||
|
*p_offset = offset = align_uint(offset, 4);
|
||||||
|
}
|
||||||
|
|
||||||
offset = align_uint(offset, 4);
|
offset = align_uint(offset, 4);
|
||||||
EMIT_U32(AOT_SECTION_TYPE_CUSTOM);
|
EMIT_U32(AOT_SECTION_TYPE_CUSTOM);
|
||||||
/* sub section id + content */
|
/* sub section id + content */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user