rustc_trans: Link archives with --whole-archive
#19183
Closed
+67
−47
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.
If archives are passed to linker, linker does not add all object files
but instead scans each object in archive then adds it only if it
defines some symbols which has been undefined.
It is problematic when rlib needs to be contained in dylib, since
some portion of rlib is stripped out if unused by dylib itself.
This patch uses
--whole-archive
flag which changes linker behaviorthat the linker just adds all objects in archive.
Unfortunately, ld does not accept rlib as-is because it contains
non-object files, so they are manually removed before passed to ld.
Also, this change can be problematic if several archives actually
contain same symbol. For example, this patch breaks code like:
Previously it worked because linker stripped out
cfoo
.Fixes #14344