This is an archive of the discontinued LLVM Phabricator instance.

ModuleLinker: Import linkonce even when they have no use
Needs ReviewPublic

Authored by mehdi_amini on Apr 26 2016, 3:44 AM.
This revision needs review, but all specified reviewers are disabled or inactive.

Details

Reviewers
espindola
Summary

If the linker decided that LTO is supposed to provide the
"Prevailing" definition for a symbol, and ask the symbol
to be "preserved", then we should honor it and make sure
the symbol is emitted.
Here we import useless definition in some cases, but we
can rely on GlobalDCE to delete them after (unless the
linker requested us to preserve them).

A bunch of tests are failing:

Failing Tests (5):

LLVM :: Linker/comdat12.ll
LLVM :: Linker/internalize-lazy.ll
LLVM :: Linker/only-needed-named-metadata.ll
LLVM :: Linker/pr21494.ll
LLVM :: tools/lto/hide-linkonce-odr.ll

So I'm not sure at this point this is the right fix, but I'm
eager to get feedback on how to solve this.

Diff Detail

Event Timeline

mehdi_amini retitled this revision from to ModuleLinker: Import linkonce even when they have no use.
mehdi_amini updated this object.
mehdi_amini added a reviewer: rafael.
mehdi_amini added a subscriber: llvm-commits.
rafael edited edge metadata.Apr 26 2016, 7:55 AM

So, I assume this is because of a mixed (MachO + BC) lto, right?

If so it seems the lib/LTO version of https://llvm.org/bugs/show_bug.cgi?id=19901.

This change as is would probably be undesirable for some users. I see two ways of solving a pr19901 like problem that are a bit more light weight:

  • Add a new API to lib/LTO where the linker is required to pass *all* necessary symbols is a separate list. Pass that as GlobalsToImport.
  • Add a flag that say that instead of the current "if and only if" handling of GlobalsToImport, it should be just "if". That is, anything in GlobalsToImport is imported, but so is anything that would be imported by the current logic. This should not require a new lib/LTO api.
espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 10:51 AM