Skip to content

Allow running tests when stdlib is built with LTO by working around auto-linking #34975

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
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,21 @@ if run_vendor == 'apple':
config.resource_dir_opt = "-resource-dir %s" % new_resource_dir
lit_config.note('Using freestanding resource dir: ' + new_resource_dir)

# Auto-linking does not work when stdlib is built with LTO, because linked
# libraries are discovered too late (after optimizations are applied). Let's
# explicitly link all libraries needed in tests.
#
# Note that this won't work on Linux (without LLD). The autolinking
# mechanism on Linux will fail due to needing -L arguments to the path even
# with this forced linking as the extracted commands will force the linker
# to look up the linking by name as well.
if "stdlib_lto" in config.available_features:
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 this really needs a comment explaining that this won't work on Linux (without LLD). The autolinking mechanism on Linux will fail due to needing -L arguments to the path even with this forced linking as the extracted commands will force the linker to look up the linking by name as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you expand on this a bit? I thought we're already passing in -L to the resource dir. Why is Linux different from Darwin here? Forgive my ignorance, please :)

Copy link
Member

Choose a reason for hiding this comment

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

It isn't the resource dir that is always the location for the library - the resource dir is meant for a small subset of libraries, those which are needed by the compiler directly (i.e. stdlib). The other libraries can be anywhere. The autolink only indicates that the library must be linked, not where to find it. The normal lookup order/path applies for the resolution of linked libraries, even when auto-linked. LLD will encode the -l... just as much as what we do now, so ultimately, the normal linker search rules apply.

for library in ["swiftCore", "swiftStdlibUnittest",
"swiftSwiftPrivateLibcExtras", "swiftSwiftPrivate",
"swiftDarwin", "swiftSwiftPrivateThreadExtras",
"swiftSwiftOnoneSupport"]:
swift_execution_tests_extra_flags += ' -Xlinker -l%s'% library

xcrun_prefix = (
"xcrun --toolchain %s --sdk %r" %
(config.darwin_xcrun_toolchain, config.variant_sdk))
Expand Down
3 changes: 3 additions & 0 deletions test/lit.site.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ if '@SWIFT_TOOLS_ENABLE_LTO@'.lower() in ['full', 'thin']:
else:
config.available_features.add('no_lto')

if '@SWIFT_STDLIB_ENABLE_LTO@'.lower() in ['full', 'thin']:
config.available_features.add('stdlib_lto')

if "@LLVM_ENABLE_ASSERTIONS@" == "TRUE":
config.available_features.add('asserts')
else:
Expand Down