From 94a16cb6111c0e10681f2047e043ff19882473e0 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Thu, 22 Nov 2018 11:40:08 +0000 Subject: [PATCH] [ELF] - Make SymbolTable::addDefined return Defined. Now it returns Symbol. This should be NFC that avoids doing cast at the caller's sides. Differential revision: https://reviews.llvm.org/D54627 llvm-svn: 347455 --- lld/ELF/SymbolTable.cpp | 8 ++++---- lld/ELF/SymbolTable.h | 6 +++--- lld/ELF/Writer.cpp | 11 +++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index f99b2a320218..e372461ee3c8 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -459,9 +459,9 @@ static void reportDuplicate(Symbol *Sym, InputFile *NewFile, error(Msg); } -Symbol *SymbolTable::addDefined(StringRef Name, uint8_t StOther, uint8_t Type, - uint64_t Value, uint64_t Size, uint8_t Binding, - SectionBase *Section, InputFile *File) { +Defined *SymbolTable::addDefined(StringRef Name, uint8_t StOther, uint8_t Type, + uint64_t Value, uint64_t Size, uint8_t Binding, + SectionBase *Section, InputFile *File) { Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, getVisibility(StOther), @@ -474,7 +474,7 @@ Symbol *SymbolTable::addDefined(StringRef Name, uint8_t StOther, uint8_t Type, else if (Cmp == 0) reportDuplicate(S, File, dyn_cast_or_null(Section), Value); - return S; + return cast(S); } template diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index e91e5cc2cef3..b5fd8d3b4ed9 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -45,9 +45,9 @@ public: Symbol *addUndefined(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t Type, bool CanOmitFromDynSym, InputFile *File); - Symbol *addDefined(StringRef Name, uint8_t StOther, uint8_t Type, - uint64_t Value, uint64_t Size, uint8_t Binding, - SectionBase *Section, InputFile *File); + Defined *addDefined(StringRef Name, uint8_t StOther, uint8_t Type, + uint64_t Value, uint64_t Size, uint8_t Binding, + SectionBase *Section, InputFile *File); template void addShared(StringRef Name, SharedFile &F, diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 0eb117a6228e..98a464adf7fb 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -172,15 +172,14 @@ static Defined *addOptionalRegular(StringRef Name, SectionBase *Sec, Symbol *S = Symtab->find(Name); if (!S || S->isDefined()) return nullptr; - Symbol *Sym = Symtab->addDefined(Name, StOther, STT_NOTYPE, Val, - /*Size=*/0, Binding, Sec, - /*File=*/nullptr); - return cast(Sym); + return Symtab->addDefined(Name, StOther, STT_NOTYPE, Val, + /*Size=*/0, Binding, Sec, + /*File=*/nullptr); } static Defined *addAbsolute(StringRef Name) { - return cast(Symtab->addDefined(Name, STV_HIDDEN, STT_NOTYPE, 0, 0, - STB_GLOBAL, nullptr, nullptr)); + return Symtab->addDefined(Name, STV_HIDDEN, STT_NOTYPE, 0, 0, STB_GLOBAL, + nullptr, nullptr); } // The linker is expected to define some symbols depending on