From 489759672814aab8af90985efef1d4812266e9a5 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 1 Jul 2015 22:32:23 +0000 Subject: COFF: Chagne weak alias' type from SymbolBody** to SymbolBody*. NFC. llvm-svn: 241198 --- lld/COFF/InputFiles.cpp | 4 +++- lld/COFF/SymbolTable.cpp | 13 +++++++------ lld/COFF/Symbols.cpp | 4 ++-- lld/COFF/Symbols.h | 8 ++------ 4 files changed, 14 insertions(+), 15 deletions(-) (limited to 'lld/COFF') diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 9187504280cb..845f3e502c35 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -195,8 +195,10 @@ Undefined *ObjectFile::createUndefined(COFFSymbolRef Sym) { 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, diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 8a4ad59e5190..51cf3de1d1d7 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -123,11 +123,9 @@ bool SymbolTable::reportRemainingUndefines() { 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(Alias->getReplacement())) { - Sym->Body = D; - continue; - } + if (auto *D = dyn_cast_or_null(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(SymbolBody *New) { // let the lazy symbol to read a member file. SymbolBody *Existing = Sym->Body; if (auto *L = dyn_cast(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(New)) - if (!U->getWeakAlias()) + if (!U->WeakAlias) return addMemberFile(L); Sym->Body = New; return std::error_code(); diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp index 883666e5780b..58eb1908043c 100644 --- a/lld/COFF/Symbols.cpp +++ b/lld/COFF/Symbols.cpp @@ -49,7 +49,7 @@ int SymbolBody::compare(SymbolBody *Other) { if (LK != RK) { if (RK > LastDefinedKind) { - if (LK == LazyKind && cast(Other)->getWeakAlias()) + if (LK == LazyKind && cast(Other)->WeakAlias) return -1; // The LHS is either defined or lazy and so it wins. @@ -121,7 +121,7 @@ int SymbolBody::compare(SymbolBody *Other) { case UndefinedKind: // Don't tie, just pick the LHS unless the RHS has a weak alias. - return cast(Other)->getWeakAlias() ? -1 : 1; + return cast(Other)->WeakAlias ? -1 : 1; case DefinedLocalImportKind: case DefinedImportThunkKind: diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h index ae7e3b5075e8..86ed2b321f0c 100644 --- a/lld/COFF/Symbols.h +++ b/lld/COFF/Symbols.h @@ -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. -- cgit v1.2.3