Skip to content

Swift-to-C++: getTypeMetadata inline helpers that refer to C++ type metadata are annotated as used for debug compilations, causing linker errors #69234

Closed
@hyp

Description

@hyp

as reported on https://forums.swift.org/t/undeclared-use-of-identifier-in-generated-module-swift-file/67894.
It shows up as a linker error like this:

ld: Undefined symbols:
  type metadata accessor for __C.HelloCxxWorld, referenced from:
      swift::TypeMetadataTrait<HelloCxxWorld>::getTypeMetadata() in HelloHello.o

This is caused by how the C++ getTypeMetadata inline function is annotated in the generated header. It uses the SWIFT_INLINE_THUNK annotation which in debug mode in Xcode (when DEBUG is defined as a preprocessor macro/Swift build condition) is forced to be emitted into the object file, even when it's not used. This is wrong, as it's not supposed to be linked in forcefully and should only be needed when it's actually used.

Such functions should be annotated with SWIFT_INLINE_PRIVATE_HELPER instead.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++compilerThe Swift compiler itselflinker errorswift 5.10swift 6.0swift to c++Feature → c++ interop: swift to c++

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions