[lld] r239418 - COFF: Split SymbolTable::addCombinedLTOObject. NFC.
Rui Ueyama
ruiu at google.com
Tue Jun 9 10:52:17 PDT 2015
Author: ruiu
Date: Tue Jun 9 12:52:17 2015
New Revision: 239418
URL: http://llvm.org/viewvc/llvm-project?rev=239418&view=rev
Log:
COFF: Split SymbolTable::addCombinedLTOObject. NFC.
Modified:
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=239418&r1=239417&r2=239418&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Tue Jun 9 12:52:17 2015
@@ -235,40 +235,17 @@ std::error_code SymbolTable::addCombined
if (BitcodeFiles.empty())
return std::error_code();
- llvm::LTOCodeGenerator CG;
-
- // All symbols referenced by non-bitcode objects must be preserved.
- for (std::unique_ptr<ObjectFile> &File : ObjectFiles)
- for (SymbolBody *Body : File->getSymbols())
- if (auto *S = dyn_cast<DefinedBitcode>(Body->getReplacement()))
- CG.addMustPreserveSymbol(S->getName());
-
- // Likewise for other symbols that must be preserved.
- for (StringRef Name : Config->GCRoots)
- if (isa<DefinedBitcode>(Symtab[Name]->Body))
- CG.addMustPreserveSymbol(Name);
-
- CG.setModule(BitcodeFiles[0]->releaseModule());
- for (unsigned I = 1, E = BitcodeFiles.size(); I != E; ++I)
- CG.addModule(BitcodeFiles[I]->getModule());
-
- std::string ErrMsg;
- LTOObjectFile = CG.compile(false, false, false, ErrMsg);
- if (!LTOObjectFile) {
- llvm::errs() << ErrMsg << '\n';
- return make_error_code(LLDError::BrokenFile);
- }
-
// Create an object file and add it to the symbol table by replacing any
// DefinedBitcode symbols with the definitions in the object file.
- auto Obj = new ObjectFile(LTOObjectFile->getMemBufferRef());
- ObjectFiles.emplace_back(Obj);
- if (auto EC = Obj->parse())
+ LTOCodeGenerator CG;
+ auto FileOrErr = createLTOObject(&CG);
+ if (auto EC = FileOrErr.getError())
return EC;
+ ObjectFile *Obj = FileOrErr.get();
+
for (SymbolBody *Body : Obj->getSymbols()) {
if (!Body->isExternal())
continue;
-
// Find an existing Symbol. We should not see any new undefined symbols at
// this point.
StringRef Name = Body->getName();
@@ -311,9 +288,39 @@ std::error_code SymbolTable::addCombined
// New runtime library symbol references may have created undefined references.
if (reportRemainingUndefines())
return make_error_code(LLDError::BrokenFile);
-
return std::error_code();
}
+// Combine and compile bitcode files and then return the result
+// as a regular COFF object file.
+ErrorOr<ObjectFile *> SymbolTable::createLTOObject(LTOCodeGenerator *CG) {
+ // All symbols referenced by non-bitcode objects must be preserved.
+ for (std::unique_ptr<ObjectFile> &File : ObjectFiles)
+ for (SymbolBody *Body : File->getSymbols())
+ if (auto *S = dyn_cast<DefinedBitcode>(Body->getReplacement()))
+ CG->addMustPreserveSymbol(S->getName());
+
+ // Likewise for other symbols that must be preserved.
+ for (StringRef Name : Config->GCRoots)
+ if (isa<DefinedBitcode>(Symtab[Name]->Body))
+ CG->addMustPreserveSymbol(Name);
+
+ CG->setModule(BitcodeFiles[0]->releaseModule());
+ for (unsigned I = 1, E = BitcodeFiles.size(); I != E; ++I)
+ CG->addModule(BitcodeFiles[I]->getModule());
+
+ std::string ErrMsg;
+ LTOMB = CG->compile(false, false, false, ErrMsg); // take MB ownership
+ if (!LTOMB) {
+ llvm::errs() << ErrMsg << '\n';
+ return make_error_code(LLDError::BrokenFile);
+ }
+ auto Obj = new ObjectFile(LTOMB->getMemBufferRef());
+ ObjectFiles.emplace_back(Obj);
+ if (auto EC = Obj->parse())
+ return EC;
+ return Obj;
+}
+
} // namespace coff
} // namespace lld
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=239418&r1=239417&r2=239418&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Tue Jun 9 12:52:17 2015
@@ -15,6 +15,10 @@
#include "llvm/Support/Allocator.h"
#include <unordered_map>
+namespace llvm {
+struct LTOCodeGenerator;
+}
+
namespace lld {
namespace coff {
@@ -86,11 +90,12 @@ private:
std::error_code resolve(SymbolBody *Body);
std::error_code addMemberFile(Lazy *Body);
+ ErrorOr<ObjectFile *> createLTOObject(llvm::LTOCodeGenerator *CG);
std::unordered_map<StringRef, Symbol *> Symtab;
std::vector<std::unique_ptr<ArchiveFile>> ArchiveFiles;
std::vector<std::unique_ptr<BitcodeFile>> BitcodeFiles;
- std::unique_ptr<MemoryBuffer> LTOObjectFile;
+ std::unique_ptr<MemoryBuffer> LTOMB;
llvm::BumpPtrAllocator Alloc;
};
More information about the llvm-commits
mailing list