bytecodealliance / bytecodealliance/wasmtime

Cranelift: COMDAT support

Open
#2,048 3 comments 0 reactions 0 assignees View on GitHub
cranelift
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

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

#### Benefit

It's currently not possible to do COMDAT at all, thus any duplicate symbol will fail.

#### Implementation

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.