Skip to content

[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

Merged
merged 4 commits into from
Jul 12, 2018

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Jul 9, 2018

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

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
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2018

Build failed
Swift Test OS X Platform
Git Sha - 64b3d88

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 64b3d88

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 64b3d88

@jrose-apple
Copy link
Contributor Author

swiftlang/swift-source-compat-suite#213
@swift-ci Please test source compatibility

Copy link
Contributor

@davidungar davidungar left a 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.

case DarwinPlatformKind::IPhoneOSSimulator:
if (distinguishSimulator)
return "iossim";
LLVM_FALLTHROUGH;
case DarwinPlatformKind::IPhoneOS:
return "ios";
Copy link
Contributor

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));

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -0,0 +1,36 @@
// REQUIRES: OS=macosx
Copy link
Contributor

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',
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explain what why?

Copy link
Contributor

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.)

Copy link
Contributor Author

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tx!

Copy link
Contributor

@davidungar davidungar left a 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!
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - d466883

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - d466883

@jrose-apple jrose-apple merged commit b02d554 into swiftlang:master Jul 12, 2018
@jrose-apple jrose-apple deleted the batteries-included branch July 12, 2018 00:35
jrose-apple added a commit to jrose-apple/swift that referenced this pull request Jul 12, 2018
[Driver] Always link compiler_rt on Darwin (when available)

rdar://problem/41911599
(cherry picked from commit b02d554)
jrose-apple added a commit that referenced this pull request Jul 12, 2018
[Driver] Always link compiler_rt on Darwin (when available)

rdar://problem/41911599
(cherry picked from commit b02d554)
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.

3 participants