This is an archive of the discontinued LLVM Phabricator instance.

[lld/mac] Fix mislink with ICF
ClosedPublic

Authored by thakis on Oct 29 2021, 7:32 PM.

Details

Reviewers
gkm
int3
Group Reviewers
Restricted Project
Commits
rG2d48b1913672: [lld/mac] Fix mislink with ICF
Summary

When comparing relocations against two symbols, ICF's equalsConstant() did not
look at the value of the two symbols. With subsections_via_symbols, the value
is usually 0 but not always: In particular, it isn't 0 for constants in string
and literal sections. Since we ignored the value, comparing two constant string
symbols or two literal symbols always compared the 0th's element, so functions
in the same TU always compared as equal.

This can cause mislinks, and with -dead_strip crashes.

Fixes PR52349, see that bug for lots of details and examples of mislinks.

While here, make the existing assembly in icf-literals.s a bit more realistic
(use leaq instead of movq with strings, and use foo(%rip) instead of
foo@gotpcrel(%rip)). This has no interesting effect, it just maybe makes the
test look a bit less surprising.

Diff Detail

Event Timeline

thakis created this revision.Oct 29 2021, 7:32 PM
Herald added a project: Restricted Project. · View Herald Transcript
thakis requested review of this revision.Oct 29 2021, 7:32 PM
int3 accepted this revision.Oct 30 2021, 1:34 PM
int3 added a subscriber: int3.

Oof, yeah, this was quite an oversight. Thanks for the fix!

This revision is now accepted and ready to land.Oct 30 2021, 1:34 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 30 2021, 3:59 PM
int3 added a comment.Feb 18 2022, 8:26 AM

Heh, I belatedly realized that I'd put up a similar fix in D106214: [lld-macho] ICF: Fold some sections with differing addends, but never got it reviewed / landed...