[lld] r241198 - COFF: Chagne weak alias' type from SymbolBody** to SymbolBody*. NFC.
Rui Ueyama
ruiu at google.com
Wed Jul 1 15:32:23 PDT 2015
Author: ruiu
Date: Wed Jul 1 17:32:23 2015
New Revision: 241198
URL: http://llvm.org/viewvc/llvm-project?rev=241198&view=rev
Log:
COFF: Chagne weak alias' type from SymbolBody** to SymbolBody*. NFC.
Modified:
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/Symbols.cpp
lld/trunk/COFF/Symbols.h
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=241198&r1=241197&r2=241198&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Wed Jul 1 17:32:23 2015
@@ -195,8 +195,10 @@ Undefined *ObjectFile::createUndefined(C
Undefined *ObjectFile::createWeakExternal(COFFSymbolRef Sym, const void *AuxP) {
StringRef Name;
COFFObj->getSymbolName(Sym, Name);
+ auto *U = new (Alloc) Undefined(Name);
auto *Aux = (const coff_aux_weak_external *)AuxP;
- return new (Alloc) Undefined(Name, &SparseSymbolBodies[Aux->TagIndex]);
+ U->WeakAlias = SparseSymbolBodies[Aux->TagIndex];
+ return U;
}
Defined *ObjectFile::createDefined(COFFSymbolRef Sym, const void *AuxP,
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=241198&r1=241197&r2=241198&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Wed Jul 1 17:32:23 2015
@@ -123,11 +123,9 @@ bool SymbolTable::reportRemainingUndefin
continue;
StringRef Name = Undef->getName();
// The weak alias may have been resovled, so check for that.
- if (SymbolBody *Alias = Undef->getWeakAlias()) {
- if (auto *D = dyn_cast<Defined>(Alias->getReplacement())) {
- Sym->Body = D;
- continue;
- }
+ if (auto *D = dyn_cast_or_null<Defined>(Undef->WeakAlias)) {
+ Sym->Body = D;
+ continue;
}
// If we can resolve a symbol by removing __imp_ prefix, do that.
// This odd rule is for compatibility with MSVC linker.
@@ -181,8 +179,11 @@ std::error_code SymbolTable::addSymbol(S
// 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
+ // undefined.
if (auto *U = dyn_cast<Undefined>(New))
- if (!U->getWeakAlias())
+ if (!U->WeakAlias)
return addMemberFile(L);
Sym->Body = New;
return std::error_code();
Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=241198&r1=241197&r2=241198&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Wed Jul 1 17:32:23 2015
@@ -49,7 +49,7 @@ int SymbolBody::compare(SymbolBody *Othe
if (LK != RK) {
if (RK > LastDefinedKind) {
- if (LK == LazyKind && cast<Undefined>(Other)->getWeakAlias())
+ if (LK == LazyKind && cast<Undefined>(Other)->WeakAlias)
return -1;
// The LHS is either defined or lazy and so it wins.
@@ -121,7 +121,7 @@ int SymbolBody::compare(SymbolBody *Othe
case UndefinedKind:
// Don't tie, just pick the LHS unless the RHS has a weak alias.
- return cast<Undefined>(Other)->getWeakAlias() ? -1 : 1;
+ return cast<Undefined>(Other)->WeakAlias ? -1 : 1;
case DefinedLocalImportKind:
case DefinedImportThunkKind:
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=241198&r1=241197&r2=241198&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Wed Jul 1 17:32:23 2015
@@ -239,8 +239,7 @@ private:
// Undefined symbols.
class Undefined : public SymbolBody {
public:
- explicit Undefined(StringRef N, SymbolBody **S = nullptr)
- : SymbolBody(UndefinedKind, N), Alias(S) {}
+ explicit Undefined(StringRef N) : SymbolBody(UndefinedKind, N) {}
static bool classof(const SymbolBody *S) {
return S->kind() == UndefinedKind;
@@ -250,10 +249,7 @@ public:
// undefined symbol a second chance if it would remain undefined.
// If it remains undefined, it'll be replaced with whatever the
// Alias pointer points to.
- SymbolBody *getWeakAlias() { return Alias ? *Alias : nullptr; }
-
-private:
- SymbolBody **Alias;
+ SymbolBody *WeakAlias = nullptr;
};
// Windows-specific classes.
More information about the llvm-commits
mailing list