carlokok opened Issue #2048:
COMDAT can be used for two purposes:
- Allow multiple symbols with the same name without linking failures(pick largest, pick any, etc)
- Bind symbols together
This is very useful for using Cranelift as a compiler backend (for example any c++ implementation requires comdat). Can easily be done now that object supports comdat too: https://github.com/gimli-rs/object/pull/243
Feature
<!-- What is the feature or code improvement you would like to do in
Cranelift/Wasmtime? -->Benefit
It's currently not possible to do COMDAT at all, thus any duplicate symbol will fail.
Implementation
<!-- Do you have an implementation plan, and/or ideas for data structures or
algorithms to use? -->Open for suggestions, but was thinking something like how LLVM does it:
Module gets a list of comdat records consisting of a name + mode:
any
The linker may choose any COMDAT key, the choice is arbitrary.
exactmatch
The linker may choose any COMDAT key but the sections must contain the same data.
largest
The linker will choose the section containing the largest COMDAT key.
noduplicates
The linker requires that only section with this COMDAT key exist.
samesize
The linker may choose any COMDAT key but the sections must contain the same amount of data.Then for data and for function symbols, an associated comdat recordid can be set (without changing the public interface, so something like set_comdat on DataSection/Context.
For Mach-O and Wasm this should fail, for COFF the name should match 1 of the functions or data by name. For ELF the mode much be any. When emitting, Fairie should fail or ignore when set, Object should work, and jit should probably ignore it all together.
Alternatives
None really.
bjorn3 commented on Issue #2048:
When emitting, Fairie should fail or ignore when set, Object should work, and jit should probably ignore it all together.
I think it should fail for both fairie and jit. It should not silently ignore it when you didn't explicitly say that it is okay to ignore it, as that could cause (relatively) hard to debug problems.
carlokok commented on Issue #2048:
Api wise I was thinking something like:
add_comdat(&Self, main: FuncOrVarRef, mode: ComdatMode, symbols: &[FuncOrVarRef])
(is there a FuncRef or GlobalVariableRef I can use for this?)
Any suggestions?
Technically, comdat binds a symbol of an existing global (func or var) to 1 or more extra sections. Not 100% sure this is the best design for that.
bnjbvr labeled Issue #2048:
COMDAT can be used for two purposes:
- Allow multiple symbols with the same name without linking failures(pick largest, pick any, etc)
- Bind symbols together
This is very useful for using Cranelift as a compiler backend (for example any c++ implementation requires comdat). Can easily be done now that object supports comdat too: https://github.com/gimli-rs/object/pull/243
Feature
<!-- What is the feature or code improvement you would like to do in
Cranelift/Wasmtime? -->Benefit
It's currently not possible to do COMDAT at all, thus any duplicate symbol will fail.
Implementation
<!-- Do you have an implementation plan, and/or ideas for data structures or
algorithms to use? -->Open for suggestions, but was thinking something like how LLVM does it:
Module gets a list of comdat records consisting of a name + mode:
any
The linker may choose any COMDAT key, the choice is arbitrary.
exactmatch
The linker may choose any COMDAT key but the sections must contain the same data.
largest
The linker will choose the section containing the largest COMDAT key.
noduplicates
The linker requires that only section with this COMDAT key exist.
samesize
The linker may choose any COMDAT key but the sections must contain the same amount of data.Then for data and for function symbols, an associated comdat recordid can be set (without changing the public interface, so something like set_comdat on DataSection/Context.
For Mach-O and Wasm this should fail, for COFF the name should match 1 of the functions or data by name. For ELF the mode much be any. When emitting, Fairie should fail or ignore when set, Object should work, and jit should probably ignore it all together.
Alternatives
None really.
github-actions[bot] commented on Issue #2048:
Subscribe to Label Action
cc @bnjbvr
<details>
This issue or pull request has been labeled: "cranelift"Thus the following users have been cc'd because of the following labels:
- bnjbvr: cranelift
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
Last updated: Dec 23 2024 at 12:05 UTC