Skip to content

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

Merged
merged 1 commit into from
Oct 3, 2019

Conversation

jinlin-bayarea
Copy link
Contributor

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.

@jinlin-bayarea jinlin-bayarea changed the title Llvm used use llvm.used for __objc_protorefs and __objc_protolist Sep 24, 2019
@jinlin-bayarea jinlin-bayarea changed the title use llvm.used for __objc_protorefs and __objc_protolist Use llvm.used for __objc_protorefs and __objc_protolist Sep 24, 2019
@@ -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
Copy link
Member

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.

@aschwaighofer
Copy link
Contributor

aschwaighofer commented Sep 25, 2019

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?

@compnerd
Copy link
Member

@aschwaighofer yeah, that is correct. This should match the clang behaviour and fix the LTO cases.

@jinlin-bayarea
Copy link
Contributor Author

jinlin-bayarea commented Sep 25, 2019 via email

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rjmccall
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - f151af5a164a2b4232b648532bd6530aeb5310ef

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - f151af5a164a2b4232b648532bd6530aeb5310ef

@rajbarik
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e7e4fcde3ab1f1a66da456a442eb99ba57f1b37a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e7e4fcde3ab1f1a66da456a442eb99ba57f1b37a

@jinlin-bayarea
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@rajbarik
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9b4891a8dc25fadbb693c5242724e314c38516a3

@rajbarik
Copy link
Contributor

@swift-ci benchmark

@rajbarik
Copy link
Contributor

@swift-ci test source compatibility.

@@ -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.
Copy link
Contributor

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?

Copy link
Member

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.

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
DataAppendArray 2900 3300 +13.8% 0.88x (?)
 
Improvement OLD NEW DELTA RATIO
DropLastAnyCollection 13 12 -7.7% 1.08x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
PrefixArray 13 14 +7.7% 0.93x (?)

Code size: -Osize

Performance: -Onone

Code size: -swiftlibs

How to read the data The 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
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac mini
  Model Identifier: Macmini8,1
  Processor Name: Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@rajbarik
Copy link
Contributor

rajbarik commented Oct 1, 2019

@swift-ci Please test

@rajbarik
Copy link
Contributor

rajbarik commented Oct 1, 2019

@swift-ci test source compatibility.

@rajbarik
Copy link
Contributor

rajbarik commented Oct 1, 2019

@swift-ci benchmark

@swift-ci
Copy link
Contributor

swift-ci commented Oct 1, 2019

Build failed
Swift Test OS X Platform
Git Sha - 0991b3de9528aa6b487e05f79b9ccafb2941efff

@swift-ci
Copy link
Contributor

swift-ci commented Oct 1, 2019

Performance: -O

Improvement OLD NEW DELTA RATIO
ObjectiveCBridgeStubFromNSStringRef 105 93 -11.4% 1.13x (?)
SuffixAnyCollection 13 12 -7.7% 1.08x (?)

Code size: -O

Performance: -Osize

Improvement OLD NEW DELTA RATIO
SuffixArray 5 4 -20.0% 1.25x (?)
FlattenListLoop 3136 2686 -14.3% 1.17x (?)
MapReduceShortString 14 13 -7.1% 1.08x (?)

Code size: -Osize

Performance: -Onone

Code size: -swiftlibs

How to read the data The 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
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac mini
  Model Identifier: Macmini8,1
  Processor Name: Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@swift-ci
Copy link
Contributor

swift-ci commented Oct 1, 2019

Build failed
Swift Test Linux Platform
Git Sha - c00a7ec799b54d7e96a23129768559dd4fb3bf4b

@rajbarik
Copy link
Contributor

rajbarik commented Oct 2, 2019

@swift-ci benchmark

@swift-ci
Copy link
Contributor

swift-ci commented Oct 2, 2019

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 2801 3149 +12.4% 0.89x (?)
FlattenListFlatMap 5640 6092 +8.0% 0.93x (?)

Code size: -O

Performance: -Osize

Code size: -Osize

Performance: -Onone

Code size: -swiftlibs

How to read the data The 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
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac mini
  Model Identifier: Macmini8,1
  Processor Name: Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@rajbarik
Copy link
Contributor

rajbarik commented Oct 2, 2019

@swift-ci Please test

@rajbarik
Copy link
Contributor

rajbarik commented Oct 3, 2019

@swift-ci Smoke test

@rajbarik
Copy link
Contributor

rajbarik commented Oct 3, 2019

@aschwaighofer @compnerd @aschwaighofer @rjmccall This looks good now and I am merging it.

@rajbarik rajbarik merged commit 333f0db into swiftlang:master Oct 3, 2019
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.

6 participants