Intro
I'm trying to determine whether Xcode's new Mergeable Libraries feature can remove duplicated symbols in a scenario where an app links to two dynamic frameworks which both link to the same static library, as follows:
|--App
|--DynamicFramework1
|--StaticLibrary
|--DynamicFramework2
|--StaticLibrary <- the same library that DynamicFramework1 links to
Project setup
Here are some details about the app's structure:
- The static library is named
StaticLibrary
. It:
- Contains a single Objective-C class named
SLClass1
- The first dynamic framework target is named
DynamicFramework1
. It:
- Contains a single Objective-C class named
DF1Class1
that calls intoSLClass1
; and - Has a
MERGEABLE_LIBRARY
build setting value ofYES
.
- The second dynamic framework target is named
DynamicFramework2
. It:
- Contains a single Objective-C class named
DF2Class1
that calls intoSLClass1
; and - Has a
MERGEABLE_LIBRARY
build setting value ofYES
.
- The app target is named
App
. It:
- Contains a single Swift class named
ViewController
that calls into theDF1Class1
andDF2Class1
classes; and - Has a
MERGED_BINARY_TYPE
build setting value ofAutomatic
. (1)
I've created a minimal Xcode project here that has the above structure.
Expected result
The merged app binary, when built it in Release mode, contains the symbols for DF1Class1,
DF2Class1
and SLClass1
directly within it and it contains only one instance of each of these symbols (i.e. no duplicates).
I am basing this expectation on the Benefits of mergeable libraries section of the Meet mergeable libraries talk from WWDC 2023 where the speaker said:
When merging, the linker can de-duplicate content, such as strings, across all libraries. For instance, it removes redundant symbol references, Objective-C selectors, and objc_msgsend stubs.
Actual result
The merged app binary, when built it in Release mode, contains the symbols for DF1Class1
, DF2Class1
and SLClass1
directly within it but it contains two instances of SLClass1
's symbols (i.e. it contains duplicates). (2)
My Question
Have I missed something in the app's build settings or have I misunderstood the capability of Mergeable Libraries? Can I get the Xcode linker to deduplicate symbols in the app's merged binary?
Footnotes
- I have tried with a MERGED_BINARY_TYPE build setting value of Manual also but the result is the same.
- I have validated this by running the nm command on the app's executable file and inspecting the output.