[PATCH] D51759: [llvm] Improve the performance of getSymbols used by ArchiveWriter
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 6 16:51:12 PDT 2018
alexshap created this revision.
alexshap added a reviewer: compnerd.
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 (on both OSX and Linux)
Repository:
rL LLVM
https://reviews.llvm.org/D51759
Files:
lib/Object/ArchiveWriter.cpp
Index: lib/Object/ArchiveWriter.cpp
===================================================================
--- lib/Object/ArchiveWriter.cpp
+++ lib/Object/ArchiveWriter.cpp
@@ -372,20 +372,30 @@
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;
+ 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 +480,7 @@
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51759.164317.patch
Type: text/x-patch
Size: 2004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180906/72eda88d/attachment.bin>
More information about the llvm-commits
mailing list