[lld] r241311 - COFF: Define SymbolTable::insert to simplify. NFC.
Rui Ueyama
ruiu at google.com
Thu Jul 2 15:52:33 PDT 2015
Author: ruiu
Date: Thu Jul 2 17:52:33 2015
New Revision: 241311
URL: http://llvm.org/viewvc/llvm-project?rev=241311&view=rev
Log:
COFF: Define SymbolTable::insert to simplify. 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=241311&r1=241310&r2=241311&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Jul 2 17:52:33 2015
@@ -164,12 +164,9 @@ bool SymbolTable::reportRemainingUndefin
}
void SymbolTable::addLazy(Lazy *New, std::vector<Symbol *> *Accum) {
- Symbol *&Sym = Symtab[New->getName()];
- if (!Sym) {
- Sym = new (Alloc) Symbol(New);
- New->setBackref(Sym);
+ Symbol *Sym = insert(New);
+ if (Sym->Body == New)
return;
- }
SymbolBody *Existing = Sym->Body;
if (!isa<Undefined>(Existing))
return;
@@ -181,17 +178,13 @@ void SymbolTable::addLazy(Lazy *New, std
std::error_code SymbolTable::addSymbol(SymbolBody *New) {
// Find an existing symbol or create and insert a new one.
assert(isa<Defined>(New) || isa<Undefined>(New));
- Symbol *&Sym = Symtab[New->getName()];
- if (!Sym) {
- Sym = new (Alloc) Symbol(New);
- New->setBackref(Sym);
+ Symbol *Sym = insert(New);
+ if (Sym->Body == New)
return std::error_code();
- }
- New->setBackref(Sym);
+ SymbolBody *Existing = Sym->Body;
// If we have an undefined symbol and a lazy symbol,
// let the lazy symbol to read a member file.
- SymbolBody *Existing = Sym->Body;
if (auto *L = dyn_cast<Lazy>(Existing)) {
// Undefined symbols with weak aliases need not to be resolved,
// since they would be replaced with weak aliases if they remain
@@ -216,6 +209,17 @@ std::error_code SymbolTable::addSymbol(S
return std::error_code();
}
+Symbol *SymbolTable::insert(SymbolBody *New) {
+ Symbol *&Sym = Symtab[New->getName()];
+ if (Sym) {
+ New->setBackref(Sym);
+ return Sym;
+ }
+ Sym = new (Alloc) Symbol(New);
+ New->setBackref(Sym);
+ return Sym;
+}
+
// Reads an archive member file pointed by a given symbol.
std::error_code SymbolTable::addMemberFile(Lazy *Body) {
auto FileOrErr = Body->getMember();
@@ -304,17 +308,11 @@ std::error_code SymbolTable::addCombined
// Find an existing Symbol. We should not see any new undefined symbols at
// this point.
StringRef Name = Body->getName();
- Symbol *&Sym = Symtab[Name];
- if (!Sym) {
- if (!isa<Defined>(Body)) {
- llvm::errs() << "LTO: undefined symbol: " << Name << '\n';
- return make_error_code(LLDError::BrokenFile);
- }
- Sym = new (Alloc) Symbol(Body);
- Body->setBackref(Sym);
- continue;
+ Symbol *Sym = insert(Body);
+ if (Sym->Body == Body && !isa<Defined>(Body)) {
+ llvm::errs() << "LTO: undefined symbol: " << Name << '\n';
+ return make_error_code(LLDError::BrokenFile);
}
- Body->setBackref(Sym);
if (isa<DefinedBitcode>(Sym->Body)) {
// The symbol should now be defined.
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=241311&r1=241310&r2=241311&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Thu Jul 2 17:52:33 2015
@@ -89,6 +89,7 @@ private:
std::error_code addSymbol(SymbolBody *New);
void addLazy(Lazy *New, std::vector<Symbol *> *Accum);
+ Symbol *insert(SymbolBody *New);
std::error_code addMemberFile(Lazy *Body);
ErrorOr<ObjectFile *> createLTOObject(llvm::LTOCodeGenerator *CG);
More information about the llvm-commits
mailing list