-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom name section to aot file #794
Conversation
core/iwasm/aot/aot_runtime.h
Outdated
@@ -223,6 +224,8 @@ typedef struct AOTModule { | |||
/* constant string set */ | |||
HashMap *const_str_set; | |||
|
|||
StringList const_str_list; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to define a new string list, use const_str_set should be enough, and use macro read_string to read and insert the const string to the hash set.
size = align_uint(size, 4); | ||
/* section id + section size + sub section id */ | ||
size += (uint32)sizeof(uint32) * 3; | ||
size += comp_data->name_section_buf_end - comp_data->name_section_buf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we decode the function names previously here, and emit these strings with format 2-byte string len + string
so that aot loader can just use read_string macro to read string? Ref to emitting of other strings.
core/iwasm/aot/aot_loader.c
Outdated
} | ||
|
||
static char * | ||
const_str_list_insert(const uint8 *str, uint32 len, AOTModule *module, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use read_string macro instead
core/iwasm/aot/aot_loader.c
Outdated
p += name_len; | ||
|
||
while (p < p_end) { | ||
read_leb_uint32(p, p_end, name_type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just emit decoded uint32 directly, so here we can read uint32 directly, don't add decoding leb codes so as to reduce footprint.
core/iwasm/aot/aot_loader.c
Outdated
|
||
for (name_index = 0; name_index < num_func_name; | ||
name_index++) { | ||
read_leb_uint32(p, p_end, func_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that here the func_index is bound to the following function_name, should add an array in AOTModule to store these func indexes? And when looking up, we should traverse the array one by one to lookup the func name of related func index?
core/iwasm/aot/aot_runtime.c
Outdated
@@ -2822,6 +2822,12 @@ get_func_name_from_index(const AOTModuleInstance *module_inst, | |||
const char *func_name = NULL; | |||
AOTModule *module = module_inst->aot_module.ptr; | |||
|
|||
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0 | |||
if (module->aux_func_name && func_index < module->aux_func_name_count) { | |||
return *(module->aux_func_name + func_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems invalid, seems that we should also add a func index array in AOTModule, and here lookup it (Just my understanding, to be confirmed):
AOTModule {
uint32 aux_func_name_count;
uint32 *aux_func_indexes;
const char *aux_func_names;
};
Here:
for (i = 0; i < aux_func_name_count; i++) {
if (aux_func_indexes[i] == func_index)
return aux_func_names[i];
}
Or sort the arrays previously, and here use quick search to lookup the func name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/iwasm/aot/aot_loader.c
Outdated
if (name_len == 0 || p + name_len > p_end) { | ||
set_error_buf(error_buf, error_buf_size, "unexpected end"); | ||
return false; | ||
} | ||
|
||
if (!check_utf8_str(p, name_len)) { | ||
set_error_buf(error_buf, error_buf_size, "invalid UTF-8 encoding"); | ||
return false; | ||
} | ||
|
||
if (memcmp(p, "name", 4) != 0) { | ||
set_error_buf(error_buf, error_buf_size, "invalid custom name section"); | ||
return false; | ||
} | ||
p += name_len; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must the name here be "name" and the name_len be 4? If yes, how about changing the codes to be:
if (name_len != 4 || p + name_len > p_end) {
set_error_buf(error_buf, error_buf_size, "unexpected end");
return false;
}
if (memcmp(p, "name", 4) != 0) {
set_error_buf(error_buf, error_buf_size, "invalid custom name section");
return false;
}
p += name_len;
So that we don't need to call check_utf8_str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/iwasm/aot/aot_loader.c
Outdated
for (name_index = 0; name_index < num_func_name; | ||
name_index++) { | ||
read_uint32(p, p_end, func_index); | ||
if (func_index == previous_func_index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be name_index != 0 && func_index == previous_func_index
? The first func_index can be 0.
core/iwasm/aot/aot_loader.c
Outdated
return false; | ||
} | ||
if (func_index < previous_func_index | ||
&& previous_func_index != ~0U) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about change to if (name_index != 0 && func_index < previous_func_index)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And had better check whether func_index < module->import_func_count + module->func_count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/iwasm/aot/aot_runtime.c
Outdated
for (i = 0; i < module->aux_func_name_count; i++) { | ||
if (module->aux_func_indexes[i] == func_index) | ||
return module->aux_func_names[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Traversing array elements one by one is a little slow, as the elements in aux_func_indexes are sorted, can we use binary search to search the element, so as to improve the performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Enable emitting custom name section to aot file when adding `--enable-dump-call-stack` or `--enable-dump-call-stack` to wamrc and there is custom name section in wasm file, which can be generated by wasi-sdk/emcc "-g" option. So aot runtime can also get the function name from the custom name section instead of export section, to which developer should use `--export-all` for wasi-sdk/emcc to generate export function names.
Wamrc will append custom name section to aot file if we set WAMR_BUILD_DUMP_CALL_STACK to 1(which is disable by default),
this makes aot_dump_call_stack() could print function name but no need to use
-Wl, --export-all
to export all methods(I haven't found some way to export all methods of AssemblyScript module).I am not sure whether we should extract following duplicate methods, please help me to review it, thanks.