Emit vtables/type infos with weak ODR linkage for MachO compatibility#1206
Merged
Conversation
VTables, type infos and type info names are ODR entities that may legitimately be emitted in more than one translation unit (e.g. an interface that is forward-declared in one file and fully defined in another, as the bootstrap IAbstractAstVisitor is). They were emitted as strong ExternalLinkage symbols relying on a comdat group to coalesce duplicates. comdat is skipped on MachO, so on macOS the duplicate definitions collided with a linker "duplicate symbol" error. Give these symbols weak ODR linkage, matching how Clang emits C++ vtables/type infos. On ELF this pairs with the existing comdat group (behavior unchanged); on MachO the weak/coalesced linkage lets the linker merge the duplicates. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Since the bootstrap accept()-dispatch commits, macOS CI fails to link
BootstrapCompilerTests.bootstrapCompiler_unitWrapperAstVisualizer:IAbstractAstVisitoris deliberately declared in two files — an empty forward declaration inabstract-ast-visitor-intf.spice(soast-nodes.spicecan typeaccept(IAbstractAstVisitor*)without a circular import) and the full typed interface inabstract-ast-visitor.spice. Both translation units emit thevtable/typeinfo/typeinfo namesymbols.These were emitted as strong
ExternalLinkagesymbols relying on a comdat group to coalesce the duplicates.attachComdatToSymbolskips comdat on MachO (macOS has no comdat support), so on macOS the two strong definitions collide. On ELF the comdat coalesces them, which is why Linux CI was green.Fix
VTables, type infos and type info names are ODR entities that can legitimately appear in multiple translation units. Emit them with
WeakODRLinkageinstead of strong external, exactly as Clang emits C++ vtables/type infos:Regular functions and global variables are unaffected (they still use
getSymbolLinkageType).Tests
bootstrapCompiler_unitWrapperAstVisualizerand the interface/bootstrap-linker tests pass (22/22).IRGeneratorTestssuite passes (171/171).success-cross-sourcefile-interfaces), regenerated via--update-refs; the only delta is theweak_odrprefix on the public vtable/type info, matching standard Clang codegen.🤖 Generated with Claude Code