-
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
Changes from all commits
64b3d88
d466883
d11704b
51f6e9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Make sure that the platform-appropriate clang_rt library (found relative to | ||
// the compiler) is included when using Swift as a linker (with Apple targets). | ||
|
||
// We use hard links to make sure the Swift driver really thinks it's been | ||
// moved. | ||
|
||
// RUN: rm -rf %t | ||
// RUN: %empty-directory(%t/bin) | ||
// RUN: %hardlink-or-copy(from: %swift_driver_plain, to: %t/bin/swiftc) | ||
// RUN: %empty-directory(%t/lib/clang/darwin/) | ||
|
||
// RUN: %t/bin/swiftc -driver-print-jobs -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix CHECK-NO-RUNTIME %s | ||
|
||
// RUN: touch %t/lib/clang/darwin/libclang_rt.osx.a %t/lib/clang/darwin/libclang_rt.ios.a %t/lib/clang/darwin/libclang_rt.tvos.a %t/lib/clang/darwin/libclang_rt.watchos.a | ||
|
||
// RUN: %t/bin/swiftc -driver-print-jobs -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix MACOS %s | ||
|
||
// RUN: %t/bin/swiftc -driver-print-jobs -target i386-apple-ios7 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix IOS %s | ||
// RUN: %t/bin/swiftc -driver-print-jobs -target x86_64-apple-ios7 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix IOS %s | ||
// RUN: %t/bin/swiftc -driver-print-jobs -target armv7s-apple-ios7 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix IOS %s | ||
// RUN: %t/bin/swiftc -driver-print-jobs -target arm64-apple-ios7 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix IOS %s | ||
|
||
// RUN: %t/bin/swiftc -driver-print-jobs -target x86_64-apple-ios9 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix TVOS %s | ||
// RUN: %t/bin/swiftc -driver-print-jobs -target arm64-apple-tvos9 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix TVOS %s | ||
|
||
// RUN: %t/bin/swiftc -driver-print-jobs -target i386-apple-watchos2 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix WATCHOS %s | ||
// RUN: %t/bin/swiftc -driver-print-jobs -target armv7k-apple-watchos2 %S/../Inputs/empty.swift | %FileCheck -check-prefix CHECK -check-prefix WATCHOS %s | ||
|
||
// Clean up the test executable because hard links are expensive. | ||
// RUN: rm -f %t/bin/swiftc | ||
|
||
// CHECK: bin/ld{{"? }} | ||
// CHECK-NO-RUNTIME-NOT: libclang_rt | ||
// CHECK-MACOS-SAME: {{[^ ]+/lib/clang/darwin/libclang_rt.osx.a}} | ||
// CHECK-IOS-SAME: {{[^ ]+/lib/clang/darwin/libclang_rt.ios.a}} | ||
// CHECK-TVOS-SAME: {{[^ ]+/lib/clang/darwin/libclang_rt.tvos.a}} | ||
// CHECK-WATCHOS-SAME: {{[^ ]+/lib/clang/darwin/libclang_rt.watchos.a}} | ||
// CHECK-SAME: -o {{[^ ]+}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
platform.system().lower()) | ||
source_compiler_rt_libs(compiler_rt_dir) | ||
|
||
def check_runtime_libs(features_to_check): | ||
for lib in config.compiler_rt_libs: | ||
|
@@ -967,6 +968,17 @@ if run_ptrsize != "32": | |
|
||
check_runtime_libs(runtime_libs) | ||
|
||
# From https://stackoverflow.com/a/2393022 | ||
def strip_right(text, suffix): | ||
if not text.endswith(suffix): | ||
return text | ||
return text[:len(text)-len(suffix)] | ||
|
||
base_runtime_lib_name = ( | ||
'libclang_rt.' + strip_right(config.compiler_rt_platform, 'sim') + '.a') | ||
if os.path.exists(make_path(compiler_rt_dir, base_runtime_lib_name)): | ||
config.available_features.add('c_runtime') | ||
|
||
if not getattr(config, 'target_run_simple_swift', None): | ||
config.target_run_simple_swift = ( | ||
'%%empty-directory(%%t) && ' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdbool.h> | ||
|
||
static inline bool isRunningOnFairlyRecentOS() { | ||
if (__builtin_available(macOS 10.12, iOS 10, tvOS 10, watchOS 3, *)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// RUN: %target-build-swift -emit-executable %s -import-objc-header %S/Inputs/clang_rt-helper.h -o %t | ||
|
||
// REQUIRES: c_runtime | ||
|
||
// Just make sure we can build and link successfully. | ||
|
||
if isRunningOnFairlyRecentOS() { | ||
print("new!") | ||
} else { | ||
print("old...") | ||
} |
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 thisconstructInvocation
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.