This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Keep non-prevailing (linkonce|weak)_odr symbols live
ClosedPublic

Authored by trentxintong on Oct 4 2018, 10:00 AM.

Details

Summary

If we have a symbol with (linkonce|weak)_odr linkage, we do not want
to dead strip it even it is not prevailing.

IR level (linkonce|weak)_odr symbol can become non-prevailing when we mix
ELF objects and IR objects where the (linkonce|weak)_odr symbol in the ELF
object is prevailing and the ones in the IR objects are not. Stripping
them will prevent us from doing optimizations with them.

By not dead stripping them, We will convert these symbols to
available_externally linkage as a result of non-prevailing and eventually
dropping them after inlining.

I modified cache-prevailing.ll to use linkonce linkage as it is
testing whether cache prevailing bit is effective or not, not
we should treat linkonce_odr alive or not

Diff Detail

Repository
rL LLVM

Event Timeline

trentxintong created this revision.Oct 4 2018, 10:00 AM

This seems reasonable - we should be able to keep ODR non-prevailing defs around to optimize with. I assume this is a missed optimization fix and not a correctness fix (i.e. the build currently succeeds and builds a correct binary)? Question about that below.

lib/Transforms/IPO/FunctionImport.cpp
746 ↗(On Diff #168325)

Are you fixing another instance of PR36483? If not, then the comment should probably be updated to indicate that this is to fix a missed optimization.

trentxintong added inline comments.Oct 5 2018, 11:00 AM
lib/Transforms/IPO/FunctionImport.cpp
746 ↗(On Diff #168325)

Hi Teresa

Thank you for the comment.

We have some linkonceodr symbols that are included in multiple files, one of the files is compiled to ELF object file directly which makes the ones in the IR object non-prevailing.

Originally we crashed because the IR level vtable (linkonce_odr linkage) is not prevailing and WPD crashed. This should be prevented by https://reviews.llvm.org/D52175.

So at this point, this patch is more to improve a missed optimization opportunity than fix a crash. I have the comment "or limit optimization opportunities" in the comment.

trentxintong added inline comments.Oct 7 2018, 6:39 PM
lib/Transforms/IPO/FunctionImport.cpp
746 ↗(On Diff #168325)

This also applies to other vague odr symbols we see with template functions, etc.

This revision is now accepted and ready to land.Oct 8 2018, 8:08 AM
This revision was automatically updated to reflect the committed changes.