This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] Add --[no-]whole-archive command line switches
ClosedPublic

Authored by ikudrin on Sep 30 2015, 6:06 AM.

Details

Summary

If --whole-archive is used, all symbols from the following archives are added to the output. --no-whole-archive restores default behavior. These switches can be used multiple times.

NB. We have to keep an ArchiveFile instance within SymbolTable even if --whole-archive mode is active since it can be a thin archive which contains just names of external files. In that case actual memory buffers for the archive members will be stored within the File member of ArchiveFile class.

Diff Detail

Event Timeline

ikudrin updated this revision to Diff 36091.Sep 30 2015, 6:06 AM
ikudrin retitled this revision from to [ELF2] Add --[no-]whole-archive command line switches.
ikudrin updated this object.
ikudrin added reviewers: rafael, ruiu.
ikudrin added a project: lld.
ikudrin added a subscriber: llvm-commits.
grimar added a subscriber: grimar.Sep 30 2015, 9:13 AM
grimar added inline comments.
ELF/Driver.cpp
147

There is no default section. Not sure is is necessarily to use though since I guess warning about that is turned off in most cases.

ELF/InputFiles.cpp
210

Looks like that assert should be at first line. Also that would be consistent with ArchiveFile::getMembers()

ruiu added inline comments.Sep 30 2015, 10:39 AM
ELF/InputFiles.cpp
223–224

We don't have this assertion at other places in this file, so we shouldn't have this one as well. Also, nullptr != something looks inconsistent.

ELF/SymbolTable.cpp
31

You want to avoid calling parse() on an archive file if Config->WholeArchive to keep the existing behavior of parse().

ikudrin updated this revision to Diff 36213.Oct 1 2015, 3:34 AM
  • Updated to the top.
  • Addressed review comments.
ikudrin marked 4 inline comments as done.Oct 1 2015, 3:34 AM
ruiu added inline comments.Oct 1 2015, 6:29 AM
ELF/InputFiles.cpp
183–186

The point is that we never want to call both parse() and getMembers() on the same ArchiveFile object. If you call getMembers() on an ArchiveFile, that's the end of that archive file, and we won't call any other member function after that.

Restore the original code here so that it sets this class' File pointer only when parse() is called. We don't have to set that pointer in getMembers().

186

I'd be easy to read if you write this way:

File = open(MB);

assuming you modify the function as

std::unique_ptr<Archive> open(MemoryBufferRef MB);
220–222

This guard should be removed. You can call either getMembers() or pares() but not both.

ELF/SymbolTable.cpp
34–35

Do not push archive file objects to the vector if WholeArchive is true. If --whole-archive is set, archive files are treated as if they did not exist.

36–37

Early return after this for-loop.

ikudrin added inline comments.Oct 1 2015, 6:46 AM
ELF/SymbolTable.cpp
34–35

If I understand it right, Archive::Child::getBuffer() can, under certain circumstances, create a new memory buffer and return its reference. This memory buffer is stored in the ThinBuffers member of the instance of Archive. That's why we need to hold Archive through holding ArchiveFile.

ikudrin updated this revision to Diff 36264.Oct 1 2015, 9:50 AM
  • Rebase to the top
  • Fix indentation
  • Sort switches
  • Slightly rework ArchiveFile && add explanations why we have to keep it
ruiu added inline comments.Oct 1 2015, 9:58 AM
ELF/InputFiles.cpp
206

Remove this comment.

ELF/SymbolTable.cpp
35–38

Is that true? MemoryBuffers are not freed until the end of Driver, so it should be safe if thin archives have references to MemoryBuffers.

36–37

Please return here.

ikudrin marked an inline comment as done.Oct 1 2015, 10:15 AM
ikudrin added inline comments.
ELF/SymbolTable.cpp
35–38

A thin archive holds just names of the external files. These files are opened and their memory buffers are stored within the instance of Archive class, not in Driver.

ruiu added inline comments.Oct 1 2015, 10:18 AM
ELF/SymbolTable.cpp
35–38

I see. Please note that in the commit message and remove this comment from here.

ikudrin updated this revision to Diff 36268.Oct 1 2015, 10:32 AM
ikudrin updated this object.
  • Addressed review comments
ikudrin updated this object.Oct 1 2015, 10:42 AM
ikudrin marked 5 inline comments as done.
ruiu accepted this revision.Oct 1 2015, 10:47 AM
ruiu edited edge metadata.

LGTM with a nit.

ELF/Options.td
47–48

"_" is smaller than "i" in ASCIIbetical order. Move this before noinhibit_exec.

This revision is now accepted and ready to land.Oct 1 2015, 10:47 AM
ikudrin closed this revision.Oct 1 2015, 11:04 AM