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

Conversation

kubamracek
Copy link
Contributor

No description provided.

@kubamracek kubamracek requested a review from compnerd December 5, 2020 00:34
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Dec 8, 2020

@swift-ci please test Windows platform

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

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

Resurrecting this old PR, because the problem is still present. At least with ld64 (and possibly other linkers too?), auto-linking doesn't play well with LTO. I have requested fixes from the linker, but to unblock progress (towards enabling LTO on the stdlib on the "minimal" build preset) I'd like to propose to go forward with this workaround.

@compnerd Any chance you could once more explain the Linux linking specifics here? For now, I have included your comment verbatim, but I don't really follow tbh 😃

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 36e0bf48dcef7de7f9e361e084c6a82b138fce06

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@compnerd gentle ping :)

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Discussed with @kubamracek offline; with some minor tweaks to the comment, this seems fine.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6b7971c

@kubamracek
Copy link
Contributor Author

@swift-ci please test macOS platform

@kubamracek kubamracek merged commit 6cb4568 into swiftlang:main Sep 18, 2021
@kubamracek kubamracek deleted the lto-tests branch September 18, 2021 22:19
@kubamracek
Copy link
Contributor Author

I accidentally clicked "merge" before pushing the comment change, sorry about that 😞 Fixing that here: #39362

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