diff options
| author | Igor Kudrin <ikudrin.dev@gmail.com> | 2015-10-01 18:02:21 +0000 |
|---|---|---|
| committer | Igor Kudrin <ikudrin.dev@gmail.com> | 2015-10-01 18:02:21 +0000 |
| commit | 2696bbeb93acf67734fe1310ef3d643ab377deba (patch) | |
| tree | d3cb94cf9f5dcdba83eabc4dfa79031cb9c8c2b8 /lld/ELF/InputFiles.cpp | |
| parent | 8adbded6a4d39ce474995847046a8921b57230e2 (diff) | |
| download | bcm5719-llvm-2696bbeb93acf67734fe1310ef3d643ab377deba.tar.gz bcm5719-llvm-2696bbeb93acf67734fe1310ef3d643ab377deba.zip | |
[ELF2] Add --[no-]whole-archive command line switches
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.
Reviewers: rafael, ruiu
Subscribers: grimar, llvm-commits
Projects: #lld
Differential Revision: http://reviews.llvm.org/D13286
llvm-svn: 249045
Diffstat (limited to 'lld/ELF/InputFiles.cpp')
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index cc7bbaa9216..5eabb298c2a 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -181,10 +181,14 @@ SymbolBody *elf2::ObjectFile<ELFT>::createSymbolBody(StringRef StringTable, } } -void ArchiveFile::parse() { +static std::unique_ptr<Archive> openArchive(MemoryBufferRef MB) { ErrorOr<std::unique_ptr<Archive>> ArchiveOrErr = Archive::create(MB); error(ArchiveOrErr, "Failed to parse archive"); - File = std::move(*ArchiveOrErr); + return std::move(*ArchiveOrErr); +} + +void ArchiveFile::parse() { + File = openArchive(MB); // Allocate a buffer for Lazy objects. size_t NumSyms = File->getNumberOfSymbols(); @@ -211,6 +215,20 @@ MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) { return *Ret; } +std::vector<MemoryBufferRef> ArchiveFile::getMembers() { + File = openArchive(MB); + + std::vector<MemoryBufferRef> Result; + for (const Archive::Child &Child : File->children()) { + ErrorOr<MemoryBufferRef> MbOrErr = Child.getMemoryBufferRef(); + error(MbOrErr, + Twine("Could not get the buffer for a child of the archive ") + + File->getFileName()); + Result.push_back(MbOrErr.get()); + } + return Result; +} + template <class ELFT> SharedFile<ELFT>::SharedFile(MemoryBufferRef M) : SharedFileBase(getStaticELFKind<ELFT>(), M), ELFData<ELFT>(M) {} |

