diff options
author | Alexander Shaposhnikov <shal1t712@gmail.com> | 2018-09-11 22:00:47 +0000 |
---|---|---|
committer | Alexander Shaposhnikov <shal1t712@gmail.com> | 2018-09-11 22:00:47 +0000 |
commit | 72b27a6a397404f7c1faff7813e26fd1f84b6183 (patch) | |
tree | e549139fdbf460f5eb60f43ee685c7db84753508 /llvm/lib/Object/ArchiveWriter.cpp | |
parent | 26725bdc508f0c011e39f7ef0125e961d2ad76ed (diff) | |
download | bcm5719-llvm-72b27a6a397404f7c1faff7813e26fd1f84b6183.tar.gz bcm5719-llvm-72b27a6a397404f7c1faff7813e26fd1f84b6183.zip |
[object] Improve the performance of getSymbols used by ArchiveWriter
In this diff we adjust the code of getSymbols to avoid creating LLVMContext when it's not necessary.
Without this patch when the function getSymbols was called on a MachO object with a __bitcode section
it was parsing the embedded bitcode and then ignoring the result.
Test plan: make check-all
Differential revision: https://reviews.llvm.org/D51759
llvm-svn: 341998
Diffstat (limited to 'llvm/lib/Object/ArchiveWriter.cpp')
-rw-r--r-- | llvm/lib/Object/ArchiveWriter.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index ea17b2220a0..ebb00f8027d 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -372,20 +372,32 @@ static void writeSymbolTable(raw_ostream &Out, object::Archive::Kind Kind, static Expected<std::vector<unsigned>> getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject) { std::vector<unsigned> Ret; - LLVMContext Context; - Expected<std::unique_ptr<object::SymbolicFile>> ObjOrErr = - object::SymbolicFile::createSymbolicFile(Buf, llvm::file_magic::unknown, - &Context); - if (!ObjOrErr) { - // FIXME: check only for "not an object file" errors. - consumeError(ObjOrErr.takeError()); - return Ret; + // In the scenario when LLVMContext is populated SymbolicFile will contain a + // reference to it, thus SymbolicFile should be destroyed first. + LLVMContext Context; + std::unique_ptr<object::SymbolicFile> Obj; + if (identify_magic(Buf.getBuffer()) == file_magic::bitcode) { + auto ObjOrErr = object::SymbolicFile::createSymbolicFile( + Buf, file_magic::bitcode, &Context); + if (!ObjOrErr) { + // FIXME: check only for "not an object file" errors. + consumeError(ObjOrErr.takeError()); + return Ret; + } + Obj = std::move(*ObjOrErr); + } else { + auto ObjOrErr = object::SymbolicFile::createSymbolicFile(Buf); + if (!ObjOrErr) { + // FIXME: check only for "not an object file" errors. + consumeError(ObjOrErr.takeError()); + return Ret; + } + Obj = std::move(*ObjOrErr); } HasObject = true; - object::SymbolicFile &Obj = *ObjOrErr.get(); - for (const object::BasicSymbolRef &S : Obj.symbols()) { + for (const object::BasicSymbolRef &S : Obj->symbols()) { if (!isArchiveSymbol(S)) continue; Ret.push_back(SymNames.tell()); @@ -470,7 +482,7 @@ Error llvm::writeArchive(StringRef ArcName, if (WriteSymtab) { uint64_t MaxOffset = 0; uint64_t LastOffset = MaxOffset; - for (const auto& M : Data) { + for (const auto &M : Data) { // Record the start of the member's offset LastOffset = MaxOffset; // Account for the size of each part associated with the member. |