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
Here are some details about the app's structure:
StaticLibrary
. It:
SLClass1
DynamicFramework1
. It:
DF1Class1
that calls into SLClass1
; andMERGEABLE_LIBRARY
build setting value of YES
.DynamicFramework2
. It:
DF2Class1
that calls into SLClass1
; andMERGEABLE_LIBRARY
build setting value of YES
.App
. It:
ViewController
that calls into the DF1Class1
and DF2Class1
classes; andMERGED_BINARY_TYPE
build setting value of Automatic
.1I've created a minimal Xcode project here that has the above structure.
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.
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
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?
MERGED_BINARY_TYPE
build setting value of Manual
also but the result is the same.nm
command on the app's executable file and inspecting the output.
Apple's Quinn "The Eskimo" (renowned for his tireless support in the Apple Developer forums) has confirmed that Mergeable Libraries will not deduplicate symbols in the above scenario.
For the details, see his answer in the Apple Developer Forums here.