Stream: git-wasmtime

Topic: wasmtime / Issue #2048 Cranelift: COMDAT support


view this post on Zulip Wasmtime GitHub notifications bot (Jul 20 2020 at 18:58):

carlokok opened Issue #2048:

COMDAT can be used for two purposes:

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.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 20 2020 at 19:06):

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.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 05 2020 at 07:53):

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.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 24 2020 at 14:38):

bnjbvr labeled Issue #2048:

COMDAT can be used for two purposes:

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.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 24 2020 at 14:39):

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:

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

Learn more.
</details>


Last updated: Nov 22 2024 at 17:03 UTC