[lld] r241238 - COFF: Merge SymbolTable::find{,Symbol}. NFC
Rui Ueyama
ruiu at google.com
Wed Jul 1 20:59:04 PDT 2015
Author: ruiu
Date: Wed Jul 1 22:59:04 2015
New Revision: 241238
URL: http://llvm.org/viewvc/llvm-project?rev=241238&view=rev
Log:
COFF: Merge SymbolTable::find{,Symbol}. NFC
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=241238&r1=241237&r2=241238&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Jul 1 22:59:04 2015
@@ -218,7 +218,7 @@ StringRef LinkerDriver::findDefaultEntry
{"wWinMain", "wWinMainCRTStartup"},
};
for (auto E : Entries) {
- Symbol *Sym = Symtab.findSymbol(E[0]);
+ Symbol *Sym = Symtab.find(E[0]);
if (Sym && !isa<Undefined>(Sym->Body))
return E[1];
}
@@ -575,7 +575,7 @@ bool LinkerDriver::link(llvm::ArrayRef<c
for (auto Pair : Config->AlternateNames) {
StringRef From = Pair.first;
StringRef To = Pair.second;
- Symbol* Sym = Symtab.findSymbol(From);
+ Symbol *Sym = Symtab.find(From);
if (!Sym)
continue;
if (auto *U = dyn_cast<Undefined>(Sym->Body))
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=241238&r1=241237&r2=241238&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Wed Jul 1 22:59:04 2015
@@ -141,8 +141,10 @@ bool SymbolTable::reportRemainingUndefin
// If we can resolve a symbol by removing __imp_ prefix, do that.
// This odd rule is for compatibility with MSVC linker.
if (Name.startswith("__imp_")) {
- if (Defined *Imp = find(Name.substr(strlen("__imp_")))) {
- auto *S = new (Alloc) DefinedLocalImport(Name, Imp);
+ Symbol *Imp = find(Name.substr(strlen("__imp_")));
+ if (Imp && isa<Defined>(Imp->Body)) {
+ auto *D = cast<Defined>(Imp->Body);
+ auto *S = new (Alloc) DefinedLocalImport(Name, D);
LocalImportChunks.push_back(S->getChunk());
Sym->Body = S;
continue;
@@ -241,16 +243,7 @@ std::vector<Chunk *> SymbolTable::getChu
return Res;
}
-Defined *SymbolTable::find(StringRef Name) {
- auto It = Symtab.find(Name);
- if (It == Symtab.end())
- return nullptr;
- if (auto *Def = dyn_cast<Defined>(It->second->Body))
- return Def;
- return nullptr;
-}
-
-Symbol *SymbolTable::findSymbol(StringRef Name) {
+Symbol *SymbolTable::find(StringRef Name) {
auto It = Symtab.find(Name);
if (It == Symtab.end())
return nullptr;
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=241238&r1=241237&r2=241238&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Wed Jul 1 22:59:04 2015
@@ -53,12 +53,8 @@ public:
// Returns a list of chunks of selected symbols.
std::vector<Chunk *> getChunks();
- // Returns a symbol for a given name. It's not guaranteed that the
- // returned symbol actually has the same name (because of various
- // mechanisms to allow aliases, a name can be resolved to a
- // different symbol). Returns a nullptr if not found.
- Defined *find(StringRef Name);
- Symbol *findSymbol(StringRef Name);
+ // Returns a symbol for a given name. Returns a nullptr if not found.
+ Symbol *find(StringRef Name);
// Occasionally we have to resolve an undefined symbol to its
// mangled symbol. This function tries to find a mangled name
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=241238&r1=241237&r2=241238&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Jul 1 22:59:04 2015
@@ -235,7 +235,8 @@ void Writer::createImportTables() {
Sec->addChunk(C);
}
if (!DelayIdata.empty()) {
- DelayIdata.create(Symtab->find("__delayLoadHelper2"));
+ Defined *Helper = cast<Defined>(Symtab->find("__delayLoadHelper2")->Body);
+ DelayIdata.create(Helper);
OutputSection *Sec = createSection(".didat");
for (Chunk *C : DelayIdata.getChunks())
Sec->addChunk(C);
@@ -526,7 +527,7 @@ OutputSection *Writer::createSection(Str
// Dest is .reloc section. Add contents to that section.
void Writer::addBaserels(OutputSection *Dest) {
std::vector<uint32_t> V;
- Defined *ImageBase = cast<Defined>(Symtab->find("__ImageBase"));
+ Defined *ImageBase = cast<Defined>(Symtab->find("__ImageBase")->Body);
for (OutputSection *Sec : OutputSections) {
if (Sec == Dest)
continue;
More information about the llvm-commits
mailing list