This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Appending linkage fixes
ClosedPublic

Authored by tejohnson on Dec 2 2015, 9:17 AM.

Details

Summary

Fix import from module with appending var, which cannot be imported. The
first fix is to remove an overly-aggressive error check.

The second fix is to deal with restructuring introduced to the module
linker yesterday in r254418. The handling in linkGlobalValueProto for
not linking in appending variables during function importing is coming
too late, when we are materializing decls. Add the same check to
linkIfNeeded. (Rafael, perhaps the checking in linkGlobalValueProto and
linkIfNeeded should be commoned? Also, I'm concerned about the case
where linkGlobalValueProto decides linkFromSrc==false and there is no
existing dest GV. Previously we would skip linking for that source GV,
but now we will create a decl in the dest module, as the early return
when "!LinkFromSrc && !DGV" has been removed from linkGlobalValueProto
due to the change in callsite. Are there other lurking issues?)

Test by Mehdi Amini.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson updated this revision to Diff 41640.Dec 2 2015, 9:17 AM
tejohnson retitled this revision from to [ThinLTO] Appending linkage fixes.
tejohnson updated this object.
tejohnson added reviewers: mehdi_amini, rafael.
tejohnson added a subscriber: llvm-commits.
rafael edited edge metadata.Dec 2 2015, 10:31 AM
rafael added a subscriber: rafael.

Can this be tested with llvm-link instead of opt? LGTM with that.

tejohnson updated this revision to Diff 41649.Dec 2 2015, 11:12 AM
tejohnson edited edge metadata.
  • Change test to be llvm-link based.
rafael accepted this revision.Dec 2 2015, 11:21 AM
rafael edited edge metadata.

LGTM with a nit.

test/Linker/funcimport_appending_global.ll
6 ↗(On Diff #41649)

Can you just pass %s to llvm-link and remove the llvm-as run?

This revision is now accepted and ready to land.Dec 2 2015, 11:21 AM
tejohnson added inline comments.Dec 2 2015, 11:25 AM
test/Linker/funcimport_appending_global.ll
6 ↗(On Diff #41649)

I can't because the .ll file doesn't have the function summary. Running llvm-as with the -function-summary option is required to get that, then llvm-lto creates the combined function index to drive importing.

mehdi_amini added inline comments.Dec 2 2015, 2:30 PM
lib/Linker/LinkModules.cpp
1867 ↗(On Diff #41649)

Found another crash:

ModuleLinker::run() will start by iterating over all the variables in the module and call linkIfNeeded(GV). Your fix here only kicks in if there is no "DGV" (why?).

If the destination module already have a global_ctors, DGV won't be null. We may want to fix getLinkedToGlobal() as well.

All of this logic gets more and more complicate, this is a bit scary.

tejohnson added inline comments.Dec 3 2015, 6:44 AM
lib/Linker/LinkModules.cpp
1867 ↗(On Diff #41649)

Right, for appending vars we shouldn't import regardless of DGV status. Fixed this, updated test, and removed the old handling in linkGlobalValueProto which is no longer needed as the check is moved here (consistent with other checks that moved from linkGlobalValueProto to linkIfNeeded in the restructuring earlier this week). I don't think the logic is getting more complicated, it has just moved as needed based on the restructuring.

tejohnson updated this revision to Diff 41750.Dec 3 2015, 6:44 AM
tejohnson edited edge metadata.
  • Handle case where dest module already has an appending linkage variable with the same name. Cleanup old handling.
This revision was automatically updated to reflect the committed changes.