[lld] r338767 - Set IsUsedInRegularObj in a consistent manor between COFF, ELF and wasm. NFC
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 2 13:39:19 PDT 2018
Author: sbc
Date: Thu Aug 2 13:39:19 2018
New Revision: 338767
URL: http://llvm.org/viewvc/llvm-project?rev=338767&view=rev
Log:
Set IsUsedInRegularObj in a consistent manor between COFF, ELF and wasm. NFC
Differential Revision: https://reviews.llvm.org/D49147
Modified:
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/SymbolTable.h
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=338767&r1=338766&r2=338767&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Aug 2 13:39:19 2018
@@ -206,23 +206,25 @@ void SymbolTable::reportRemainingUndefin
}
}
-std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
+std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name, InputFile *File) {
+ bool Inserted = false;
Symbol *&Sym = SymMap[CachedHashStringRef(Name)];
- if (Sym)
- return {Sym, false};
- Sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
- Sym->IsUsedInRegularObj = false;
- Sym->PendingArchiveLoad = false;
- return {Sym, true};
+ if (!Sym) {
+ Sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
+ Sym->IsUsedInRegularObj = false;
+ Sym->PendingArchiveLoad = false;
+ Inserted = true;
+ }
+ if (!File || !isa<BitcodeFile>(File))
+ Sym->IsUsedInRegularObj = true;
+ return {Sym, Inserted};
}
Symbol *SymbolTable::addUndefined(StringRef Name, InputFile *F,
bool IsWeakAlias) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
- if (!F || !isa<BitcodeFile>(F))
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(Name, F);
if (WasInserted || (isa<Lazy>(S) && IsWeakAlias)) {
replaceSymbol<Undefined>(S, Name);
return S;
@@ -240,7 +242,7 @@ void SymbolTable::addLazy(ArchiveFile *F
StringRef Name = Sym.getName();
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
+ std::tie(S, WasInserted) = insert(Name, nullptr);
if (WasInserted) {
replaceSymbol<Lazy>(S, F, Sym);
return;
@@ -260,7 +262,7 @@ void SymbolTable::reportDuplicate(Symbol
Symbol *SymbolTable::addAbsolute(StringRef N, COFFSymbolRef Sym) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(N);
+ std::tie(S, WasInserted) = insert(N, nullptr);
S->IsUsedInRegularObj = true;
if (WasInserted || isa<Undefined>(S) || isa<Lazy>(S))
replaceSymbol<DefinedAbsolute>(S, N, Sym);
@@ -272,7 +274,7 @@ Symbol *SymbolTable::addAbsolute(StringR
Symbol *SymbolTable::addAbsolute(StringRef N, uint64_t VA) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(N);
+ std::tie(S, WasInserted) = insert(N, nullptr);
S->IsUsedInRegularObj = true;
if (WasInserted || isa<Undefined>(S) || isa<Lazy>(S))
replaceSymbol<DefinedAbsolute>(S, N, VA);
@@ -284,7 +286,7 @@ Symbol *SymbolTable::addAbsolute(StringR
Symbol *SymbolTable::addSynthetic(StringRef N, Chunk *C) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(N);
+ std::tie(S, WasInserted) = insert(N, nullptr);
S->IsUsedInRegularObj = true;
if (WasInserted || isa<Undefined>(S) || isa<Lazy>(S))
replaceSymbol<DefinedSynthetic>(S, N, C);
@@ -298,9 +300,7 @@ Symbol *SymbolTable::addRegular(InputFil
SectionChunk *C) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(N);
- if (!isa<BitcodeFile>(F))
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(N, F);
if (WasInserted || !isa<DefinedRegular>(S))
replaceSymbol<DefinedRegular>(S, F, N, /*IsCOMDAT*/ false,
/*IsExternal*/ true, Sym, C);
@@ -314,9 +314,7 @@ SymbolTable::addComdat(InputFile *F, Str
const coff_symbol_generic *Sym) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(N);
- if (!isa<BitcodeFile>(F))
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(N, F);
if (WasInserted || !isa<DefinedRegular>(S)) {
replaceSymbol<DefinedRegular>(S, F, N, /*IsCOMDAT*/ true,
/*IsExternal*/ true, Sym, nullptr);
@@ -331,9 +329,7 @@ Symbol *SymbolTable::addCommon(InputFile
const coff_symbol_generic *Sym, CommonChunk *C) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(N);
- if (!isa<BitcodeFile>(F))
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(N, F);
if (WasInserted || !isa<DefinedCOFF>(S))
replaceSymbol<DefinedCommon>(S, F, N, Size, Sym, C);
else if (auto *DC = dyn_cast<DefinedCommon>(S))
@@ -345,7 +341,7 @@ Symbol *SymbolTable::addCommon(InputFile
Symbol *SymbolTable::addImportData(StringRef N, ImportFile *F) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(N);
+ std::tie(S, WasInserted) = insert(N, nullptr);
S->IsUsedInRegularObj = true;
if (WasInserted || isa<Undefined>(S) || isa<Lazy>(S)) {
replaceSymbol<DefinedImportData>(S, N, F);
@@ -360,7 +356,7 @@ Symbol *SymbolTable::addImportThunk(Stri
uint16_t Machine) {
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
+ std::tie(S, WasInserted) = insert(Name, nullptr);
S->IsUsedInRegularObj = true;
if (WasInserted || isa<Undefined>(S) || isa<Lazy>(S)) {
replaceSymbol<DefinedImportThunk>(S, Name, ID, Machine);
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=338767&r1=338766&r2=338767&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Thu Aug 2 13:39:19 2018
@@ -108,7 +108,7 @@ public:
}
private:
- std::pair<Symbol *, bool> insert(StringRef Name);
+ std::pair<Symbol *, bool> insert(StringRef Name, InputFile *F);
StringRef findByPrefix(StringRef Prefix);
llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> SymMap;
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=338767&r1=338766&r2=338767&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Thu Aug 2 13:39:19 2018
@@ -88,14 +88,18 @@ Symbol *SymbolTable::find(StringRef Name
return SymMap.lookup(CachedHashStringRef(Name));
}
-std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
+std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name, InputFile *File) {
+ bool Inserted = false;
Symbol *&Sym = SymMap[CachedHashStringRef(Name)];
- if (Sym)
- return {Sym, false};
- Sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
- Sym->IsUsedInRegularObj = false;
- SymVector.emplace_back(Sym);
- return {Sym, true};
+ if (!Sym) {
+ Sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
+ Sym->IsUsedInRegularObj = false;
+ SymVector.emplace_back(Sym);
+ Inserted = true;
+ }
+ if (!File || File->kind() == InputFile::ObjectKind)
+ Sym->IsUsedInRegularObj = true;
+ return {Sym, Inserted};
}
static void reportTypeError(const Symbol *Existing, const InputFile *File,
@@ -158,15 +162,15 @@ DefinedFunction *SymbolTable::addSynthet
LLVM_DEBUG(dbgs() << "addSyntheticFunction: " << Name << "\n");
assert(!find(Name));
SyntheticFunctions.emplace_back(Function);
- return replaceSymbol<DefinedFunction>(insert(Name).first, Name, Flags,
- nullptr, Function);
+ return replaceSymbol<DefinedFunction>(insert(Name, nullptr).first, Name,
+ Flags, nullptr, Function);
}
DefinedData *SymbolTable::addSyntheticDataSymbol(StringRef Name,
uint32_t Flags) {
LLVM_DEBUG(dbgs() << "addSyntheticDataSymbol: " << Name << "\n");
assert(!find(Name));
- return replaceSymbol<DefinedData>(insert(Name).first, Name, Flags);
+ return replaceSymbol<DefinedData>(insert(Name, nullptr).first, Name, Flags);
}
DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags,
@@ -175,8 +179,8 @@ DefinedGlobal *SymbolTable::addSynthetic
<< "\n");
assert(!find(Name));
SyntheticGlobals.emplace_back(Global);
- return replaceSymbol<DefinedGlobal>(insert(Name).first, Name, Flags, nullptr,
- Global);
+ return replaceSymbol<DefinedGlobal>(insert(Name, nullptr).first, Name, Flags,
+ nullptr, Global);
}
static bool shouldReplace(const Symbol *Existing, InputFile *NewFile,
@@ -213,10 +217,7 @@ Symbol *SymbolTable::addDefinedFunction(
LLVM_DEBUG(dbgs() << "addDefinedFunction: " << Name << "\n");
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
-
- if (!File || File->kind() == InputFile::ObjectKind)
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(Name, File);
if (WasInserted || S->isLazy()) {
replaceSymbol<DefinedFunction>(S, Name, Flags, File, Function);
@@ -238,10 +239,7 @@ Symbol *SymbolTable::addDefinedData(Stri
<< "\n");
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
-
- if (!File || File->kind() == InputFile::ObjectKind)
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(Name, File);
if (WasInserted || S->isLazy()) {
replaceSymbol<DefinedData>(S, Name, Flags, File, Segment, Address, Size);
@@ -258,12 +256,10 @@ Symbol *SymbolTable::addDefinedData(Stri
Symbol *SymbolTable::addDefinedGlobal(StringRef Name, uint32_t Flags,
InputFile *File, InputGlobal *Global) {
LLVM_DEBUG(dbgs() << "addDefinedGlobal:" << Name << "\n");
+
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
-
- if (!File || File->kind() == InputFile::ObjectKind)
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(Name, File);
if (WasInserted || S->isLazy()) {
replaceSymbol<DefinedGlobal>(S, Name, Flags, File, Global);
@@ -284,10 +280,7 @@ Symbol *SymbolTable::addUndefinedFunctio
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
-
- if (!File || File->kind() == InputFile::ObjectKind)
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(Name, File);
if (WasInserted)
replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig);
@@ -305,10 +298,7 @@ Symbol *SymbolTable::addUndefinedData(St
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
-
- if (!File || File->kind() == InputFile::ObjectKind)
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(Name, File);
if (WasInserted)
replaceSymbol<UndefinedData>(S, Name, Flags, File);
@@ -326,10 +316,7 @@ Symbol *SymbolTable::addUndefinedGlobal(
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
-
- if (!File || File->kind() == InputFile::ObjectKind)
- S->IsUsedInRegularObj = true;
+ std::tie(S, WasInserted) = insert(Name, File);
if (WasInserted)
replaceSymbol<UndefinedGlobal>(S, Name, Flags, File, Type);
@@ -346,7 +333,7 @@ void SymbolTable::addLazy(ArchiveFile *F
Symbol *S;
bool WasInserted;
- std::tie(S, WasInserted) = insert(Name);
+ std::tie(S, WasInserted) = insert(Name, nullptr);
if (WasInserted) {
replaceSymbol<LazySymbol>(S, Name, File, *Sym);
Modified: lld/trunk/wasm/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.h?rev=338767&r1=338766&r2=338767&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.h (original)
+++ lld/trunk/wasm/SymbolTable.h Thu Aug 2 13:39:19 2018
@@ -77,7 +77,7 @@ public:
InputFunction *Function);
private:
- std::pair<Symbol *, bool> insert(StringRef Name);
+ std::pair<Symbol *, bool> insert(StringRef Name, InputFile *File);
llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> SymMap;
std::vector<Symbol *> SymVector;
More information about the llvm-commits
mailing list