diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /lld/ELF/Arch/Mips.cpp | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'lld/ELF/Arch/Mips.cpp')
-rw-r--r-- | lld/ELF/Arch/Mips.cpp | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/lld/ELF/Arch/Mips.cpp b/lld/ELF/Arch/Mips.cpp index ed6f4ca24130..fd1c5f507734 100644 --- a/lld/ELF/Arch/Mips.cpp +++ b/lld/ELF/Arch/Mips.cpp @@ -18,9 +18,9 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::ELF; +using namespace lld; +using namespace lld::elf; -namespace lld { -namespace elf { namespace { template <class ELFT> class MIPS final : public TargetInfo { public: @@ -37,7 +37,8 @@ public: bool needsThunk(RelExpr expr, RelType type, const InputFile *file, uint64_t branchAddr, const Symbol &s, int64_t a) const override; - void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override; + void relocate(uint8_t *loc, const Relocation &rel, + uint64_t val) const override; bool usesOnlyLowPageBits(RelType type) const override; }; } // namespace @@ -274,12 +275,12 @@ template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *buf) const { write16(buf + 18, 0x0f83); // move $28, $3 write16(buf + 20, 0x472b); // jalrc $25 write16(buf + 22, 0x0c00); // nop - relocateOne(buf, R_MICROMIPS_PC19_S2, gotPlt - plt); + relocateNoSym(buf, R_MICROMIPS_PC19_S2, gotPlt - plt); } else { write16(buf + 18, 0x45f9); // jalrc $25 write16(buf + 20, 0x0f83); // move $28, $3 write16(buf + 22, 0x0c00); // nop - relocateOne(buf, R_MICROMIPS_PC23_S2, gotPlt - plt); + relocateNoSym(buf, R_MICROMIPS_PC23_S2, gotPlt - plt); } return; } @@ -330,13 +331,13 @@ void MIPS<ELFT>::writePlt(uint8_t *buf, const Symbol &sym, write16(buf + 4, 0xff22); // lw $25, 0($2) write16(buf + 8, 0x0f02); // move $24, $2 write16(buf + 10, 0x4723); // jrc $25 / jr16 $25 - relocateOne(buf, R_MICROMIPS_PC19_S2, gotPltEntryAddr - pltEntryAddr); + relocateNoSym(buf, R_MICROMIPS_PC19_S2, gotPltEntryAddr - pltEntryAddr); } else { write16(buf, 0x7900); // addiupc $2, (GOTPLT) - . write16(buf + 4, 0xff22); // lw $25, 0($2) write16(buf + 8, 0x4599); // jrc $25 / jr16 $25 write16(buf + 10, 0x0f02); // move $24, $2 - relocateOne(buf, R_MICROMIPS_PC23_S2, gotPltEntryAddr - pltEntryAddr); + relocateNoSym(buf, R_MICROMIPS_PC23_S2, gotPltEntryAddr - pltEntryAddr); } return; } @@ -537,8 +538,10 @@ static uint64_t fixupCrossModeJump(uint8_t *loc, RelType type, uint64_t val) { } template <class ELFT> -void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { +void MIPS<ELFT>::relocate(uint8_t *loc, const Relocation &rel, + uint64_t val) const { const endianness e = ELFT::TargetEndianness; + RelType type = rel.type; if (ELFT::Is64Bits || config->mipsN32Abi) std::tie(type, val) = calculateMipsRelChain(loc, type, val); @@ -577,7 +580,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { if (config->relocatable) { writeValue(loc, val + 0x8000, 16, 16); } else { - checkInt(loc, val, 16, type); + checkInt(loc, val, 16, rel); writeValue(loc, val, 16, 0); } break; @@ -585,7 +588,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { if (config->relocatable) { writeShuffleValue<e>(loc, val + 0x8000, 16, 16); } else { - checkInt(loc, val, 16, type); + checkInt(loc, val, 16, rel); writeShuffleValue<e>(loc, val, 16, 0); } break; @@ -596,7 +599,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { case R_MIPS_TLS_GD: case R_MIPS_TLS_GOTTPREL: case R_MIPS_TLS_LDM: - checkInt(loc, val, 16, type); + checkInt(loc, val, 16, rel); LLVM_FALLTHROUGH; case R_MIPS_CALL_LO16: case R_MIPS_GOT_LO16: @@ -610,7 +613,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { case R_MICROMIPS_GPREL16: case R_MICROMIPS_TLS_GD: case R_MICROMIPS_TLS_LDM: - checkInt(loc, val, 16, type); + checkInt(loc, val, 16, rel); writeShuffleValue<e>(loc, val, 16, 0); break; case R_MICROMIPS_CALL16: @@ -622,7 +625,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { writeShuffleValue<e>(loc, val, 16, 0); break; case R_MICROMIPS_GPREL7_S2: - checkInt(loc, val, 7, type); + checkInt(loc, val, 7, rel); writeShuffleValue<e>(loc, val, 7, 2); break; case R_MIPS_CALL_HI16: @@ -665,23 +668,23 @@ void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { // Ignore this optimization relocation for now break; case R_MIPS_PC16: - checkAlignment(loc, val, 4, type); - checkInt(loc, val, 18, type); + checkAlignment(loc, val, 4, rel); + checkInt(loc, val, 18, rel); writeValue(loc, val, 16, 2); break; case R_MIPS_PC19_S2: - checkAlignment(loc, val, 4, type); - checkInt(loc, val, 21, type); + checkAlignment(loc, val, 4, rel); + checkInt(loc, val, 21, rel); writeValue(loc, val, 19, 2); break; case R_MIPS_PC21_S2: - checkAlignment(loc, val, 4, type); - checkInt(loc, val, 23, type); + checkAlignment(loc, val, 4, rel); + checkInt(loc, val, 23, rel); writeValue(loc, val, 21, 2); break; case R_MIPS_PC26_S2: - checkAlignment(loc, val, 4, type); - checkInt(loc, val, 28, type); + checkAlignment(loc, val, 4, rel); + checkInt(loc, val, 28, rel); writeValue(loc, val, 26, 2); break; case R_MIPS_PC32: @@ -689,35 +692,35 @@ void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { break; case R_MICROMIPS_26_S1: case R_MICROMIPS_PC26_S1: - checkInt(loc, val, 27, type); + checkInt(loc, val, 27, rel); writeShuffleValue<e>(loc, val, 26, 1); break; case R_MICROMIPS_PC7_S1: - checkInt(loc, val, 8, type); + checkInt(loc, val, 8, rel); writeMicroRelocation16<e>(loc, val, 7, 1); break; case R_MICROMIPS_PC10_S1: - checkInt(loc, val, 11, type); + checkInt(loc, val, 11, rel); writeMicroRelocation16<e>(loc, val, 10, 1); break; case R_MICROMIPS_PC16_S1: - checkInt(loc, val, 17, type); + checkInt(loc, val, 17, rel); writeShuffleValue<e>(loc, val, 16, 1); break; case R_MICROMIPS_PC18_S3: - checkInt(loc, val, 21, type); + checkInt(loc, val, 21, rel); writeShuffleValue<e>(loc, val, 18, 3); break; case R_MICROMIPS_PC19_S2: - checkInt(loc, val, 21, type); + checkInt(loc, val, 21, rel); writeShuffleValue<e>(loc, val, 19, 2); break; case R_MICROMIPS_PC21_S1: - checkInt(loc, val, 22, type); + checkInt(loc, val, 22, rel); writeShuffleValue<e>(loc, val, 21, 1); break; case R_MICROMIPS_PC23_S2: - checkInt(loc, val, 25, type); + checkInt(loc, val, 25, rel); writeShuffleValue<e>(loc, val, 23, 2); break; default: @@ -731,7 +734,7 @@ template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType type) const { } // Return true if the symbol is a PIC function. -template <class ELFT> bool isMipsPIC(const Defined *sym) { +template <class ELFT> bool elf::isMipsPIC(const Defined *sym) { if (!sym->isFunc()) return false; @@ -749,20 +752,17 @@ template <class ELFT> bool isMipsPIC(const Defined *sym) { return file->getObj().getHeader()->e_flags & EF_MIPS_PIC; } -template <class ELFT> TargetInfo *getMipsTargetInfo() { +template <class ELFT> TargetInfo *elf::getMipsTargetInfo() { static MIPS<ELFT> target; return ⌖ } -template TargetInfo *getMipsTargetInfo<ELF32LE>(); -template TargetInfo *getMipsTargetInfo<ELF32BE>(); -template TargetInfo *getMipsTargetInfo<ELF64LE>(); -template TargetInfo *getMipsTargetInfo<ELF64BE>(); +template TargetInfo *elf::getMipsTargetInfo<ELF32LE>(); +template TargetInfo *elf::getMipsTargetInfo<ELF32BE>(); +template TargetInfo *elf::getMipsTargetInfo<ELF64LE>(); +template TargetInfo *elf::getMipsTargetInfo<ELF64BE>(); -template bool isMipsPIC<ELF32LE>(const Defined *); -template bool isMipsPIC<ELF32BE>(const Defined *); -template bool isMipsPIC<ELF64LE>(const Defined *); -template bool isMipsPIC<ELF64BE>(const Defined *); - -} // namespace elf -} // namespace lld +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 *); |