[PATCH] D30348: De-template DefinedRegular.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 11:33:12 PST 2017


LGTM!

Thanks!


Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:

> ruiu updated this revision to Diff 89819.
> ruiu added a comment.
>
> Rebased.
>
>
> https://reviews.llvm.org/D30348
>
> Files:
>   lld/ELF/ICF.cpp
>   lld/ELF/InputFiles.cpp
>   lld/ELF/InputSection.cpp
>   lld/ELF/InputSection.h
>   lld/ELF/LinkerScript.cpp
>   lld/ELF/MapFile.cpp
>   lld/ELF/MarkLive.cpp
>   lld/ELF/OutputSections.h
>   lld/ELF/Relocations.cpp
>   lld/ELF/SymbolTable.cpp
>   lld/ELF/SymbolTable.h
>   lld/ELF/Symbols.cpp
>   lld/ELF/Symbols.h
>   lld/ELF/SyntheticSections.cpp
>   lld/ELF/Target.cpp
>   lld/ELF/Thunks.cpp
>   lld/ELF/Writer.cpp
>
> Index: lld/ELF/Writer.cpp
> ===================================================================
> --- lld/ELF/Writer.cpp
> +++ lld/ELF/Writer.cpp
> @@ -486,7 +486,7 @@
>    if (!B.isLocal() && !B.symbol()->IsUsedInRegularObj)
>      return false;
>  
> -  if (auto *D = dyn_cast<DefinedRegular<ELFT>>(&B)) {
> +  if (auto *D = dyn_cast<DefinedRegular>(&B)) {
>      // Always include absolute symbols.
>      if (!D->Section)
>        return true;
> @@ -510,7 +510,7 @@
>        if (!B->IsLocal)
>          fatal(toString(F) +
>                ": broken object: getLocalSymbols returns a non-local symbol");
> -      auto *DR = dyn_cast<DefinedRegular<ELFT>>(B);
> +      auto *DR = dyn_cast<DefinedRegular>(B);
>  
>        // No reason to keep local undefined symbol in symtab.
>        if (!DR)
> @@ -537,8 +537,8 @@
>          IS->Type == SHT_RELA)
>        continue;
>      auto *B = new (BAlloc)
> -        DefinedRegular<ELFT>("", /*IsLocal=*/true, /*StOther*/ 0, STT_SECTION,
> -                             /*Value*/ 0, /*Size*/ 0, IS, nullptr);
> +        DefinedRegular("", /*IsLocal=*/true, /*StOther*/ 0, STT_SECTION,
> +                       /*Value*/ 0, /*Size*/ 0, IS, nullptr);
>  
>      In<ELFT>::SymTab->addLocal(B);
>    }
> @@ -791,23 +791,22 @@
>      // to GOT. Default offset is 0x7ff0.
>      // See "Global Data Symbols" in Chapter 6 in the following document:
>      // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
> -    ElfSym<ELFT>::MipsGp =
> -        Symtab<ELFT>::X->addAbsolute("_gp", STV_HIDDEN, STB_LOCAL);
> +    ElfSym::MipsGp = Symtab<ELFT>::X->addAbsolute("_gp", STV_HIDDEN, STB_LOCAL);
>  
>      // On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
>      // start of function and 'gp' pointer into GOT. To simplify relocation
>      // calculation we assign _gp value to it and calculate corresponding
>      // relocations as relative to this value.
>      if (Symtab<ELFT>::X->find("_gp_disp"))
> -      ElfSym<ELFT>::MipsGpDisp =
> +      ElfSym::MipsGpDisp =
>            Symtab<ELFT>::X->addAbsolute("_gp_disp", STV_HIDDEN, STB_LOCAL);
>  
>      // The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
>      // pointer. This symbol is used in the code generated by .cpload pseudo-op
>      // in case of using -mno-shared option.
>      // https://sourceware.org/ml/binutils/2004-12/msg00094.html
>      if (Symtab<ELFT>::X->find("__gnu_local_gp"))
> -      ElfSym<ELFT>::MipsLocalGp =
> +      ElfSym::MipsLocalGp =
>            Symtab<ELFT>::X->addAbsolute("__gnu_local_gp", STV_HIDDEN, STB_LOCAL);
>    }
>  
> @@ -840,7 +839,7 @@
>      return;
>  
>    // __ehdr_start is the location of ELF file headers.
> -  ElfSym<ELFT>::EhdrStart =
> +  ElfSym::EhdrStart =
>        addOptionalSynthetic<ELFT>("__ehdr_start", Out<ELFT>::ElfHeader, 0);
>  
>    auto Define = [](StringRef S, DefinedSynthetic *&Sym1,
> @@ -851,9 +850,9 @@
>      Sym2 = addOptionalSynthetic<ELFT>(S, nullptr, 0, STV_DEFAULT);
>    };
>  
> -  Define("_end", ElfSym<ELFT>::End, ElfSym<ELFT>::End2);
> -  Define("_etext", ElfSym<ELFT>::Etext, ElfSym<ELFT>::Etext2);
> -  Define("_edata", ElfSym<ELFT>::Edata, ElfSym<ELFT>::Edata2);
> +  Define("_end", ElfSym::End, ElfSym::End2);
> +  Define("_etext", ElfSym::Etext, ElfSym::Etext2);
> +  Define("_edata", ElfSym::Edata, ElfSym::Edata2);
>  }
>  
>  // Sort input sections by section name suffixes for
> @@ -887,7 +886,7 @@
>    DenseMap<InputSectionBase *, int> SectionOrder;
>    for (elf::ObjectFile<ELFT> *File : Symtab<ELFT>::X->getObjectFiles()) {
>      for (SymbolBody *Body : File->getSymbols()) {
> -      auto *D = dyn_cast<DefinedRegular<ELFT>>(Body);
> +      auto *D = dyn_cast<DefinedRegular>(Body);
>        if (!D || !D->Section)
>          continue;
>        int &Priority = SectionOrder[D->Section];
> @@ -1658,31 +1657,29 @@
>        LastRO = &P;
>    }
>    if (Last)
> -    Set(ElfSym<ELFT>::End, ElfSym<ELFT>::End2, Last->First, Last->p_memsz);
> +    Set(ElfSym::End, ElfSym::End2, Last->First, Last->p_memsz);
>    if (LastRO)
> -    Set(ElfSym<ELFT>::Etext, ElfSym<ELFT>::Etext2, LastRO->First,
> -        LastRO->p_filesz);
> +    Set(ElfSym::Etext, ElfSym::Etext2, LastRO->First, LastRO->p_filesz);
>    if (LastRW)
> -    Set(ElfSym<ELFT>::Edata, ElfSym<ELFT>::Edata2, LastRW->First,
> -        LastRW->p_filesz);
> +    Set(ElfSym::Edata, ElfSym::Edata2, LastRW->First, LastRW->p_filesz);
>  
>    // Setup MIPS _gp_disp/__gnu_local_gp symbols which should
>    // be equal to the _gp symbol's value.
>    if (Config->EMachine == EM_MIPS) {
> -    if (!ElfSym<ELFT>::MipsGp->Value) {
> +    if (!ElfSym::MipsGp->Value) {
>        // Find GP-relative section with the lowest address
>        // and use this address to calculate default _gp value.
>        uintX_t Gp = -1;
>        for (const OutputSection *OS : OutputSections)
>          if ((OS->Flags & SHF_MIPS_GPREL) && OS->Addr < Gp)
>            Gp = OS->Addr;
>        if (Gp != (uintX_t)-1)
> -        ElfSym<ELFT>::MipsGp->Value = Gp + 0x7ff0;
> +        ElfSym::MipsGp->Value = Gp + 0x7ff0;
>      }
> -    if (ElfSym<ELFT>::MipsGpDisp)
> -      ElfSym<ELFT>::MipsGpDisp->Value = ElfSym<ELFT>::MipsGp->Value;
> -    if (ElfSym<ELFT>::MipsLocalGp)
> -      ElfSym<ELFT>::MipsLocalGp->Value = ElfSym<ELFT>::MipsGp->Value;
> +    if (ElfSym::MipsGpDisp)
> +      ElfSym::MipsGpDisp->Value = ElfSym::MipsGp->Value;
> +    if (ElfSym::MipsLocalGp)
> +      ElfSym::MipsLocalGp->Value = ElfSym::MipsGp->Value;
>    }
>  }
>  
> Index: lld/ELF/Thunks.cpp
> ===================================================================
> --- lld/ELF/Thunks.cpp
> +++ lld/ELF/Thunks.cpp
> @@ -225,7 +225,7 @@
>  
>  template <class ELFT>
>  InputSection *MipsThunk<ELFT>::getTargetInputSection() const {
> -  auto *DR = dyn_cast<DefinedRegular<ELFT>>(&this->Destination);
> +  auto *DR = dyn_cast<DefinedRegular>(&this->Destination);
>    return dyn_cast<InputSection>(DR->Section);
>  }
>  
> Index: lld/ELF/Target.cpp
> ===================================================================
> --- lld/ELF/Target.cpp
> +++ lld/ELF/Target.cpp
> @@ -2086,7 +2086,7 @@
>      // offset between start of function and 'gp' value which by default
>      // equal to the start of .got section. In that case we consider these
>      // relocations as relative.
> -    if (&S == ElfSym<ELFT>::MipsGpDisp)
> +    if (&S == ElfSym::MipsGpDisp)
>        return R_PC;
>      return R_ABS;
>    case R_MIPS_PC32:
> @@ -2245,10 +2245,10 @@
>    // If current file has PIC code, LA25 stub is not required.
>    if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
>      return false;
> -  auto *D = dyn_cast<DefinedRegular<ELFT>>(&S);
> +  auto *D = dyn_cast<DefinedRegular>(&S);
>    // LA25 is required if target file has PIC code
>    // or target symbol is a PIC symbol.
> -  return D && D->isMipsPIC();
> +  return D && D->isMipsPIC<ELFT>();
>  }
>  
>  template <class ELFT>
> Index: lld/ELF/SyntheticSections.cpp
> ===================================================================
> --- lld/ELF/SyntheticSections.cpp
> +++ lld/ELF/SyntheticSections.cpp
> @@ -292,8 +292,8 @@
>  template <class ELFT>
>  SymbolBody *elf::addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value,
>                                     uint64_t Size, InputSectionBase *Section) {
> -  auto *S = make<DefinedRegular<ELFT>>(Name, /*IsLocal*/ true, STV_DEFAULT,
> -                                       Type, Value, Size, Section, nullptr);
> +  auto *S = make<DefinedRegular>(Name, /*IsLocal*/ true, STV_DEFAULT, Type,
> +                                 Value, Size, Section, nullptr);
>    if (In<ELFT>::SymTab)
>      In<ELFT>::SymTab->addLocal(S);
>    return S;
> @@ -445,7 +445,7 @@
>      return false;
>    const RelTy &Rel = Rels[FirstRelI];
>    SymbolBody &B = Sec->template getFile<ELFT>()->getRelocTargetSym(Rel);
> -  auto *D = dyn_cast<DefinedRegular<ELFT>>(&B);
> +  auto *D = dyn_cast<DefinedRegular>(&B);
>    if (!D || !D->Section)
>      return false;
>    InputSectionBase *Target = D->Section->Repl;
> @@ -697,7 +697,7 @@
>      // sections referenced by GOT relocations. Then later in the `finalize`
>      // method calculate number of "pages" required to cover all saved output
>      // section and allocate appropriate number of GOT entries.
> -    auto *DefSym = cast<DefinedRegular<ELFT>>(&Sym);
> +    auto *DefSym = cast<DefinedRegular>(&Sym);
>      PageIndexMap.insert(
>          {DefSym->Section->template getOutputSection<ELFT>(), 0});
>      return;
> @@ -770,8 +770,7 @@
>  MipsGotSection<ELFT>::getPageEntryOffset(const SymbolBody &B,
>                                           int64_t Addend) const {
>    const OutputSection *OutSec =
> -      cast<DefinedRegular<ELFT>>(&B)
> -          ->Section->template getOutputSection<ELFT>();
> +      cast<DefinedRegular>(&B)->Section->template getOutputSection<ELFT>();
>    uintX_t SecAddr = getMipsPageAddr(OutSec->Addr);
>    uintX_t SymAddr = getMipsPageAddr(B.getVA<ELFT>(Addend));
>    uintX_t Index = PageIndexMap.lookup(OutSec) + (SymAddr - SecAddr) / 0xffff;
> @@ -849,7 +848,7 @@
>  
>  template <class ELFT>
>  typename MipsGotSection<ELFT>::uintX_t MipsGotSection<ELFT>::getGp() const {
> -  return ElfSym<ELFT>::MipsGp->template getVA<ELFT>(0);
> +  return ElfSym::MipsGp->template getVA<ELFT>(0);
>  }
>  
>  template <class ELFT>
> @@ -1347,8 +1346,8 @@
>      // This is used for -r, so we have to handle multiple section
>      // symbols being combined.
>      if (Body->Type == STT_SECTION && E.Symbol->Type == STT_SECTION)
> -      return cast<DefinedRegular<ELFT>>(Body)->Section->OutSec ==
> -             cast<DefinedRegular<ELFT>>(E.Symbol)->Section->OutSec;
> +      return cast<DefinedRegular>(Body)->Section->OutSec ==
> +             cast<DefinedRegular>(E.Symbol)->Section->OutSec;
>      return false;
>    });
>    if (I == Symbols.end())
> @@ -1373,7 +1372,7 @@
>    // to the output symbol table pointed by Buf.
>  
>    for (auto I = Symbols.begin(); I != Symbols.begin() + NumLocals; ++I) {
> -    const DefinedRegular<ELFT> &Body = *cast<DefinedRegular<ELFT>>(I->Symbol);
> +    const DefinedRegular &Body = *cast<DefinedRegular>(I->Symbol);
>      InputSectionBase *Section = Body.Section;
>      auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
>  
> @@ -1383,7 +1382,7 @@
>      } else {
>        const OutputSection *OutSec = Section->getOutputSection<ELFT>();
>        ESym->st_shndx = OutSec->SectionIndex;
> -      ESym->st_value = OutSec->Addr + Section->getOffset(Body);
> +      ESym->st_value = OutSec->Addr + Section->getOffset<ELFT>(Body);
>      }
>      ESym->st_name = I->StrTabOffset;
>      ESym->st_size = Body.template getSize<ELFT>();
> @@ -1414,7 +1413,7 @@
>  
>      if (const OutputSection *OutSec = getOutputSection(Body)) {
>        ESym->st_shndx = OutSec->SectionIndex;
> -    } else if (isa<DefinedRegular<ELFT>>(Body)) {
> +    } else if (isa<DefinedRegular>(Body)) {
>        ESym->st_shndx = SHN_ABS;
>      } else if (isa<DefinedCommon>(Body)) {
>        ESym->st_shndx = SHN_COMMON;
> @@ -1429,8 +1428,8 @@
>        if (Body->isInPlt() && Body->NeedsPltAddr)
>          ESym->st_other |= STO_MIPS_PLT;
>        if (Config->Relocatable) {
> -        auto *D = dyn_cast<DefinedRegular<ELFT>>(Body);
> -        if (D && D->isMipsPIC())
> +        auto *D = dyn_cast<DefinedRegular>(Body);
> +        if (D && D->isMipsPIC<ELFT>())
>            ESym->st_other |= STO_MIPS_PIC;
>        }
>      }
> @@ -1445,7 +1444,7 @@
>    case SymbolBody::DefinedSyntheticKind:
>      return cast<DefinedSynthetic>(Sym)->Section;
>    case SymbolBody::DefinedRegularKind: {
> -    auto &D = cast<DefinedRegular<ELFT>>(*Sym);
> +    auto &D = cast<DefinedRegular>(*Sym);
>      if (D.Section)
>        return D.Section->template getOutputSection<ELFT>();
>      break;
> Index: lld/ELF/Symbols.h
> ===================================================================
> --- lld/ELF/Symbols.h
> +++ lld/ELF/Symbols.h
> @@ -173,29 +173,26 @@
>  };
>  
>  // Regular defined symbols read from object file symbol tables.
> -template <class ELFT> class DefinedRegular : public Defined {
> -  typedef typename ELFT::Sym Elf_Sym;
> -  typedef typename ELFT::uint uintX_t;
> -
> +class DefinedRegular : public Defined {
>  public:
>    DefinedRegular(StringRefZ Name, bool IsLocal, uint8_t StOther, uint8_t Type,
> -                 uintX_t Value, uintX_t Size, InputSectionBase *Section,
> +                 uint64_t Value, uint64_t Size, InputSectionBase *Section,
>                   InputFile *File)
>        : Defined(SymbolBody::DefinedRegularKind, Name, IsLocal, StOther, Type),
>          Value(Value), Size(Size),
>          Section(Section ? Section->Repl : NullInputSection) {
>      this->File = File;
>    }
>  
>    // Return true if the symbol is a PIC function.
> -  bool isMipsPIC() const;
> +  template <class ELFT> bool isMipsPIC() const;
>  
>    static bool classof(const SymbolBody *S) {
>      return S->kind() == SymbolBody::DefinedRegularKind;
>    }
>  
> -  uintX_t Value;
> -  uintX_t Size;
> +  uint64_t Value;
> +  uint64_t Size;
>  
>    // The input section this symbol belongs to. Notice that this is
>    // a reference to a pointer. We are using two levels of indirections
> @@ -209,8 +206,6 @@
>    static InputSectionBase *NullInputSection;
>  };
>  
> -template <class ELFT> InputSectionBase *DefinedRegular<ELFT>::NullInputSection;
> -
>  // DefinedSynthetic is a class to represent linker-generated ELF symbols.
>  // The difference from the regular symbol is that DefinedSynthetic symbols
>  // don't belong to any input files or sections. Thus, its constructor
> @@ -336,7 +331,7 @@
>  
>  // Some linker-generated symbols need to be created as
>  // DefinedRegular symbols.
> -template <class ELFT> struct ElfSym {
> +struct ElfSym {
>    // The content for __ehdr_start symbol.
>    static DefinedSynthetic *EhdrStart;
>  
> @@ -353,22 +348,11 @@
>    static DefinedSynthetic *End2;
>  
>    // The content for _gp_disp/__gnu_local_gp symbols for MIPS target.
> -  static DefinedRegular<ELFT> *MipsGpDisp;
> -  static DefinedRegular<ELFT> *MipsLocalGp;
> -  static DefinedRegular<ELFT> *MipsGp;
> +  static DefinedRegular *MipsGpDisp;
> +  static DefinedRegular *MipsLocalGp;
> +  static DefinedRegular *MipsGp;
>  };
>  
> -template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::EhdrStart;
> -template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Etext;
> -template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Etext2;
> -template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Edata;
> -template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::Edata2;
> -template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::End;
> -template <class ELFT> DefinedSynthetic *ElfSym<ELFT>::End2;
> -template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGpDisp;
> -template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsLocalGp;
> -template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGp;
> -
>  // A real symbol object, SymbolBody, is usually stored within a Symbol. There's
>  // always one Symbol for each symbol name. The resolver updates the SymbolBody
>  // stored in the Body field of this object as it resolves symbols. Symbol also
> @@ -415,9 +399,8 @@
>    // large and aligned enough to store any derived class of SymbolBody. We
>    // assume that the size and alignment of ELF64LE symbols is sufficient for any
>    // ELFT, and we verify this with the static_asserts in replaceBody.
> -  llvm::AlignedCharArrayUnion<
> -      DefinedCommon, DefinedRegular<llvm::object::ELF64LE>, DefinedSynthetic,
> -      Undefined, SharedSymbol, LazyArchive, LazyObject>
> +  llvm::AlignedCharArrayUnion<DefinedCommon, DefinedRegular, DefinedSynthetic,
> +                              Undefined, SharedSymbol, LazyArchive, LazyObject>
>        Body;
>  
>    SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
> Index: lld/ELF/Symbols.cpp
> ===================================================================
> --- lld/ELF/Symbols.cpp
> +++ lld/ELF/Symbols.cpp
> @@ -28,6 +28,19 @@
>  using namespace lld;
>  using namespace lld::elf;
>  
> +InputSectionBase *DefinedRegular::NullInputSection;
> +
> +DefinedSynthetic *ElfSym::EhdrStart;
> +DefinedSynthetic *ElfSym::Etext;
> +DefinedSynthetic *ElfSym::Etext2;
> +DefinedSynthetic *ElfSym::Edata;
> +DefinedSynthetic *ElfSym::Edata2;
> +DefinedSynthetic *ElfSym::End;
> +DefinedSynthetic *ElfSym::End2;
> +DefinedRegular *ElfSym::MipsGpDisp;
> +DefinedRegular *ElfSym::MipsLocalGp;
> +DefinedRegular *ElfSym::MipsGp;
> +
>  template <class ELFT>
>  static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) {
>    typedef typename ELFT::uint uintX_t;
> @@ -43,7 +56,7 @@
>      return Sec->Addr + D.Value;
>    }
>    case SymbolBody::DefinedRegularKind: {
> -    auto &D = cast<DefinedRegular<ELFT>>(Body);
> +    auto &D = cast<DefinedRegular>(Body);
>      InputSectionBase *IS = D.Section;
>  
>      // According to the ELF spec reference to a local symbol from outside
> @@ -165,7 +178,7 @@
>  template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
>    if (const auto *C = dyn_cast<DefinedCommon>(this))
>      return C->Size;
> -  if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this))
> +  if (const auto *DR = dyn_cast<DefinedRegular>(this))
>      return DR->Size;
>    if (const auto *S = dyn_cast<SharedSymbol>(this))
>      return S->getSize<ELFT>();
> @@ -215,7 +228,7 @@
>                   uint8_t Type)
>      : SymbolBody(K, Name, IsLocal, StOther, Type) {}
>  
> -template <class ELFT> bool DefinedRegular<ELFT>::isMipsPIC() const {
> +template <class ELFT> bool DefinedRegular::isMipsPIC() const {
>    if (!Section || !isFunc())
>      return false;
>    return (this->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
> @@ -359,10 +372,10 @@
>  template uint64_t SymbolBody::template getSize<ELF64LE>() const;
>  template uint64_t SymbolBody::template getSize<ELF64BE>() const;
>  
> -template class elf::DefinedRegular<ELF32LE>;
> -template class elf::DefinedRegular<ELF32BE>;
> -template class elf::DefinedRegular<ELF64LE>;
> -template class elf::DefinedRegular<ELF64BE>;
> +template bool DefinedRegular::template isMipsPIC<ELF32LE>() const;
> +template bool DefinedRegular::template isMipsPIC<ELF32BE>() const;
> +template bool DefinedRegular::template isMipsPIC<ELF64LE>() const;
> +template bool DefinedRegular::template isMipsPIC<ELF64BE>() const;
>  
>  template uint64_t SharedSymbol::template getAlignment<ELF32LE>() const;
>  template uint64_t SharedSymbol::template getAlignment<ELF32BE>() const;
> Index: lld/ELF/SymbolTable.h
> ===================================================================
> --- lld/ELF/SymbolTable.h
> +++ lld/ELF/SymbolTable.h
> @@ -46,11 +46,11 @@
>    ArrayRef<BinaryFile *> getBinaryFiles() const { return BinaryFiles; }
>    ArrayRef<SharedFile<ELFT> *> getSharedFiles() const { return SharedFiles; }
>  
> -  DefinedRegular<ELFT> *addAbsolute(StringRef Name,
> -                                    uint8_t Visibility = llvm::ELF::STV_HIDDEN,
> -                                    uint8_t Binding = llvm::ELF::STB_GLOBAL);
> -  DefinedRegular<ELFT> *addIgnored(StringRef Name,
> -                                   uint8_t Visibility = llvm::ELF::STV_HIDDEN);
> +  DefinedRegular *addAbsolute(StringRef Name,
> +                              uint8_t Visibility = llvm::ELF::STV_HIDDEN,
> +                              uint8_t Binding = llvm::ELF::STB_GLOBAL);
> +  DefinedRegular *addIgnored(StringRef Name,
> +                             uint8_t Visibility = llvm::ELF::STV_HIDDEN);
>  
>    Symbol *addUndefined(StringRef Name);
>    Symbol *addUndefined(StringRef Name, bool IsLocal, uint8_t Binding,
> Index: lld/ELF/SymbolTable.cpp
> ===================================================================
> --- lld/ELF/SymbolTable.cpp
> +++ lld/ELF/SymbolTable.cpp
> @@ -126,19 +126,19 @@
>  }
>  
>  template <class ELFT>
> -DefinedRegular<ELFT> *SymbolTable<ELFT>::addAbsolute(StringRef Name,
> -                                                     uint8_t Visibility,
> -                                                     uint8_t Binding) {
> +DefinedRegular *SymbolTable<ELFT>::addAbsolute(StringRef Name,
> +                                               uint8_t Visibility,
> +                                               uint8_t Binding) {
>    Symbol *Sym =
>        addRegular(Name, Visibility, STT_NOTYPE, 0, 0, Binding, nullptr, nullptr);
> -  return cast<DefinedRegular<ELFT>>(Sym->body());
> +  return cast<DefinedRegular>(Sym->body());
>  }
>  
>  // Add Name as an "ignored" symbol. An ignored symbol is a regular
>  // linker-synthesized defined symbol, but is only defined if needed.
>  template <class ELFT>
> -DefinedRegular<ELFT> *SymbolTable<ELFT>::addIgnored(StringRef Name,
> -                                                    uint8_t Visibility) {
> +DefinedRegular *SymbolTable<ELFT>::addIgnored(StringRef Name,
> +                                              uint8_t Visibility) {
>    SymbolBody *S = find(Name);
>    if (!S || S->isInCurrentDSO())
>      return nullptr;
> @@ -309,7 +309,7 @@
>      if (Config->WarnCommon)
>        warn("common " + S->body()->getName() + " is overridden");
>      return 1;
> -  } else if (auto *R = dyn_cast<DefinedRegular<ELFT>>(B)) {
> +  } else if (auto *R = dyn_cast<DefinedRegular>(B)) {
>      if (R->Section == nullptr && Binding == STB_GLOBAL && IsAbsolute &&
>          R->Value == Value)
>        return -1;
> @@ -363,7 +363,7 @@
>  template <class ELFT>
>  static void reportDuplicate(SymbolBody *Existing, InputSectionBase *ErrSec,
>                              typename ELFT::uint ErrOffset) {
> -  DefinedRegular<ELFT> *D = dyn_cast<DefinedRegular<ELFT>>(Existing);
> +  DefinedRegular *D = dyn_cast<DefinedRegular>(Existing);
>    if (!D || !D->Section || !ErrSec) {
>      reportDuplicate(Existing, ErrSec ? ErrSec->getFile<ELFT>() : nullptr);
>      return;
> @@ -388,8 +388,8 @@
>    int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, Binding,
>                                            Section == nullptr, Value);
>    if (Cmp > 0)
> -    replaceBody<DefinedRegular<ELFT>>(S, Name, /*IsLocal=*/false, StOther, Type,
> -                                      Value, Size, Section, File);
> +    replaceBody<DefinedRegular>(S, Name, /*IsLocal=*/false, StOther, Type,
> +                                Value, Size, Section, File);
>    else if (Cmp == 0)
>      reportDuplicate<ELFT>(S->body(), Section, Value);
>    return S;
> @@ -446,8 +446,8 @@
>    int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, Binding,
>                                            /*IsAbs*/ false, /*Value*/ 0);
>    if (Cmp > 0)
> -    replaceBody<DefinedRegular<ELFT>>(S, Name, /*IsLocal=*/false, StOther, Type,
> -                                      0, 0, nullptr, F);
> +    replaceBody<DefinedRegular>(S, Name, /*IsLocal=*/false, StOther, Type, 0, 0,
> +                                nullptr, F);
>    else if (Cmp == 0)
>      reportDuplicate(S->body(), F);
>    return S;
> Index: lld/ELF/Relocations.cpp
> ===================================================================
> --- lld/ELF/Relocations.cpp
> +++ lld/ELF/Relocations.cpp
> @@ -292,7 +292,7 @@
>  template <class ELFT> static bool isAbsolute(const SymbolBody &Body) {
>    if (Body.isUndefined())
>      return !Body.isLocal() && Body.symbol()->isWeak();
> -  if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(&Body))
> +  if (const auto *DR = dyn_cast<DefinedRegular>(&Body))
>      return DR->Section == nullptr; // Absolute symbol.
>    return false;
>  }
> @@ -352,7 +352,7 @@
>    if (AbsVal && RelE) {
>      if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
>        return true;
> -    if (&Body == ElfSym<ELFT>::MipsGpDisp)
> +    if (&Body == ElfSym::MipsGpDisp)
>        return true;
>      error(S.getLocation<ELFT>(RelOff) + ": relocation " + toString(Type) +
>            " cannot refer to absolute symbol '" + toString(Body) +
> Index: lld/ELF/OutputSections.h
> ===================================================================
> --- lld/ELF/OutputSections.h
> +++ lld/ELF/OutputSections.h
> @@ -31,7 +31,7 @@
>  template <class ELFT> class ObjectFile;
>  template <class ELFT> class SharedFile;
>  class SharedSymbol;
> -template <class ELFT> class DefinedRegular;
> +class DefinedRegular;
>  
>  // This represents a section in an output file.
>  // It is composed of multiple InputSections.
> Index: lld/ELF/MarkLive.cpp
> ===================================================================
> --- lld/ELF/MarkLive.cpp
> +++ lld/ELF/MarkLive.cpp
> @@ -46,7 +46,7 @@
>  // was resolved to an offset within a section.
>  template <class ELFT> struct ResolvedReloc {
>    InputSectionBase *Sec;
> -  typename ELFT::uint Offset;
> +  uint64_t Offset;
>  };
>  } // end anonymous namespace
>  
> @@ -66,7 +66,7 @@
>  template <class ELFT, class RelT>
>  static ResolvedReloc<ELFT> resolveReloc(InputSectionBase &Sec, RelT &Rel) {
>    SymbolBody &B = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
> -  auto *D = dyn_cast<DefinedRegular<ELFT>>(&B);
> +  auto *D = dyn_cast<DefinedRegular>(&B);
>    if (!D || !D->Section)
>      return {nullptr, 0};
>    typename ELFT::uint Offset = D->Value;
> @@ -217,7 +217,7 @@
>    };
>  
>    auto MarkSymbol = [&](const SymbolBody *Sym) {
> -    if (auto *D = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym))
> +    if (auto *D = dyn_cast_or_null<DefinedRegular>(Sym))
>        Enqueue({D->Section, D->Value});
>    };
>  
> Index: lld/ELF/MapFile.cpp
> ===================================================================
> --- lld/ELF/MapFile.cpp
> +++ lld/ELF/MapFile.cpp
> @@ -80,7 +80,7 @@
>    OS << '\n';
>  
>    for (SymbolBody *Sym : File->getSymbols()) {
> -    auto *DR = dyn_cast<DefinedRegular<ELFT>>(Sym);
> +    auto *DR = dyn_cast<DefinedRegular>(Sym);
>      if (!DR)
>        continue;
>      if (DR->Section != IS)
> Index: lld/ELF/LinkerScript.cpp
> ===================================================================
> --- lld/ELF/LinkerScript.cpp
> +++ lld/ELF/LinkerScript.cpp
> @@ -63,9 +63,8 @@
>        Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
>        /*File*/ nullptr);
>    Sym->Binding = STB_GLOBAL;
> -  replaceBody<DefinedRegular<ELFT>>(Sym, Cmd->Name, /*IsLocal=*/false,
> -                                    Visibility, STT_NOTYPE, 0, 0, nullptr,
> -                                    nullptr);
> +  replaceBody<DefinedRegular>(Sym, Cmd->Name, /*IsLocal=*/false, Visibility,
> +                              STT_NOTYPE, 0, 0, nullptr, nullptr);
>    return Sym->body();
>  }
>  
> @@ -131,7 +130,7 @@
>      return;
>    }
>  
> -  cast<DefinedRegular<ELFT>>(Cmd->Sym)->Value = Cmd->Expression(Dot);
> +  cast<DefinedRegular>(Cmd->Sym)->Value = Cmd->Expression(Dot);
>  }
>  
>  template <class ELFT>
> @@ -974,7 +973,7 @@
>  
>  template <class ELFT> bool LinkerScript<ELFT>::isAbsolute(StringRef S) {
>    SymbolBody *Sym = Symtab<ELFT>::X->find(S);
> -  auto *DR = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym);
> +  auto *DR = dyn_cast_or_null<DefinedRegular>(Sym);
>    return DR && !DR->Section;
>  }
>  
> Index: lld/ELF/InputSection.h
> ===================================================================
> --- lld/ELF/InputSection.h
> +++ lld/ELF/InputSection.h
> @@ -27,7 +27,7 @@
>  class SymbolBody;
>  struct SectionPiece;
>  
> -template <class ELFT> class DefinedRegular;
> +class DefinedRegular;
>  template <class ELFT> class EhFrameSection;
>  template <class ELFT> class MergeSyntheticSection;
>  template <class ELFT> class ObjectFile;
> @@ -117,8 +117,7 @@
>      return getFile<ELFT>()->getObj();
>    }
>  
> -  template <class ELFT>
> -  uint64_t getOffset(const DefinedRegular<ELFT> &Sym) const;
> +  template <class ELFT> uint64_t getOffset(const DefinedRegular &Sym) const;
>  
>    template <class ELFT> InputSectionBase *getLinkOrderDep() const;
>    // Translate an offset in the input section to an offset in the output
> Index: lld/ELF/InputSection.cpp
> ===================================================================
> --- lld/ELF/InputSection.cpp
> +++ lld/ELF/InputSection.cpp
> @@ -148,7 +148,7 @@
>  }
>  
>  template <class ELFT>
> -uint64_t InputSectionBase::getOffset(const DefinedRegular<ELFT> &Sym) const {
> +uint64_t InputSectionBase::getOffset(const DefinedRegular &Sym) const {
>    return getOffset<ELFT>(Sym.Value);
>  }
>  
> @@ -175,7 +175,7 @@
>  
>    // Find a function symbol that encloses a given location.
>    for (SymbolBody *B : getFile<ELFT>()->getSymbols())
> -    if (auto *D = dyn_cast<DefinedRegular<ELFT>>(B))
> +    if (auto *D = dyn_cast<DefinedRegular>(B))
>        if (D->Section == this && D->Type == STT_FUNC)
>          if (D->Value <= Offset && Offset < D->Value + D->Size)
>            return SrcFile + ":(function " + toString(*D) + ")";
> @@ -248,7 +248,7 @@
>        // avoid having to parse and recreate .eh_frame, we just replace any
>        // relocation in it pointing to discarded sections with R_*_NONE, which
>        // hopefully creates a frame that is ignored at runtime.
> -      InputSectionBase *Section = cast<DefinedRegular<ELFT>>(Body).Section;
> +      InputSectionBase *Section = cast<DefinedRegular>(Body).Section;
>        if (Section == &InputSection::Discarded) {
>          P->setSymbolAndType(0, 0, false);
>          continue;
> @@ -838,13 +838,13 @@
>  template InputSectionBase *InputSection::getRelocatedSection<ELF64BE>();
>  
>  template uint64_t
> -InputSectionBase::getOffset(const DefinedRegular<ELF32LE> &Sym) const;
> +InputSectionBase::getOffset<ELF32LE>(const DefinedRegular &Sym) const;
>  template uint64_t
> -InputSectionBase::getOffset(const DefinedRegular<ELF32BE> &Sym) const;
> +InputSectionBase::getOffset<ELF32BE>(const DefinedRegular &Sym) const;
>  template uint64_t
> -InputSectionBase::getOffset(const DefinedRegular<ELF64LE> &Sym) const;
> +InputSectionBase::getOffset<ELF64LE>(const DefinedRegular &Sym) const;
>  template uint64_t
> -InputSectionBase::getOffset(const DefinedRegular<ELF64BE> &Sym) const;
> +InputSectionBase::getOffset<ELF64BE>(const DefinedRegular &Sym) const;
>  
>  template uint64_t InputSectionBase::getOffset<ELF32LE>(uint64_t Offset) const;
>  template uint64_t InputSectionBase::getOffset<ELF32BE>(uint64_t Offset) const;
> Index: lld/ELF/InputFiles.cpp
> ===================================================================
> --- lld/ELF/InputFiles.cpp
> +++ lld/ELF/InputFiles.cpp
> @@ -514,8 +514,8 @@
>        return new (BAlloc)
>            Undefined(Name, /*IsLocal=*/true, StOther, Type, this);
>  
> -    return new (BAlloc) DefinedRegular<ELFT>(Name, /*IsLocal=*/true, StOther,
> -                                             Type, Value, Size, Sec, this);
> +    return new (BAlloc) DefinedRegular(Name, /*IsLocal=*/true, StOther, Type,
> +                                       Value, Size, Sec, this);
>    }
>  
>    StringRef Name = check(Sym->getName(this->StringTable));
> Index: lld/ELF/ICF.cpp
> ===================================================================
> --- lld/ELF/ICF.cpp
> +++ lld/ELF/ICF.cpp
> @@ -245,8 +245,8 @@
>      if (&SA == &SB)
>        return true;
>  
> -    auto *DA = dyn_cast<DefinedRegular<ELFT>>(&SA);
> -    auto *DB = dyn_cast<DefinedRegular<ELFT>>(&SB);
> +    auto *DA = dyn_cast<DefinedRegular>(&SA);
> +    auto *DB = dyn_cast<DefinedRegular>(&SB);
>      if (!DA || !DB)
>        return false;
>      if (DA->Value != DB->Value)


More information about the llvm-commits mailing list