From 38c67a27fe811074d39aaba6d4e9fbcc8f0640fc Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 15 Apr 2016 14:41:56 +0000 Subject: [PATCH] Store a Symbol for EntrySym. This makes it impossible to forget to call repl on the SymbolBody. llvm-svn: 266432 --- lld/ELF/Config.h | 4 ++-- lld/ELF/Driver.cpp | 2 +- lld/ELF/InputSection.h | 2 ++ lld/ELF/MarkLive.cpp | 5 +++-- lld/ELF/Writer.cpp | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index 656ae33d259d..fbd19a3f11fa 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -20,7 +20,7 @@ namespace lld { namespace elf { class InputFile; -class SymbolBody; +struct Symbol; enum ELFKind { ELFNoneKind, @@ -37,7 +37,7 @@ enum class BuildIdKind { None, Fnv1, Md5, Sha1 }; // and such fields have the same name as the corresponding options. // Most fields are initialized by the driver. struct Configuration { - SymbolBody *EntrySym = nullptr; + Symbol *EntrySym = nullptr; InputFile *FirstElf = nullptr; llvm::StringRef DynamicLinker; llvm::StringRef Entry; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 4eb00bddc333..f8d5b10bed68 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -428,7 +428,7 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // Set either EntryAddr (if S is a number) or EntrySym (otherwise). StringRef S = Config->Entry; if (S.getAsInteger(0, Config->EntryAddr)) - Config->EntrySym = Symtab.addUndefined(S); + Config->EntrySym = Symtab.addUndefined(S)->getSymbol(); } for (std::unique_ptr &F : Files) diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index c50ce60a05bb..3a3035f9e6a0 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -18,6 +18,8 @@ namespace lld { namespace elf { +class SymbolBody; + template class ICF; template class DefinedRegular; template class ObjectFile; diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 4d0b08dc76dc..ade0dceeb2c5 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -99,12 +99,13 @@ template void elf::markLive(SymbolTable *Symtab) { auto MarkSymbol = [&](SymbolBody *Sym) { if (Sym) - if (auto *D = dyn_cast>(&Sym->repl())) + if (auto *D = dyn_cast>(Sym)) Enqueue(D->Section); }; // Add GC root symbols. - MarkSymbol(Config->EntrySym); + if (Config->EntrySym) + MarkSymbol(Config->EntrySym->Body); MarkSymbol(Symtab->find(Config->Init)); MarkSymbol(Symtab->find(Config->Fini)); for (StringRef S : Config->Undefined) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index c942b5d856e9..ee1d32bc1b62 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1634,8 +1634,8 @@ static uint32_t getMipsEFlags() { } template static typename ELFT::uint getEntryAddr() { - if (SymbolBody *B = Config->EntrySym) - return B->repl().getVA(); + if (Symbol *S = Config->EntrySym) + return S->Body->getVA(); if (Config->EntryAddr != uint64_t(-1)) return Config->EntryAddr; return 0;