-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Use llvm.used for __objc_protorefs and __objc_protolist #27346
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
Conversation
test/IRGen/objc_protocol_vars.sil
Outdated
@@ -0,0 +1,39 @@ | |||
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version none -primary-file %s -emit-ir | %FileCheck -check-prefix CHECK %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use -parse-as-library
and drop main
.
I think this is the right fix. The problem that this PR addresses is if one LTO's swift and objective c objects together. If objective c uses protocol descriptors without adding it to llvm.used it would explain current failures. AFAICT clang eagerly adds references to protocols when it generates protocols (https://github.com/apple/swift-clang/blob/f667f9fe4ab9da2a82db0291609f2480c30f079c/lib/CodeGen/CGObjCMac.cpp#L6978) and so there would be no need for clang to add them to llvm.used at protocol use sites. Swift doing the same makes sense to me. @rjmccall do you agree? |
@aschwaighofer yeah, that is correct. This should match the clang behaviour and fix the LTO cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
Build failed |
@swift-ci benchmark |
@swift-ci test source compatibility. |
lib/IRGen/GenObjC.cpp
Outdated
@@ -363,6 +363,10 @@ IRGenModule::getObjCProtocolGlobalVars(ProtocolDecl *proto) { | |||
protocolLabel->setSection(GetObjCSectionName("__objc_protolist", | |||
"coalesced,no_dead_strip")); | |||
|
|||
// Add __objc_protolist into llvm.used to avoid runtime crash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jinlin-bayarea might help to add some information regarding the crash, perhaps LTO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that a comment along the lines of:
Mark used to prevent DCE of public unreferenced protocols to ensure that they are available for external use when used a module is used as a library.
should be good.
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -OnoneCode size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
0991b3d
to
c00a7ec
Compare
@swift-ci Please test |
@swift-ci test source compatibility. |
@swift-ci benchmark |
Build failed |
Performance: -O
Code size: -OPerformance: -Osize
Code size: -OsizePerformance: -OnoneCode size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
Build failed |
…dd test to verify.
c00a7ec
to
9e414da
Compare
@swift-ci benchmark |
Performance: -O
Code size: -OPerformance: -OsizeCode size: -OsizePerformance: -OnoneCode size: -swiftlibsHow to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
@swift-ci Please test |
@swift-ci Smoke test |
@aschwaighofer @compnerd @aschwaighofer @rjmccall This looks good now and I am merging it. |
The purpose of the changes is to use llvm.used for __objc_protorefs and __objc_protolist
in the IRGen in Swift compiler to avoid runtime crash.
Resolves SR-11246.