Undefined symbols linker error at -Osize (App + Extensions linking against a shared framework)

We’re running into an issue when sharing code with app extensions and the main app binary, both of which link against a common framework we call SharedKit (a framework that hosts a .dylib and wraps common libraries).

  1. With Debug builds (-Onone), everything links and runs fine.
  2. With Production builds (-Osize), we hit undefined symbol linker errors - specifically missing modifier accessor symbols (public private(set) properties in the linked repro).
 "NeedleFoundation.PluginizedComponent.(releasableNonCoreComponent in _1B32DB22F194C7BD683D0EE09E1A9157).modify : NeedleFoundation.NonCoreScope?", referenced from: full type metadata for Sources.MockPluginizedComponent in libSources.a[2](BazelApp.swift.o) "NeedleFoundation.PluginizedComponent.(releasableNonCoreComponent in _1B32DB22F194C7BD683D0EE09E1A9157).getter : NeedleFoundation.NonCoreScope?", referenced from: full type metadata for Sources.MockPluginizedComponent in libSources.a[2](BazelApp.swift.o) "NeedleFoundation.PluginizedComponent.(releasableNonCoreComponent in _1B32DB22F194C7BD683D0EE09E1A9157).setter : NeedleFoundation.NonCoreScope?", referenced from: 

It seems that under optimization, the compiler does not emit these symbols, which then breaks linking when extensions and the app depend on SharedKit.

Are there any compiler flags or alternatives (that don’t require code changes or enabling full library evolution / Build for Distribution) that can force the compiler to preserve those modifier accessors so linking succeeds?

Repro: https://github.com/bazelbuild/rules_apple/issues/2784

Other refs: Structuring Your Code to Support App Extensions

1 Like