Skip to content
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 wasm_runtime_get_func_name_from_index() api #4117

Closed

Conversation

Jiax-cn
Copy link
Contributor

@Jiax-cn Jiax-cn commented Feb 27, 2025

WAMR already implements this function, but its scope is limited to the source file and only applies to the module instance. I reimplemented this because it is clearer to obtain function names in the following scenarios, where the (WASM/AOT) module has not yet been instantiated:

  1. aot_create_perf_map() This creates /tmp/perf-.map for linux-perf.
  2. aot_add_llvm_func1() By doing so, LLVM can include function names in the IR and machine code, allowing us to see them in the call stack when debugging AOT with LLDB/GDB.

If this is useful, I would be happy to submit PRs for these two scenarios.

@lum1n0us
Copy link
Collaborator

lum1n0us commented Mar 3, 2025

If the goal is to enhance the readability of the performance map, perhaps we should consider enhancing the functionality of process_folded_data.py.


WASM_RUNTIME_API_EXTERN const uint8_t *
wasm_runtime_get_custom_section(const wasm_module_t module_comm,
                                const char *name, uint32_t *len);

can retrieve the content of the name section. With this information, the host can complete the mapping between function indices and their names. Personally, I think using an index to retrieve a name is an infrequent operation.

@Jiax-cn
Copy link
Contributor Author

Jiax-cn commented Mar 4, 2025

If the goal is to enhance the readability of the performance map, perhaps we should consider enhancing the functionality of process_folded_data.py.

I’ve read this script. IIUC, it uses WABT to extract function names and add them to perf.folded. It might be more straightforward to add them when writing perf.map.

Moreover, I think the second scenario—using function names when adding functions in LLVM—is necessary, which process_folded_data.py cannot address.

Personally, I think using an index to retrieve a name is an infrequent operation.

It’s fine to remove this API from wasm_export.h. We can make this PR a unification of the distributed functions.

aot_runtime.c

static const char *
get_func_name_from_index(const AOTModuleInstance *module_inst,
                         uint32 func_index)

wasm_runtime.c

static char *
get_func_name_from_index(const WASMModuleInstance *inst, uint32 func_index)

@Jiax-cn
Copy link
Contributor Author

Jiax-cn commented Mar 18, 2025

You're correct; having readable names for AOT functions in the IR and generated code would indeed make debugging more user-friendly. However, the reality is that .wasm files often lack a named section. Typically, in the interest of minimizing binary size, debug information is stripped, which means we need at least two naming systems to handle scenarios with and without a name section.

On the other hand, generated function names are a common assumption across AOT and JIT running modes and their supporting tools. Therefore, unless there's a comprehensive solution available, we might prefer to stick with additional scripts for the time being.

Originally posted by @lum1n0us in #4113 (comment)

This PR has been reviewed and discussed. I am closing it but will keep my branch for future reference.

@Jiax-cn Jiax-cn closed this Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants