This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Scan lazy linkerscipt symbols early.
AbandonedPublic

Authored by grimar on Feb 21 2017, 4:29 AM.

Details

Reviewers
ruiu
rafael
Summary

This is PR32026, we have next issue currently:

If script has a symbol assignment, for example PROVIDE(foo = 5)
and that foo is a lazy symbol. Then code that invokes processCommands()...addSymbol(Cmd);
will fetch that archive much later than we expect to see new sections to appear.

We have next code and comment:

void LinkerDriver::link(opt::InputArgList &Args) {
..
  // Now that we have a complete list of input files.
  // Beyond this point, no new files are added.

But that comment becomes not true in that case. We are adding new sections
from that archive for processing foo much later. Also if object where foo lives contains
mergeable section, then code that do splitIntoPieces() is completely skipped,
also this section is not merged into synthetic output section, because we doo that early.

To avoid that, patch implement early scan of assignments.
One of problems is that it does not support symbols definitions inside sections declarations,
like: ".foo : { ...; bar = .; }". It is complicated to implement those because we still need to filter
out sections not matching the constraints, so cant just add such symbols early like I did in this patch for
symbols outside. (Though I am not sure such symbols are really used in real livfe)

I think best way to implement it (if we want) is the next:
As an alternative solution probably we can reimplement handling of mergeable sections
and do not merge them into synthetics early, just like D29223 did.
I think that way later addition of sections and files will not be a problem, we should be
able to invoke merging and splitIntoPieces() from script side when we need it.
That way support of symbols like bar from above should be easy, though that complicates
the implementation of other parts, not sure if we want it now.

Diff Detail

Event Timeline

grimar updated this revision to Diff 89189.Feb 21 2017, 4:29 AM
grimar created this revision.
  • Removed unused include
grimar updated this revision to Diff 89214.Feb 21 2017, 7:45 AM
  • Simplified testcase.
ruiu edited edge metadata.Feb 21 2017, 10:24 AM

As to this patch, pulling out an object file is not a right thing to do here. A rule of thumb is that you should fetch an object file from an archive only when otherwise the link would fail because of an undefined symbol. This is not the case.

grimar abandoned this revision.Feb 22 2017, 12:23 AM

This one incorrect, D30224 was correct way of fixing it.