My apology if here is not the right place to ask a linker question.
I noticed that adding -ObjC linker flag will always force to load Swift libraries, even though no symbol is referenced. After digging into the source code of ld64, I found this was actually intentional. I understand that -ObjC is need to load Objective-C categories, but the behavior of loading Swift libraries isn't documented anywhere and surprised me. Along with Swift non-strippable public symbols, -ObjC could make binary size bigger than expected.
I'm curious to learn why Swift libraries are force loaded by -ObjC and if there is a way to disable it.
It was a short-term modification to keep ld64 from dropping dynamically-referenced Swift metadata from getting stripped. As Swift's own dead stripping gets better it should become unnecessary. In the meantime, I don't think there is a way to disable the behavior; you could leave out -ObjC and manually mark ObjC categories and Swift metadata symbols you need with -u instead, perhaps.
This will likely need to be tied to the "limit reflection" work, since a library might contain nothing but protocol conformances intended to be referenced dynamically (i.e. through as?).
Is there different behavior for this when using Swift Package Manager for integration? We're noticing that when linking various things via an xcodeproj integration itself the -ObjC flag is required to force load libraries, but the flag is not required if we link the package via SPM.