[wasm][IRGen] Stop attaching COMDATs to dead stub methods #85106
+55
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When generating dead stub methods for vtable entries, we should not attach COMDATs to their definitions. This is because such stubs may be referenced only through aliases, and the presence of a COMDAT on the stub definition would cause the aliased symbol, we want to keep, to be discarded from the symbol table when other object files also have a dead stub method.
Given the following two object files generated:
graph TD subgraph O0[A.swift.o] subgraph C0[COMDAT Group swift_dead_method_stub] D0_0["[Def] swift_dead_method_stub"] end S0_0["[Symbol] swift_dead_method_stub"] --> D0_0 S1["[Symbol] C1.dead"] --alias--> D0_0 end subgraph O1[B.swift.o] subgraph C1[COMDAT Group swift_dead_method_stub] D0_1["[Def] swift_dead_method_stub"] end S0_1["[Symbol] swift_dead_method_stub"] --> D0_1 S2["[Symbol] C2.beef"] --alias--> D0_1 endWhen linking these two object files, the linker will pick one of the COMDAT groups of
swift_dead_method_stub. The other COMDAT group will be discarded, along with all symbols aliased to the discarded definition, even though those aliased symbols (C1.deadandC2.beef) are the ones we want to keep to construct vtables.This change stops attaching COMDATs to dead stub method definitions. This effectively only affects WebAssembly targets because MachO's
supportsCOMDATreturns false, and COFF targets don't uselinkonce_odrfor dead stub methods.The COMDAT was added in 7e8f782, and it made swift-format build for Wasm to fail