Duplicate "__PROTOCOL_*" metadata in binaries

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 - Swift 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

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?

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 !

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.

I see. Since WeakAny works also and is more safe, I'll go with that for the PR.

Terms of Service

Privacy Policy

Cookie Policy