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.

llvm-svn: 317525
This commit is contained in:
Rui Ueyama 2017-11-07 00:04:22 +00:00
parent 2b881f567f
commit 7957b08e87
5 changed files with 22 additions and 21 deletions

View 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 *);

View 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;

View 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;

View 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;
}

View 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))