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

[wasm] Add wa-info tool to src/mono/wasm/tools #110565

Draft
wants to merge 157 commits into
base: main
Choose a base branch
from

Conversation

radekdoulik
Copy link
Member

No description provided.

radekdoulik and others added 30 commits December 10, 2024 09:33
Currently it is able to read wasm modules and few sections, like Type,
Imports, Exports, Function

Example output:

    > wa-info.exe -v dotnet.wasm
    Reading wasm file: dotnet.wasm
    WebAssembly binary format version: 1
    Section:      Type size:         3097 count: 339
    Section:    Import size:         2505 count: 102
    Section:  Function size:        17844 count: 17703
    Section:     Table size:            7
    Section:    Memory size:            7
    Section:    Global size:           19
    Section:    Export size:         2279 count: 98
    Section:   Element size:         8291
    Section:      Code size:      2000334
    Section:      Data size:       508697
    Section:    Custom size:       840366 name: name
    Section:    Custom size:      4063235 name: .debug_info
    Section:    Custom size:      1436986 name: .debug_loc
    Section:    Custom size:       141446 name: .debug_ranges
    Section:    Custom size:       241806 name: .debug_abbrev
    Section:    Custom size:      2032586 name: .debug_line
    Section:    Custom size:       739480 name: .debug_str
Read function code blocks, read locals
Read function, local, global and data segment name maps
Example use:

    wa-info.exe -d --function-filter Json.*Measure dotnet.wasm
    (func Wasm_Browser_Bench_Sample_Sample_JsonTask_get_Measurements(param i32 i32) (result i32))
     local 1 i32
     global_get
     i32_const
     i32_sub
     local_tee $2
     global_set
     local_get $0
     i32_eqz
     if
      call $mini_llvmonly_throw_nullref_exception
      unreachable

     local_get $2
     local_get $0
     i32_load
     i32_store
     local_get $2
     i32_load
     local_set $0
     local_get $2
     i32_const
     i32_add
     global_set
     local_get $0
The function names map includes names of imports at the beginning

Fix indentation

Example output:

    wa-info.exe -d --function-filter Wasm_Browser_Bench_Sample_Sample_ExceptionsTask_TryCatch_RunStep dotnet.wasm
    (func Wasm_Browser_Bench_Sample_Sample_ExceptionsTask_TryCatch_RunStep(param i32 i32))
     local 1 i32
     global.get
     i32.const 16
     i32.sub
     local.tee $2
     global.set
     local.get $2
     local.get $0
     i32.store
     i32.const 1997558
     i32.load8.u
     i32.eqz
     if
      i32.const 1171316
      call $mono_aot_Wasm_Browser_Bench_Sample_init_method
      i32.const 1997558
      i32.const 1
      i32.store8

     i32.const 1994984
     i32.load
     call $mini_llvmonly_get_interp_entry
     local.set $0
     local.get $2
     local.get $2
     i32.load
     i32.store
     local.get $2
     i32.load
     local.get $0
     i32.load
     local.get $0
     i32.load
     local.tee $0
     call.indirect
     local.get $2
     i32.const 16
     i32.add
     global.set
Example:

    (func System_Private_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_Runtime_GetCSOwnedObjectByJSHandle_int_int(param i32 i32 i32) (result i32))
     local 1 i32
     local 1 i32
     global.get $__stack_pointer
     i32.const 16
     i32.sub
     local.tee $3
     global.set $__stack_pointer
     i32.const 1947029
     ...
Example:

    ...
     i32.load offset:12 align:2
     i32.store offset:8 align:2
     local.get $3
     i32.load offset:8 align:2
     local.set $0
     local.get $3
     i32.const 16
     i32.add
     global.set $__stack_pointer
    ...
Also improve dump bytes to show canonical hex+ASCII output
Also fixes crash with some import types
Changes:

 * improve imports reading
 * improve dump bytes
 * show custom sections content in verbose2 mode (-vv)
 * introduce wa-lib assembly with the shared code
This is beginning of parsing content of custom sections
in wasm obj `.o` files.
Changes:

 * add support for wasm object files
 * parse linking and relocation sections
Copy link
Contributor

Tagging subscribers to this area: @akoeplinger, @matouskozak
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@radekdoulik radekdoulik reopened this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Infrastructure-mono NO-SQUASH The PR should not be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants