This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Fix handling of weak interposable symbols
ClosedPublic

Authored by tejohnson on Aug 14 2019, 5:21 PM.

Details

Summary

Keep aliasees alive if their alias is live, otherwise we end up with an
alias to a declaration, which is invalid. This can happen when the
aliasee is weak and non-prevailing.

This fix exposed the fact that we were then attempting to internalize
the weak symbol, which was not exported as it was not prevailing. We
should not internalize interposable symbols in general, unless this is
the prevailing copy, since it can lead to incorrect inlining and other
optimizations. Most of the changes in this patch are due to the
restructuring required to pass down the prevailing callback.

Finally, while implementing the test cases, I found that in the case of
a weak aliasee that is still marked not live because its alias isn't
live, after dropping the definition we incorrectly marked the
declaration with weak linkage when resolving prevailing symbols in the
module. This was due to some special case handling for symbols marked
WeakLinkage in the summary located before instead of after a subsequent
check for the symbol being a declaration. It turns out that we don't
actually need this special case handling any more (looking back at the
history, when that was added the code was structured quite differently)

  • we will correctly mark with weak linkage further below when the

definition hasn't been dropped.

Fixes PR42542.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson created this revision.Aug 14 2019, 5:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2019, 5:21 PM
pcc accepted this revision.Aug 19 2019, 5:12 PM

LGTM

This would also be fixed by switching to canonical aliases, right? Maybe another data point in favour of finally switching.

lib/Transforms/IPO/FunctionImport.cpp
911–912 ↗(On Diff #215291)

Unintentional?

942–943 ↗(On Diff #215291)

Ditto

This revision is now accepted and ready to land.Aug 19 2019, 5:12 PM
tejohnson marked 3 inline comments as done.Aug 23 2019, 7:50 AM
In D66264#1636359, @pcc wrote:

LGTM

This would also be fixed by switching to canonical aliases, right? Maybe another data point in favour of finally switching.

Yes, the alias issues would.

lib/Transforms/IPO/FunctionImport.cpp
911–912 ↗(On Diff #215291)

Yep, forgot to remove. Cleaned up here and below.

tejohnson updated this revision to Diff 216848.Aug 23 2019, 7:50 AM
tejohnson marked an inline comment as done.

Remove inadvertant debugging code.

This revision was automatically updated to reflect the committed changes.