Move MIPS-specific code from Symbols.cpp to MIPS.cpp.
authorRui Ueyama <ruiu@google.com>
Tue, 7 Nov 2017 00:04:22 +0000 (00:04 +0000)
committerRui Ueyama <ruiu@google.com>
Tue, 7 Nov 2017 00:04:22 +0000 (00:04 +0000)
We have a lot of "if (MIPS)" conditions in lld because the MIPS' ABI
is different at various places than other arch's ABIs at where it
don't have to be different, but we at least want to reduce MIPS-ness
from the regular classes.

llvm-svn: 317525

lld/ELF/Arch/Mips.cpp
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/SyntheticSections.cpp
lld/ELF/Target.h

index 534ea5d..771b8a5 100644 (file)
@@ -349,7 +349,7 @@ bool MIPS<ELFT>::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
   auto *D = dyn_cast<Defined>(&S);
   // LA25 is required if target file has PIC code
   // or target symbol is a PIC symbol.
-  return D && D->isMipsPIC<ELFT>();
+  return D && isMipsPIC<ELFT>(D);
 }
 
 template <class ELFT>
@@ -644,6 +644,18 @@ template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType Type) const {
          Type == R_MICROMIPS_LO16 || Type == R_MICROMIPS_GOT_OFST;
 }
 
+// Return true if the symbol is a PIC function.
+template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {
+  typedef typename ELFT::Ehdr Elf_Ehdr;
+  if (!Sym->Section || !Sym->isFunc())
+    return false;
+
+  auto *Sec = cast<InputSectionBase>(Sym->Section);
+  const Elf_Ehdr *Hdr = Sec->template getFile<ELFT>()->getObj().getHeader();
+  return (Sym->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
+         (Hdr->e_flags & EF_MIPS_PIC);
+}
+
 template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
   static MIPS<ELFT> Target;
   return &Target;
@@ -653,3 +665,8 @@ template TargetInfo *elf::getMipsTargetInfo<ELF32LE>();
 template TargetInfo *elf::getMipsTargetInfo<ELF32BE>();
 template TargetInfo *elf::getMipsTargetInfo<ELF64LE>();
 template TargetInfo *elf::getMipsTargetInfo<ELF64BE>();
+
+template bool elf::isMipsPIC<ELF32LE>(const Defined *);
+template bool elf::isMipsPIC<ELF32BE>(const Defined *);
+template bool elf::isMipsPIC<ELF64LE>(const Defined *);
+template bool elf::isMipsPIC<ELF64BE>(const Defined *);
index 70c510c..9822a2a 100644 (file)
@@ -247,17 +247,6 @@ void Symbol::parseSymbolVersion() {
           Verstr);
 }
 
-template <class ELFT> bool Defined::isMipsPIC() const {
-  typedef typename ELFT::Ehdr Elf_Ehdr;
-  if (!Section || !isFunc())
-    return false;
-
-  auto *Sec = cast<InputSectionBase>(Section);
-  const Elf_Ehdr *Hdr = Sec->template getFile<ELFT>()->getObj().getHeader();
-  return (this->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
-         (Hdr->e_flags & EF_MIPS_PIC);
-}
-
 InputFile *Lazy::fetch() {
   if (auto *S = dyn_cast<LazyArchive>(this))
     return S->fetch();
@@ -330,8 +319,3 @@ std::string lld::toString(const Symbol &B) {
       return *S;
   return B.getName();
 }
-
-template bool Defined::template isMipsPIC<ELF32LE>() const;
-template bool Defined::template isMipsPIC<ELF32BE>() const;
-template bool Defined::template isMipsPIC<ELF64LE>() const;
-template bool Defined::template isMipsPIC<ELF64BE>() const;
index a8ee09a..074ae50 100644 (file)
@@ -190,9 +190,6 @@ public:
       : Symbol(DefinedKind, Name, IsLocal, StOther, Type), Value(Value),
         Size(Size), Section(Section) {}
 
-  // Return true if the symbol is a PIC function.
-  template <class ELFT> bool isMipsPIC() const;
-
   static bool classof(const Symbol *S) { return S->isDefined(); }
 
   uint64_t Value;
index 0cced1f..101b717 100644 (file)
@@ -1622,7 +1622,7 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
 
       if (Config->Relocatable)
         if (auto *D = dyn_cast<Defined>(Sym))
-          if (D->isMipsPIC<ELFT>())
+          if (isMipsPIC<ELFT>(D))
             ESym->st_other |= STO_MIPS_PIC;
       ++ESym;
     }
index 6d666e8..eddadca 100644 (file)
@@ -18,6 +18,7 @@ namespace lld {
 std::string toString(elf::RelType Type);
 
 namespace elf {
+class Defined;
 class InputFile;
 class Symbol;
 
@@ -141,6 +142,8 @@ uint64_t getAArch64Page(uint64_t Expr);
 extern TargetInfo *Target;
 TargetInfo *getTarget();
 
+template <class ELFT> bool isMipsPIC(const Defined *Sym);
+
 template <unsigned N>
 static void checkInt(uint8_t *Loc, int64_t V, RelType Type) {
   if (!llvm::isInt<N>(V))