[5.7][Autolink Extract] Filter out common Swift libraries from being linked more than once #59115
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of #59063
• Explanation: #58380 brought up an issue of excessive memory consumption at link-time on Linux. The cause of memory-consumption explosion appears to be due to the linker invocation command having duplicated
-lxxx
flags which come from theswift-autolink-extract
tool which aggregates auto-linking directives across all input object files. For common Swift libraries that every Swift object file links (e.g.swiftCore
) this means that they appear on the linker invocation as many times as the number of object files in the project. Which for large projects means possibly thousands of times. The linker is not able to de-duplicate these flags because duplicate linked libraries in a certain order has a semantic meaning, and apparently it loads them into memory as many times as they appear on the linker command-line. This change addresses this issue at least partially by making sure that the common Swift libraries, at least, are de-duplicated across all object files and are only linked once:SwiftCore
,SwiftOnoneSupport
, andSwiftConcurrency
.• Scope of Issue: High memory consumption when building modules with many object files on Linux.
• Risk: Low, this change only filters common Swift libraries and should leave behavior of other linked libraries largely unchanged.
• Automated Testing: Automated test added to the compiler test suite