-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Driver] Always link compiler_rt on Darwin #17843
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
Turns out it's needed for normal builtins that can appear in inlinable functions, including Objective-C's @available. Clang always links it unconditionally, so so should Swift. Note that this does mean you have to build compiler_rt to get a successful test run on Apple platforms. That was always true if you wanted the sanitizer tests to work, though. rdar://problem/41911599
@swift-ci Please test |
Build failed |
Tweak the tests to check this correctly.
@swift-ci Please test |
Build failed |
Build failed |
swiftlang/swift-source-compat-suite#213 |
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 know this isn't a huge change, but that constructInvocation function really needs to be broken up. All my other comments are optional. I realize this change is merely adding to the long function, but I would still feel so much better if you could take this opportunity to improve it.
lib/Driver/DarwinToolChains.cpp
Outdated
case DarwinPlatformKind::IPhoneOSSimulator: | ||
if (distinguishSimulator) | ||
return "iossim"; | ||
LLVM_FALLTHROUGH; | ||
case DarwinPlatformKind::IPhoneOS: | ||
return "ios"; |
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.
What you really want here IMO is Swift's switch on tuple, so you could switch on both.
Failing that, it would be nice to make the symmetry wrt distinguishSimulator
more apparent.
E.g.:
DarwinPlatformKind mapSimulatorToOS(DarwinPlatformKind kind) {
switch kind {
case DarwinPlatformKind::MacOS: return DarwinPlatformKind::MacOS
case IPhoneOSSimulator: return IPhoneOS
case IPhoneOS: return IPhoneOS
...
}
static StringRef
getDarwinLibraryNameSuffixForTriple(const llvm::Triple &triple,
bool distinguishSimulator = true) {
const DarwinPlatformKind kind = getDarwinPlatformKind(triple)
const DarwinPlatformKind effectiveKind = distinguishSimulator ? kind : mapSimulatorToOS(kind)
switch (effectiveKind) {
case DarwinPlatformKind::MacOS:
return "osx";
case DarwinPlatformKind::IPhoneOSSimulator:
return "iossim";
case DarwinPlatformKind::IPhoneOS:
return "ios";
...
}
I like this because IMO it reduces the possibility for future errors.
".a"); | ||
if (llvm::sys::fs::exists(CompilerRTPath)) | ||
Arguments.push_back(context.Args.MakeArgString(CompilerRTPath)); | ||
|
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.
The routine this is in, constructInvocation
is already too long for me to understand without breaking it down. At the least, it would be great to factor this paragraph out into a separate function. At best, in order to ease the way for others to work on this code, it would help a lot to break this constructInvocation
function down into smaller pieces.
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 definitely don't want to do that in a cherry-pick to 4.2, and I don't want to do it without a guiding principle for grouping arguments, which I don't think we have today.
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.
Ahh, yes, I understand about cherry-picking. Sigh. Will check the other box.
test/Driver/linker-clang_rt.swift
Outdated
@@ -0,0 +1,36 @@ | |||
// REQUIRES: OS=macosx |
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.
What is this test testing? What is essential vs incidental? Comments to that effect would be helpful.
@@ -945,8 +945,9 @@ def source_compiler_rt_libs(path): | |||
if lib.startswith('libclang_rt.') | |||
and config.compiler_rt_platform in lib]) | |||
|
|||
source_compiler_rt_libs(make_path(test_resource_dir, 'clang', 'lib', | |||
platform.system().lower())) | |||
compiler_rt_dir = make_path(test_resource_dir, 'clang', 'lib', |
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.
Would it be possible to add a comment to explain the why here?
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.
Explain what why?
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.
LOL! I need to add a comment to explain my request for a comment!
My thought was to add comments to this file to explain what is going on w.r.t. the new feature being added. (I know nothing about lit.cfg files and thought maybe there were breadcrumbs you could add.)
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.
This feels like another case where there's not a reasonable comment. This part didn't change, and the part below builds a path and tests if it exists.
@@ -0,0 +1,9 @@ | |||
#include <stdbool.h> | |||
|
|||
static inline bool testNewOS() { |
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.
Is this testing the OS, or testing the availability of the OS? If the latter, the current name could be improved.
|
||
// Just make sure we can build and link successfully. | ||
|
||
if testNewOS() { |
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.
Or maybe the name should be isTestingNewOS
?
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.
It's a dummy function and we don't run the code, so it doesn't actually matter, but sure.
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.
Tx!
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.
Too bad this will be cherry-picked and so too risky to bust up constructInvocation. Thanks for adding the other clarifications (i.e. comments, and refactoring the switch).
And use it in getDarwinLibraryNameSuffixForTriple, making the logic there clearer. Suggested by David U!
Per feedback from David U.
@swift-ci Please test |
@swift-ci Please test source compatibility |
Build failed |
Build failed |
[Driver] Always link compiler_rt on Darwin (when available) rdar://problem/41911599 (cherry picked from commit b02d554)
[Driver] Always link compiler_rt on Darwin (when available) rdar://problem/41911599 (cherry picked from commit b02d554)
Turns out it's needed for normal builtins that can appear in inlinable functions, including Objective-C's
@available
. Clang always links it unconditionally, so so should Swift.Note that this does mean you have to build compiler_rt to get a successful test run on Apple platforms. That was always true if you wanted the sanitizer tests to work, though.rdar://problem/41911599