[lld] r317525 - Move MIPS-specific code from Symbols.cpp to MIPS.cpp.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 16:04:22 PST 2017
Author: ruiu
Date: Mon Nov 6 16:04:22 2017
New Revision: 317525
URL: http://llvm.org/viewvc/llvm-project?rev=317525&view=rev
Log:
Move MIPS-specific code from Symbols.cpp to MIPS.cpp.
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.
Modified:
lld/trunk/ELF/Arch/Mips.cpp
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/ELF/Target.h
Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=317525&r1=317524&r2=317525&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Mon Nov 6 16:04:22 2017
@@ -349,7 +349,7 @@ bool MIPS<ELFT>::needsThunk(RelExpr Expr
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>::u
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::getMipsTargetI
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 *);
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=317525&r1=317524&r2=317525&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Nov 6 16:04:22 2017
@@ -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 &
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;
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=317525&r1=317524&r2=317525&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Mon Nov 6 16:04:22 2017
@@ -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;
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=317525&r1=317524&r2=317525&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Nov 6 16:04:22 2017
@@ -1622,7 +1622,7 @@ template <class ELFT> void SymbolTableSe
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;
}
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=317525&r1=317524&r2=317525&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Mon Nov 6 16:04:22 2017
@@ -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))
More information about the llvm-commits
mailing list