WebAssembly / WebAssembly/tool-conventions
Text format for relocation information
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 372
- Forks
- 75
- PR merge metrics
- No merged PRs in 30d
Description
@sbc100 and I were just talking about how we might represent some of the relocation information in the WebAssembly text format.
Nothing fully formed yet, but some ideas:
- It would be useful to be able to name data segments, then use these in functions, e.g.:
(func
(i32.load (i32.const $foo)) ...) ;; This would remap to 10
(data $foo (i32.const 10) "...")
This is a nice feature for the text format, but probably not required for relocations since we also need to be able to define imported memory offset symbols that can only be resolved at link time.
- Since memory offset symbols are defined as globals, perhaps we should have some way to annotate these to specify a relocation. The current documentation says that these will be retrieved with
get_global, but @sbc100 says that this is out-of-date. Instead, ai32.const 0(with a 5-byte immediate) is written which will be replaced later by the linker. Perhaps this could be written in the text format using a new sigil for relocations,@:
(import "some" "symbol" (global @extsym i32))
(global @intsym i32 (i32.const 0)) ;; 0 is unused, will be resolved by the linker
(func
(i32.load (i32.const 0) offset=@intsym)) ;; uses R_WEBASSEMBLY_MEMORY_ADDR_LEB
(i32.load (i32.const @intsym)) ;; uses R_WEBASSEMBLY_MEMORY_ADDR_SLEB
(i32.load (i32.const @extsym)) ;; same
...)
;; Data segments now can have names, but only for relocations.
(data @intsym (i32.const 10) ...)
;; We need a way to store the address of a global in memory as well.
(data (i32.const 100) @extsym) ;; uses R_WEBASSEMBLY_MEMORY_ADDR_I32
Keeping the global definition is nice because that is what will be generated in the binary format. It's kinda weird to have to define the global and use it later for the segment, though (and has issues with the name being used twice as well). Thoughts on improvements?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the relocation conventions in Linking.md, especially the section on merging data sections, then compare them with the text-format examples in this issue. The proposal is not fully formed, so completion would require agreeing on a relocation syntax and documenting how named data segments, globals, and memory-address relocations should be represented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100