Skip to content

[cxx-interop][IRGen] Emit type metadata accessors correctly #74208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

egorzhdan
Copy link
Contributor

This change makes sure we correctly emit IR for type metadata accessors for C++ reference types.

This fixes linker errors when a type metadata of a C++ reference type is used in multiple object files that are later linked together, for instance, if a C++ reference type is conformed to different Swift protocols in different Swift source files:

duplicate symbol 'type metadata accessor for __C.SharedObject' in:
  main.o
  second.o
ld: 1 duplicate symbols

rdar://129027705

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jun 7, 2024
@egorzhdan egorzhdan requested review from zoecarver and hyp as code owners June 7, 2024 13:15
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@@ -1102,9 +1102,6 @@ MetadataAccessStrategy irgen::getTypeMetadataAccessStrategy(CanType type) {
assert(type->hasUnboundGenericType());
}

if (type->isForeignReferenceType())
return MetadataAccessStrategy::PublicUniqueAccessor;

if (requiresForeignTypeMetadata(nominal))
return MetadataAccessStrategy::ForeignAccessor;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what needs to be returned for a C++ reference type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. We were lazily emitting the type metadata when we first referenced in, but we were emitting it with strong linkage? Yes, this is the right fix, then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right

@egorzhdan egorzhdan requested review from rjmccall and Xazax-hun June 7, 2024 13:22
This change makes sure we correctly emit IR for type metadata accessors for C++ reference types.

This fixes linker errors when a type metadata of a C++ reference type is used in multiple object files that are later linked together, for instance, if a C++ reference type is conformed to different Swift protocols in different Swift source files:
```
duplicate symbol 'type metadata accessor for __C.SharedObject' in:
  main.o
  second.o
ld: 1 duplicate symbols
```

rdar://129027705
@egorzhdan egorzhdan force-pushed the egorzhdan/frt-duplicate-metadata-accessor branch from 6a4f7a0 to a5ce0dc Compare June 7, 2024 18:00
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan merged commit dbe1a98 into main Jun 7, 2024
3 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/frt-duplicate-metadata-accessor branch June 7, 2024 21:49
jefferyq2 pushed a commit to jefferyq2/swift that referenced this pull request Jun 10, 2024
…-metadata-accessor

[cxx-interop][IRGen] Emit type metadata accessors correctly
jefferyq2 pushed a commit to jefferyq2/swift that referenced this pull request Jun 10, 2024
…-metadata-accessor

[cxx-interop][IRGen] Emit type metadata accessors correctly
jefferyq2 pushed a commit to jefferyq2/swift that referenced this pull request Jun 10, 2024
…-metadata-accessor

[cxx-interop][IRGen] Emit type metadata accessors correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants