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

Try to guess symbol address in Wasm #538

Closed
ia0 opened this issue Apr 23, 2023 · 0 comments · Fixed by #539
Closed

Try to guess symbol address in Wasm #538

ia0 opened this issue Apr 23, 2023 · 0 comments · Fixed by #539

Comments

@ia0
Copy link
Contributor

ia0 commented Apr 23, 2023

I would suggest trying to guess an address for exported globals in Wasm instead of always using 0.

At least in Rust, it looks like symbols are exported globals of type i32 which value is the address (in linear memory) of the symbol. For example, an empty wasm module in Rust looks like:

(module
 (global $__stack_pointer (mut i32) (i32.const 1048576))
 (global $global$1 i32 (i32.const 1048576))
 (global $global$2 i32 (i32.const 1048576))
 (memory $0 16)
 (export "memory" (memory $0))
 (export "__data_end" (global $global$1))
 (export "__heap_base" (global $global$2))
 ;; features section: mutable-globals, sign-ext
)

Notice how __data_end and __heap_base are exported globals of type i32 with a value in linear memory (after the initial stack pointer).

My suggestion would be to detect those cases and fill the symbol address with the global value instead of 0. I wrote a draft PR in case the idea is not rejected.

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 a pull request may close this issue.

1 participant