address PR comments

This commit is contained in:
Xu Jun 2022-06-10 16:21:38 +08:00
parent 7c0ea13ebf
commit 79c4fd9a1e
4 changed files with 15 additions and 29 deletions

View File

@ -681,10 +681,7 @@ load_custom_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
#if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
case AOT_CUSTOM_SECTION_RAW:
{
const uint8 *p_orig = p;
char section_name_buf[32];
const char *section_name;
uint32 name_len, buffer_len;
WASMCustomSection *section;
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);
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,
error_buf_size);
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_len = name_len;
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_buf);
LOG_VERBOSE("Load custom section [%s] success.", section_name);
break;
}
#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
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;
while (section) {
if ((section->name_len == strlen(name))
&& (memcmp(section->name_addr, name, section->name_len) == 0)) {
if (strcmp(section->name_addr, name)) {
if (len) {
*len = section->content_len;
}

View File

@ -738,7 +738,7 @@ void
aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
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
} /* end of extern "C" */

View File

@ -4,7 +4,6 @@
*/
#include "aot.h"
#include "../interpreter/wasm_loader.h"
static char aot_error[128];

View File

@ -885,6 +885,7 @@ get_aot_file_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
AOTObjectData *obj_data)
{
uint32 size = 0;
uint32 size_custom_section = 0;
/* aot file header */
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));
}
if (comp_ctx->custom_sections_wp) {
/* custom sections */
size_custom_section = get_custom_sections_size(comp_ctx, comp_data);
if (size_custom_section > 0) {
size = align_uint(size, 4);
size += get_custom_sections_size(comp_ctx, comp_data);
size += size_custom_section;
}
return size;
@ -1941,8 +1942,7 @@ aot_emit_custom_sections(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
AOTCompData *comp_data, AOTCompContext *comp_ctx)
{
uint32 offset = *p_offset, i;
*p_offset = offset = align_uint(offset, 4);
bool emitted = false;
for (i = 0; i < comp_ctx->custom_sections_count; 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;
}
if (!emitted) {
emitted = true;
*p_offset = offset = align_uint(offset, 4);
}
offset = align_uint(offset, 4);
EMIT_U32(AOT_SECTION_TYPE_CUSTOM);
/* sub section id + content */