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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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)

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