Skip to content

[IRGen] Don't emit relative references to Objective-C class references. #21107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2018

Conversation

DougGregor
Copy link
Member

Objective-C class references (which show up in the __objc_classrefs
section) are always coalesced by the linker. When we relatively
address them (which occurs in protocol conformance records), the
linker may compute the relative offset before coalescing, leading to
an incorrect result. The net effect is a protocol conformance record
that applies to the wrong Objective-C class, causing all sorts of
runtime mayhem.

Switch relatively-addressed Objective-C classes over to using the
Objective-C runtime name of the class. It's a less efficient encoding
(since we need to go through objc_lookUpClass), but it avoids the
linker bug.

Fixes rdar://problem/46428085 by working around the linker bug.

Objective-C class references (which show up in the __objc_classrefs
section) are always coalesced by the linker. When we relatively
address them (which occurs in protocol conformance records), the
linker may compute the relative offset *before* coalescing, leading to
an incorrect result. The net effect is a protocol conformance record
that applies to the wrong Objective-C class, causing all sorts of
runtime mayhem.

Switch relatively-addressed Objective-C classes over to using the
Objective-C runtime name of the class. It's a less efficient encoding
(since we need to go through objc_lookUpClass), but it avoids the
linker bug.

Fixes rdar://problem/46428085 by working around the linker bug.
Now that we're never relatively addressing an Objective-C class reference,
stop emitting them as file-local (by eliminating the \01l_ prefix). This
is both a minor optimization and also a way to ensure that things will
break more consistently if a problem remains.
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 7, 2018

Build failed
Swift Test Linux Platform
Git Sha - e981834

@swift-ci
Copy link
Contributor

swift-ci commented Dec 7, 2018

Build failed
Swift Test OS X Platform
Git Sha - e981834

@DougGregor
Copy link
Member Author

@swift-ci please test

2 similar comments
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@swift-ci
Copy link
Contributor

swift-ci commented Dec 7, 2018

Build failed
Swift Test Linux Platform
Git Sha - e981834

@swift-ci
Copy link
Contributor

swift-ci commented Dec 7, 2018

Build failed
Swift Test Linux Platform
Git Sha - e981834

@DougGregor DougGregor merged commit adf4efe into swiftlang:master Dec 7, 2018
@DougGregor DougGregor deleted the relative-objc-class-by-name branch December 7, 2018 17:17
DougGregor added a commit to DougGregor/swift that referenced this pull request Dec 10, 2018
This test appears to have been fixed by
swiftlang#21107. Fixes rdar://problem/42789939.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants