This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Don't report error if undefined symbol is not used anywhere
ClosedPublic

Authored by evgeny777 on Oct 4 2016, 8:41 AM.

Details

Summary

The situation when undefined symbol is not used often takes place, when compiler flags -ffunction-sections -fdata-sections are used in conjunction with linker flag --gc-sections.
In such case we can have undefined symbol which is used by some function collected by linker GC. Both gold and ld add undefined symbol to symtab without reporting any error or warning. This patch makes lld to emit warning instead of error in such cases.

Diff Detail

Repository
rL LLVM

Event Timeline

evgeny777 updated this revision to Diff 73488.Oct 4 2016, 8:41 AM
evgeny777 retitled this revision from to [ELF] Emit warning instead of error, when undefined symbol is not really used..
evgeny777 updated this object.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
ruiu added inline comments.Oct 4 2016, 9:20 AM
ELF/Relocations.cpp
560 ↗(On Diff #73488)

I don't think you need to record whether a symbol is used or not here to use the information later. Instead, you could print out a warning message directly from this context.

ELF/Writer.cpp
320 ↗(On Diff #73488)

Instead of adding a new bit to the symbol, I'd do this here.

// Ignore symbols in garbage-collected sections.
// We could report them, but we don't because GNU linkers don't.
if (Sym->symbol()->includeInDynsym())
  if (auto *D = dyn_cast<DefinedRegular<ELFT>(Sym))
    if (!D->Section.Live)
      return;
320 ↗(On Diff #73488)

Ignore this comment -- I deleted it before sending a message but it wasn't removed for some reason.

evgeny777 added inline comments.Oct 4 2016, 9:24 AM
ELF/Relocations.cpp
560 ↗(On Diff #73488)

Can you please elaborate? If symbol is not a target of any reloc then I won't see it here, will I?

ruiu added inline comments.Oct 4 2016, 9:27 AM
ELF/Relocations.cpp
560 ↗(On Diff #73488)

If Body is an undefined symbol we want to warn/error here, no? Then undefined and unreferenced symbols will be ignored completely.

evgeny777 added inline comments.Oct 4 2016, 9:31 AM
ELF/Relocations.cpp
560 ↗(On Diff #73488)

Do you want to call reportUndefined() here like this:

if (Body.isUndefined())
  reportUndefined(&Body);

I'll check if this works.

evgeny777 updated this revision to Diff 73623.Oct 5 2016, 4:42 AM
evgeny777 retitled this revision from [ELF] Emit warning instead of error, when undefined symbol is not really used. to [ELF] Don't report error if undefined symbol is not used anywhere.
evgeny777 removed rL LLVM as the repository for this revision.

Addressed review comments

ruiu accepted this revision.Oct 5 2016, 10:55 AM
ruiu edited edge metadata.

LGTM

ELF/Relocations.cpp
523 ↗(On Diff #73623)

Change the type from SymbolBody * to SymbolBody &.

This revision is now accepted and ready to land.Oct 5 2016, 10:55 AM
This revision was automatically updated to reflect the committed changes.