alxb
(Alex B)
1
Hello,
I've noticed that some SWIFT binaries show duplicate metadata entries such as:
__PROTOCOL_NSObject
along with all descending linked metadata.
The Issue is coming from GenClass.cpp#L1396 where, a global is created with internal linkage: GenClass.cpp#L2181. Because of the internal linkage, the linker will not merge identical records in the final output.
The fix is to update the linkage type to WeakAnyLinkage, as in ObjC
CGObjCMac.cpp#L6967
I also opened [SR-15376] Duplicate "__PROTOCOL_*" metadata in linked binaries · Issue #57698 · apple/swift · GitHub about this.
I'm thinking about going ahead and submitting a fix to change the internal linkage to WeakAnyLinkage and updating to unit tests to reflect the change.
Is this the right way to go, am I missing anything?
cc @Joe_Groff
Thanks!
1 Like
Joe_Groff
(Joe Groff)
2
I checked in with @Mike_Ash and we both think this looks good. My one question would be whether it makes sense to use ODR linkage as well?
alxb
(Alex B)
3
Yes, ODR linkage is what makes most sense to me too. I tested that first and it worked - but wanted to be on par with ObjC to be safe. I'll submit a PR with ODR linkage. Thanks for the feedback !
Joe_Groff
(Joe Groff)
4
If Clang uses WeakAny linkage, that may be the safest place to start, since it is the canonical implementation of Apple ObjC. I don't know the history of why it isn't ODR in Clang; that might be a good question to raise on the cfe-dev list, if you're interested in investigating further.
alxb
(Alex B)
5
I see. Since WeakAny works also and is more safe, I'll go with that for the PR.