This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Prevent LTO stripping of wrapped script-referenced symbols
ClosedPublic

Authored by smeenai on Apr 25 2022, 11:02 PM.

Details

Summary

After 1af25a986069f2ae8c724133fa8649bb795a7925, we stop unconditionally
retaining wrapped symbols, which means that LTO's summary-based global
dead stripping can eliminate them even if they'll be referenced by a
linker script after the wrapping is performed. Mark symbols referenced
in linker scripts as referenced in addition to isUsedInRegularObj in
order for the wrapping logic to correctly set referencedAfterWrap and
prevent LTO from eliminating them.

An alternative would have been to change the referencedAfterWrap logic
to look at isUsedInRegularObj in addition to referenced, but
isUsedInRegularObj is also set in other places (e.g. for the entry
symbol), and it's not clear that we want referencedAfterWrap to take
all those places into account, so it seemed better to keep that logic
as-is and instead set referenced for linker script-referenced symbols.

Diff Detail

Event Timeline

smeenai created this revision.Apr 25 2022, 11:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 11:02 PM
smeenai requested review of this revision.Apr 25 2022, 11:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2022, 11:02 PM
MaskRay added inline comments.Apr 26 2022, 6:29 PM
lld/test/ELF/lto/wrap-script-referenced.ll
10

The more common suffixes are .lds, .t, and .script

16

Change the section index to [[#]]

24
smeenai updated this revision to Diff 425387.Apr 26 2022, 6:38 PM
smeenai marked 3 inline comments as done.

Address review comments

in order for the wrapping logic to correctly set referencedAfterWrap and prevent LTO from eliminating them.

Perhaps elaborate which symbol's referencedAfterWrap is set (sym's).

MaskRay accepted this revision.Apr 26 2022, 6:41 PM

LGTM.

This revision is now accepted and ready to land.Apr 26 2022, 6:41 PM
This revision was landed with ongoing or failed builds.Apr 26 2022, 6:49 PM
This revision was automatically updated to reflect the committed changes.

in order for the wrapping logic to correctly set referencedAfterWrap and prevent LTO from eliminating them.

Perhaps elaborate which symbol's referencedAfterWrap is set (sym's).

Thanks for the quick review. I updated the wording in the commit message before pushing.