This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Create and export symbols provided by a linker script if they referenced by DSOs.
ClosedPublic

Authored by ikudrin on Feb 7 2018, 2:39 AM.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

ikudrin created this revision.Feb 7 2018, 2:39 AM
grimar added inline comments.Feb 7 2018, 4:10 AM
ELF/InputFiles.h
347

It seems like instead of adding global variable you can make helper that
would scan over SharedFiles and invoke SharedFile::getUndefinedSymbols
to build the same set and then pass it to shouldDefineSym ?

ikudrin added inline comments.Feb 7 2018, 8:08 PM
ELF/InputFiles.h
347

We call shouldDefineSym not only in declareSymbols but also in addSymbol, which might be called several times. As a result, the set itself would be created several times.

Moreover, SharedFiles requires a template argument, so all involved methods would become templates too.

I thought about keeping PROVIDE symbols which are not created during declareSymbols call. SymbolTable::scanShlibUndefined would then ask LinkerScript to create referenced symbols. However, it looks like blurring of responsibility to me.

grimar added inline comments.Feb 8 2018, 2:09 AM
ELF/InputFiles.h
347

Probably getUndefinedSymbols can be moved to InputFile with corresponding member.
And then it can assert that it is called only for SharedKind, like we do in other methods there.
We already moved some functionality to InputFile to avoid dealing with templates before.

I do not think building of such set is very expensive and so it should be ok to do that twice.
In processSectionCommands and in declareSymbols.

It is also seems that after landing D43008 it should be possible to remove call from 'addSymbol`.
Since declareSymbols sets Cmd->Sym, I think addSymbol can probably do

if (!Cmd->Sym)
  return;

instead of

if (!shouldDefineSym(Cmd))
  return;

I did not try it though. But at least such approach avoids introducing one more global variable
and looks more like a correct direction IMO.

ikudrin updated this revision to Diff 133567.Feb 8 2018, 10:24 PM
  • Move Undefs and getUndefinedSymbols() into InputFile
  • Change type of Undefs to DenseSet<StringRef> so that it can be used to search for the symbol without creating another filter container.
grimar accepted this revision.Feb 9 2018, 6:31 AM

This LGTM, thanks (minor nit below).
Please wait for approval from other reviewers.

ELF/LinkerScript.cpp
134

You should be able to use count I believe:

for (InputFile *F : SharedFiles)
  if (F->getUndefinedSymbols().count(Cmd->Name))
    return true;
This revision is now accepted and ready to land.Feb 9 2018, 6:31 AM
ikudrin updated this revision to Diff 135006.Feb 19 2018, 10:04 PM
  • Use DenseSet<>::count(), as George suggested.
espindola accepted this revision.Feb 26 2018, 2:24 PM
This revision was automatically updated to reflect the committed changes.