This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Add an lld specific option /includeoptional
ClosedPublic

Authored by mstorsjo on Jun 6 2019, 1:04 PM.

Details

Summary

This works like /include, but is not fatal if the requested symbol wasn't found. This allows implementing the GNU ld option -u.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Jun 6 2019, 1:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2019, 1:04 PM
ruiu added a comment.Jun 7 2019, 1:28 AM

Our algorithm for the ELF -u option is as follows:

  1. resolve all symbols normally
  2. for each symbol given by -u, look up the symbol table, and if a returned symbol is a lazy symbol, call fetch

This way seems better than the way how it is implemented in this patch for the following two reasons:

  1. we don't need any Config member as -u option values are consumed in-place
  2. The cost of -u is proportional to the number of -u options instead of the number of (undefined) symbols
mstorsjo marked an inline comment as done.Jun 7 2019, 1:41 AM
mstorsjo added inline comments.
COFF/SymbolTable.cpp
247 ↗(On Diff #203426)

This won't do the right thing, if there actually are proper undefined to the same symbol as well. Any ideas/suggestions, @rnk @ruiu?

ruiu added a comment.Jun 7 2019, 2:40 AM

I guess that my previous comment addresses the issue?

I guess that my previous comment addresses the issue?

Yes, probably - thanks!

Since we fetch objects iteratively in the COFF linker, we probably need to wait until the normal link has converged, then fetch lazy objs for -u, and then keep iterating until it converges again?

ruiu added a comment.Jun 7 2019, 4:25 AM

I guess that my previous comment addresses the issue?

Yes, probably - thanks!

Since we fetch objects iteratively in the COFF linker, we probably need to wait until the normal link has converged, then fetch lazy objs for -u, and then keep iterating until it converges again?

Yeah, I guess so. Technically, fetching an object file can add a new archive to the input file set via a .drctive section which could in turn make other -u symbols can be resolved, so we need to iterate the whole process until it converges. That said, I don't think we have to cover that case though.

mstorsjo updated this revision to Diff 203596.Jun 7 2019, 12:32 PM

Adjusted to make it work more like how this is implemented in the ELF linker; still failing (and properly so) if there's real undefined references to a symbol that was requested with the new option (-u in GNU ld).

ruiu accepted this revision.Jun 7 2019, 7:43 PM

LGTM

COFF/Driver.cpp
1687–1690 ↗(On Diff #203596)

I think you can write them in one line

if (auto *Sym = dyn_cast_or_null<Lazy>(Symtab->find(Arg->getValue()))
COFF/Options.td
170 ↗(On Diff #203596)

We use the same spellings for identifiers representing a symbol name, so I'd name this include_optional.

This revision is now accepted and ready to land.Jun 7 2019, 7:43 PM
This revision was automatically updated to reflect the committed changes.