2017-06-17 01:32:43 +08:00
|
|
|
//===- MIPS.cpp -----------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "InputFiles.h"
|
|
|
|
#include "OutputSections.h"
|
|
|
|
#include "Symbols.h"
|
|
|
|
#include "SyntheticSections.h"
|
|
|
|
#include "Target.h"
|
|
|
|
#include "Thunks.h"
|
[lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits
Differential Revision: https://reviews.llvm.org/D39259
llvm-svn: 316624
2017-10-26 06:28:38 +08:00
|
|
|
#include "lld/Common/ErrorHandler.h"
|
2017-06-17 01:32:43 +08:00
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
using namespace llvm::support::endian;
|
|
|
|
using namespace llvm::ELF;
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::elf;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
template <class ELFT> class MIPS final : public TargetInfo {
|
|
|
|
public:
|
|
|
|
MIPS();
|
2017-10-25 01:01:40 +08:00
|
|
|
uint32_t calcEFlags() const override;
|
2017-11-04 05:21:47 +08:00
|
|
|
RelExpr getRelExpr(RelType Type, const Symbol &S,
|
2017-06-17 01:32:43 +08:00
|
|
|
const uint8_t *Loc) const override;
|
2017-10-12 06:49:24 +08:00
|
|
|
int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override;
|
|
|
|
RelType getDynRel(RelType Type) const override;
|
2017-11-04 05:21:47 +08:00
|
|
|
void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;
|
2017-06-17 01:32:43 +08:00
|
|
|
void writePltHeader(uint8_t *Buf) const override;
|
|
|
|
void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,
|
|
|
|
int32_t Index, unsigned RelOff) const override;
|
2017-10-12 06:49:24 +08:00
|
|
|
bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
|
2017-11-04 05:21:47 +08:00
|
|
|
uint64_t BranchAddr, const Symbol &S) const override;
|
2017-10-12 06:49:24 +08:00
|
|
|
void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;
|
|
|
|
bool usesOnlyLowPageBits(RelType Type) const override;
|
2017-06-17 01:32:43 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
template <class ELFT> MIPS<ELFT>::MIPS() {
|
|
|
|
GotPltHeaderEntriesNum = 2;
|
|
|
|
DefaultMaxPageSize = 65536;
|
|
|
|
GotEntrySize = sizeof(typename ELFT::uint);
|
|
|
|
GotPltEntrySize = sizeof(typename ELFT::uint);
|
2018-03-19 14:52:51 +08:00
|
|
|
GotBaseSymInGotPlt = false;
|
2017-06-17 01:32:43 +08:00
|
|
|
PltEntrySize = 16;
|
|
|
|
PltHeaderSize = 32;
|
|
|
|
CopyRel = R_MIPS_COPY;
|
|
|
|
PltRel = R_MIPS_JUMP_SLOT;
|
|
|
|
NeedsThunks = true;
|
2017-06-27 03:45:53 +08:00
|
|
|
TrapInstr = 0xefefefef;
|
2017-06-17 01:32:43 +08:00
|
|
|
|
|
|
|
if (ELFT::Is64Bits) {
|
|
|
|
RelativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;
|
|
|
|
TlsGotRel = R_MIPS_TLS_TPREL64;
|
|
|
|
TlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;
|
|
|
|
TlsOffsetRel = R_MIPS_TLS_DTPREL64;
|
|
|
|
} else {
|
|
|
|
RelativeRel = R_MIPS_REL32;
|
|
|
|
TlsGotRel = R_MIPS_TLS_TPREL32;
|
|
|
|
TlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;
|
|
|
|
TlsOffsetRel = R_MIPS_TLS_DTPREL32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-25 01:01:40 +08:00
|
|
|
template <class ELFT> uint32_t MIPS<ELFT>::calcEFlags() const {
|
|
|
|
return calcMipsEFlags<ELFT>();
|
|
|
|
}
|
|
|
|
|
2017-06-17 01:32:43 +08:00
|
|
|
template <class ELFT>
|
2017-11-04 05:21:47 +08:00
|
|
|
RelExpr MIPS<ELFT>::getRelExpr(RelType Type, const Symbol &S,
|
2017-06-17 01:32:43 +08:00
|
|
|
const uint8_t *Loc) const {
|
|
|
|
// See comment in the calculateMipsRelChain.
|
|
|
|
if (ELFT::Is64Bits || Config->MipsN32Abi)
|
|
|
|
Type &= 0xff;
|
2017-10-12 11:14:06 +08:00
|
|
|
|
2017-06-17 01:32:43 +08:00
|
|
|
switch (Type) {
|
|
|
|
case R_MIPS_JALR:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_JALR:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_HINT;
|
|
|
|
case R_MIPS_GPREL16:
|
|
|
|
case R_MIPS_GPREL32:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_GPREL16:
|
|
|
|
case R_MICROMIPS_GPREL7_S2:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_MIPS_GOTREL;
|
|
|
|
case R_MIPS_26:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_26_S1:
|
|
|
|
return R_PLT;
|
|
|
|
case R_MICROMIPS_PC26_S1:
|
|
|
|
return R_PLT_PC;
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_HI16:
|
|
|
|
case R_MIPS_LO16:
|
2017-09-21 22:40:32 +08:00
|
|
|
case R_MIPS_HIGHER:
|
|
|
|
case R_MIPS_HIGHEST:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_HI16:
|
|
|
|
case R_MICROMIPS_LO16:
|
2017-09-21 22:40:32 +08:00
|
|
|
case R_MICROMIPS_HIGHER:
|
|
|
|
case R_MICROMIPS_HIGHEST:
|
2017-06-17 01:32:43 +08:00
|
|
|
// R_MIPS_HI16/R_MIPS_LO16 relocations against _gp_disp calculate
|
|
|
|
// 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::MipsGpDisp)
|
|
|
|
return R_MIPS_GOT_GP_PC;
|
|
|
|
if (&S == ElfSym::MipsLocalGp)
|
|
|
|
return R_MIPS_GOT_GP;
|
|
|
|
LLVM_FALLTHROUGH;
|
2017-09-21 22:40:32 +08:00
|
|
|
case R_MIPS_32:
|
|
|
|
case R_MIPS_64:
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_GOT_OFST:
|
2017-09-21 22:40:32 +08:00
|
|
|
case R_MIPS_SUB:
|
|
|
|
case R_MIPS_TLS_DTPREL_HI16:
|
|
|
|
case R_MIPS_TLS_DTPREL_LO16:
|
|
|
|
case R_MIPS_TLS_DTPREL32:
|
|
|
|
case R_MIPS_TLS_DTPREL64:
|
|
|
|
case R_MIPS_TLS_TPREL_HI16:
|
|
|
|
case R_MIPS_TLS_TPREL_LO16:
|
|
|
|
case R_MIPS_TLS_TPREL32:
|
|
|
|
case R_MIPS_TLS_TPREL64:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_GOT_OFST:
|
2017-09-21 22:40:32 +08:00
|
|
|
case R_MICROMIPS_SUB:
|
|
|
|
case R_MICROMIPS_TLS_DTPREL_HI16:
|
|
|
|
case R_MICROMIPS_TLS_DTPREL_LO16:
|
|
|
|
case R_MICROMIPS_TLS_TPREL_HI16:
|
|
|
|
case R_MICROMIPS_TLS_TPREL_LO16:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_ABS;
|
|
|
|
case R_MIPS_PC32:
|
|
|
|
case R_MIPS_PC16:
|
|
|
|
case R_MIPS_PC19_S2:
|
|
|
|
case R_MIPS_PC21_S2:
|
|
|
|
case R_MIPS_PC26_S2:
|
|
|
|
case R_MIPS_PCHI16:
|
|
|
|
case R_MIPS_PCLO16:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_PC7_S1:
|
|
|
|
case R_MICROMIPS_PC10_S1:
|
|
|
|
case R_MICROMIPS_PC16_S1:
|
|
|
|
case R_MICROMIPS_PC18_S3:
|
|
|
|
case R_MICROMIPS_PC19_S2:
|
|
|
|
case R_MICROMIPS_PC23_S2:
|
|
|
|
case R_MICROMIPS_PC21_S1:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_PC;
|
|
|
|
case R_MIPS_GOT16:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_GOT16:
|
2017-06-17 01:32:43 +08:00
|
|
|
if (S.isLocal())
|
|
|
|
return R_MIPS_GOT_LOCAL_PAGE;
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case R_MIPS_CALL16:
|
|
|
|
case R_MIPS_GOT_DISP:
|
|
|
|
case R_MIPS_TLS_GOTTPREL:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_CALL16:
|
|
|
|
case R_MICROMIPS_GOT_DISP:
|
|
|
|
case R_MICROMIPS_TLS_GOTTPREL:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_MIPS_GOT_OFF;
|
|
|
|
case R_MIPS_CALL_HI16:
|
|
|
|
case R_MIPS_CALL_LO16:
|
|
|
|
case R_MIPS_GOT_HI16:
|
|
|
|
case R_MIPS_GOT_LO16:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_CALL_HI16:
|
|
|
|
case R_MICROMIPS_CALL_LO16:
|
|
|
|
case R_MICROMIPS_GOT_HI16:
|
|
|
|
case R_MICROMIPS_GOT_LO16:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_MIPS_GOT_OFF32;
|
|
|
|
case R_MIPS_GOT_PAGE:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_GOT_PAGE:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_MIPS_GOT_LOCAL_PAGE;
|
|
|
|
case R_MIPS_TLS_GD:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_TLS_GD:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_MIPS_TLSGD;
|
|
|
|
case R_MIPS_TLS_LDM:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_TLS_LDM:
|
2017-06-17 01:32:43 +08:00
|
|
|
return R_MIPS_TLSLD;
|
2017-09-21 22:40:32 +08:00
|
|
|
case R_MIPS_NONE:
|
|
|
|
return R_NONE;
|
|
|
|
default:
|
2017-10-12 11:14:06 +08:00
|
|
|
return R_INVALID;
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 06:49:24 +08:00
|
|
|
template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {
|
2018-04-05 20:07:20 +08:00
|
|
|
if (Type == R_MIPS_32 || Type == R_MIPS_64)
|
|
|
|
return RelativeRel;
|
|
|
|
return R_MIPS_NONE;
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2017-11-04 05:21:47 +08:00
|
|
|
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
|
2017-11-09 07:34:34 +08:00
|
|
|
uint64_t VA = InX::Plt->getVA();
|
|
|
|
if (isMicroMips())
|
|
|
|
VA |= 1;
|
|
|
|
write32<ELFT::TargetEndianness>(Buf, VA);
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 21:08:24 +08:00
|
|
|
template <endianness E> static uint32_t readShuffle(const uint8_t *Loc) {
|
|
|
|
// The major opcode of a microMIPS instruction needs to appear
|
|
|
|
// in the first 16-bit word (lowest address) for efficient hardware
|
|
|
|
// decode so that it knows if the instruction is 16-bit or 32-bit
|
|
|
|
// as early as possible. To do so, little-endian binaries keep 16-bit
|
|
|
|
// words in a big-endian order. That is why we have to swap these
|
|
|
|
// words to get a correct value.
|
|
|
|
uint32_t V = read32<E>(Loc);
|
|
|
|
if (E == support::little)
|
|
|
|
return (V << 16) | (V >> 16);
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
2017-09-05 00:16:46 +08:00
|
|
|
template <endianness E>
|
2018-01-18 23:59:10 +08:00
|
|
|
static void writeValue(uint8_t *Loc, uint64_t V, uint8_t BitsSize,
|
|
|
|
uint8_t Shift) {
|
2017-06-17 01:32:43 +08:00
|
|
|
uint32_t Instr = read32<E>(Loc);
|
2017-09-05 00:16:46 +08:00
|
|
|
uint32_t Mask = 0xffffffff >> (32 - BitsSize);
|
|
|
|
uint32_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
|
2017-08-25 05:57:03 +08:00
|
|
|
write32<E>(Loc, Data);
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 21:08:24 +08:00
|
|
|
template <endianness E>
|
2018-01-29 22:00:51 +08:00
|
|
|
static void writeShuffleValue(uint8_t *Loc, uint64_t V, uint8_t BitsSize,
|
|
|
|
uint8_t Shift) {
|
2017-09-12 21:08:24 +08:00
|
|
|
// See comments in readShuffle for purpose of this code.
|
|
|
|
uint16_t *Words = (uint16_t *)Loc;
|
|
|
|
if (E == support::little)
|
|
|
|
std::swap(Words[0], Words[1]);
|
|
|
|
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, V, BitsSize, Shift);
|
2017-09-12 21:08:24 +08:00
|
|
|
|
|
|
|
if (E == support::little)
|
|
|
|
std::swap(Words[0], Words[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <endianness E>
|
|
|
|
static void writeMicroRelocation16(uint8_t *Loc, uint64_t V, uint8_t BitsSize,
|
|
|
|
uint8_t Shift) {
|
|
|
|
uint16_t Instr = read16<E>(Loc);
|
|
|
|
uint16_t Mask = 0xffff >> (16 - BitsSize);
|
|
|
|
uint16_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
|
|
|
|
write16<E>(Loc, Data);
|
|
|
|
}
|
|
|
|
|
2017-06-17 01:32:43 +08:00
|
|
|
template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
|
|
|
|
const endianness E = ELFT::TargetEndianness;
|
2017-10-02 22:56:41 +08:00
|
|
|
if (isMicroMips()) {
|
2017-10-27 07:54:00 +08:00
|
|
|
uint64_t GotPlt = InX::GotPlt->getVA();
|
|
|
|
uint64_t Plt = InX::Plt->getVA();
|
2017-09-12 21:08:24 +08:00
|
|
|
// Overwrite trap instructions written by Writer::writeTrapInstr.
|
|
|
|
memset(Buf, 0, PltHeaderSize);
|
|
|
|
|
2017-10-02 22:56:41 +08:00
|
|
|
write16<E>(Buf, isMipsR6() ? 0x7860 : 0x7980); // addiupc v1, (GOTPLT) - .
|
2017-09-12 21:08:24 +08:00
|
|
|
write16<E>(Buf + 4, 0xff23); // lw $25, 0($3)
|
|
|
|
write16<E>(Buf + 8, 0x0535); // subu16 $2, $2, $3
|
|
|
|
write16<E>(Buf + 10, 0x2525); // srl16 $2, $2, 2
|
|
|
|
write16<E>(Buf + 12, 0x3302); // addiu $24, $2, -2
|
|
|
|
write16<E>(Buf + 14, 0xfffe);
|
|
|
|
write16<E>(Buf + 16, 0x0dff); // move $15, $31
|
2017-10-02 22:56:41 +08:00
|
|
|
if (isMipsR6()) {
|
2017-09-12 21:08:24 +08:00
|
|
|
write16<E>(Buf + 18, 0x0f83); // move $28, $3
|
|
|
|
write16<E>(Buf + 20, 0x472b); // jalrc $25
|
|
|
|
write16<E>(Buf + 22, 0x0c00); // nop
|
|
|
|
relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPlt - Plt);
|
|
|
|
} else {
|
|
|
|
write16<E>(Buf + 18, 0x45f9); // jalrc $25
|
|
|
|
write16<E>(Buf + 20, 0x0f83); // move $28, $3
|
|
|
|
write16<E>(Buf + 22, 0x0c00); // nop
|
|
|
|
relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPlt - Plt);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-17 01:32:43 +08:00
|
|
|
if (Config->MipsN32Abi) {
|
|
|
|
write32<E>(Buf, 0x3c0e0000); // lui $14, %hi(&GOTPLT[0])
|
|
|
|
write32<E>(Buf + 4, 0x8dd90000); // lw $25, %lo(&GOTPLT[0])($14)
|
|
|
|
write32<E>(Buf + 8, 0x25ce0000); // addiu $14, $14, %lo(&GOTPLT[0])
|
|
|
|
write32<E>(Buf + 12, 0x030ec023); // subu $24, $24, $14
|
2017-11-22 20:34:29 +08:00
|
|
|
write32<E>(Buf + 16, 0x03e07825); // move $15, $31
|
|
|
|
write32<E>(Buf + 20, 0x0018c082); // srl $24, $24, 2
|
|
|
|
} else if (ELFT::Is64Bits) {
|
|
|
|
write32<E>(Buf, 0x3c0e0000); // lui $14, %hi(&GOTPLT[0])
|
|
|
|
write32<E>(Buf + 4, 0xddd90000); // ld $25, %lo(&GOTPLT[0])($14)
|
|
|
|
write32<E>(Buf + 8, 0x25ce0000); // addiu $14, $14, %lo(&GOTPLT[0])
|
|
|
|
write32<E>(Buf + 12, 0x030ec023); // subu $24, $24, $14
|
|
|
|
write32<E>(Buf + 16, 0x03e07825); // move $15, $31
|
|
|
|
write32<E>(Buf + 20, 0x0018c0c2); // srl $24, $24, 3
|
2017-06-17 01:32:43 +08:00
|
|
|
} else {
|
|
|
|
write32<E>(Buf, 0x3c1c0000); // lui $28, %hi(&GOTPLT[0])
|
|
|
|
write32<E>(Buf + 4, 0x8f990000); // lw $25, %lo(&GOTPLT[0])($28)
|
|
|
|
write32<E>(Buf + 8, 0x279c0000); // addiu $28, $28, %lo(&GOTPLT[0])
|
|
|
|
write32<E>(Buf + 12, 0x031cc023); // subu $24, $24, $28
|
2017-11-22 20:34:29 +08:00
|
|
|
write32<E>(Buf + 16, 0x03e07825); // move $15, $31
|
|
|
|
write32<E>(Buf + 20, 0x0018c082); // srl $24, $24, 2
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
2018-02-21 07:49:17 +08:00
|
|
|
uint32_t JalrInst = Config->ZHazardplt ? 0x0320fc09 : 0x0320f809;
|
|
|
|
write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25
|
2017-06-17 01:32:43 +08:00
|
|
|
write32<E>(Buf + 28, 0x2718fffe); // subu $24, $24, 2
|
|
|
|
|
|
|
|
uint64_t GotPlt = InX::GotPlt->getVA();
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Buf, GotPlt + 0x8000, 16, 16);
|
|
|
|
writeValue<E>(Buf + 4, GotPlt, 16, 0);
|
|
|
|
writeValue<E>(Buf + 8, GotPlt, 16, 0);
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
|
|
|
|
uint64_t PltEntryAddr, int32_t Index,
|
|
|
|
unsigned RelOff) const {
|
|
|
|
const endianness E = ELFT::TargetEndianness;
|
2017-10-02 22:56:41 +08:00
|
|
|
if (isMicroMips()) {
|
2017-09-12 21:08:24 +08:00
|
|
|
// Overwrite trap instructions written by Writer::writeTrapInstr.
|
|
|
|
memset(Buf, 0, PltEntrySize);
|
|
|
|
|
2017-10-02 22:56:41 +08:00
|
|
|
if (isMipsR6()) {
|
2017-09-12 21:08:24 +08:00
|
|
|
write16<E>(Buf, 0x7840); // addiupc $2, (GOTPLT) - .
|
|
|
|
write16<E>(Buf + 4, 0xff22); // lw $25, 0($2)
|
|
|
|
write16<E>(Buf + 8, 0x0f02); // move $24, $2
|
|
|
|
write16<E>(Buf + 10, 0x4723); // jrc $25 / jr16 $25
|
|
|
|
relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPltEntryAddr - PltEntryAddr);
|
|
|
|
} else {
|
|
|
|
write16<E>(Buf, 0x7900); // addiupc $2, (GOTPLT) - .
|
|
|
|
write16<E>(Buf + 4, 0xff22); // lw $25, 0($2)
|
|
|
|
write16<E>(Buf + 8, 0x4599); // jrc $25 / jr16 $25
|
|
|
|
write16<E>(Buf + 10, 0x0f02); // move $24, $2
|
|
|
|
relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPltEntryAddr - PltEntryAddr);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-22 04:01:43 +08:00
|
|
|
uint32_t JrInst = isMipsR6() ? (Config->ZHazardplt ? 0x03200409 : 0x03200009)
|
|
|
|
: (Config->ZHazardplt ? 0x03200408 : 0x03200008);
|
2018-02-21 07:49:17 +08:00
|
|
|
|
2017-06-17 01:32:43 +08:00
|
|
|
write32<E>(Buf, 0x3c0f0000); // lui $15, %hi(.got.plt entry)
|
|
|
|
write32<E>(Buf + 4, 0x8df90000); // l[wd] $25, %lo(.got.plt entry)($15)
|
2018-02-21 07:49:17 +08:00
|
|
|
write32<E>(Buf + 8, JrInst); // jr $25 / jr.hb $25
|
2017-06-17 01:32:43 +08:00
|
|
|
write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry)
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
|
|
|
|
writeValue<E>(Buf + 4, GotPltEntryAddr, 16, 0);
|
|
|
|
writeValue<E>(Buf + 12, GotPltEntryAddr, 16, 0);
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2017-10-12 06:49:24 +08:00
|
|
|
bool MIPS<ELFT>::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,
|
2017-11-04 05:21:47 +08:00
|
|
|
uint64_t BranchAddr, const Symbol &S) const {
|
2017-06-17 01:32:43 +08:00
|
|
|
// Any MIPS PIC code function is invoked with its address in register $t9.
|
|
|
|
// So if we have a branch instruction from non-PIC code to the PIC one
|
|
|
|
// we cannot make the jump directly and need to create a small stubs
|
|
|
|
// to save the target function address.
|
|
|
|
// See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
|
2017-09-12 21:08:24 +08:00
|
|
|
if (Type != R_MIPS_26 && Type != R_MICROMIPS_26_S1 &&
|
|
|
|
Type != R_MICROMIPS_PC26_S1)
|
2017-06-17 01:32:43 +08:00
|
|
|
return false;
|
|
|
|
auto *F = dyn_cast_or_null<ELFFileBase<ELFT>>(File);
|
|
|
|
if (!F)
|
|
|
|
return false;
|
|
|
|
// If current file has PIC code, LA25 stub is not required.
|
|
|
|
if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)
|
|
|
|
return false;
|
2017-11-06 12:35:31 +08:00
|
|
|
auto *D = dyn_cast<Defined>(&S);
|
2017-06-17 01:32:43 +08:00
|
|
|
// LA25 is required if target file has PIC code
|
|
|
|
// or target symbol is a PIC symbol.
|
2017-11-07 08:04:22 +08:00
|
|
|
return D && isMipsPIC<ELFT>(D);
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2017-10-12 06:49:24 +08:00
|
|
|
int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *Buf, RelType Type) const {
|
2017-06-17 01:32:43 +08:00
|
|
|
const endianness E = ELFT::TargetEndianness;
|
|
|
|
switch (Type) {
|
|
|
|
case R_MIPS_32:
|
|
|
|
case R_MIPS_GPREL32:
|
|
|
|
case R_MIPS_TLS_DTPREL32:
|
|
|
|
case R_MIPS_TLS_TPREL32:
|
|
|
|
return SignExtend64<32>(read32<E>(Buf));
|
|
|
|
case R_MIPS_26:
|
|
|
|
// FIXME (simon): If the relocation target symbol is not a PLT entry
|
|
|
|
// we should use another expression for calculation:
|
|
|
|
// ((A << 2) | (P & 0xf0000000)) >> 2
|
2017-08-25 05:56:52 +08:00
|
|
|
return SignExtend64<28>(read32<E>(Buf) << 2);
|
2017-08-25 05:56:58 +08:00
|
|
|
case R_MIPS_GOT16:
|
|
|
|
case R_MIPS_HI16:
|
|
|
|
case R_MIPS_PCHI16:
|
|
|
|
return SignExtend64<16>(read32<E>(Buf)) << 16;
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_GPREL16:
|
|
|
|
case R_MIPS_LO16:
|
|
|
|
case R_MIPS_PCLO16:
|
|
|
|
case R_MIPS_TLS_DTPREL_HI16:
|
|
|
|
case R_MIPS_TLS_DTPREL_LO16:
|
|
|
|
case R_MIPS_TLS_TPREL_HI16:
|
|
|
|
case R_MIPS_TLS_TPREL_LO16:
|
|
|
|
return SignExtend64<16>(read32<E>(Buf));
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_GOT16:
|
|
|
|
case R_MICROMIPS_HI16:
|
|
|
|
return SignExtend64<16>(readShuffle<E>(Buf)) << 16;
|
|
|
|
case R_MICROMIPS_GPREL16:
|
|
|
|
case R_MICROMIPS_LO16:
|
|
|
|
case R_MICROMIPS_TLS_DTPREL_HI16:
|
|
|
|
case R_MICROMIPS_TLS_DTPREL_LO16:
|
|
|
|
case R_MICROMIPS_TLS_TPREL_HI16:
|
|
|
|
case R_MICROMIPS_TLS_TPREL_LO16:
|
|
|
|
return SignExtend64<16>(readShuffle<E>(Buf));
|
|
|
|
case R_MICROMIPS_GPREL7_S2:
|
|
|
|
return SignExtend64<9>(readShuffle<E>(Buf) << 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_PC16:
|
2017-08-25 05:56:52 +08:00
|
|
|
return SignExtend64<18>(read32<E>(Buf) << 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_PC19_S2:
|
2017-08-25 05:56:52 +08:00
|
|
|
return SignExtend64<21>(read32<E>(Buf) << 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_PC21_S2:
|
2017-08-25 05:56:52 +08:00
|
|
|
return SignExtend64<23>(read32<E>(Buf) << 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_PC26_S2:
|
2017-08-25 05:56:52 +08:00
|
|
|
return SignExtend64<28>(read32<E>(Buf) << 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_PC32:
|
2017-08-25 05:56:52 +08:00
|
|
|
return SignExtend64<32>(read32<E>(Buf));
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_26_S1:
|
|
|
|
return SignExtend64<27>(readShuffle<E>(Buf) << 1);
|
|
|
|
case R_MICROMIPS_PC7_S1:
|
|
|
|
return SignExtend64<8>(read16<E>(Buf) << 1);
|
|
|
|
case R_MICROMIPS_PC10_S1:
|
|
|
|
return SignExtend64<11>(read16<E>(Buf) << 1);
|
|
|
|
case R_MICROMIPS_PC16_S1:
|
|
|
|
return SignExtend64<17>(readShuffle<E>(Buf) << 1);
|
|
|
|
case R_MICROMIPS_PC18_S3:
|
|
|
|
return SignExtend64<21>(readShuffle<E>(Buf) << 3);
|
|
|
|
case R_MICROMIPS_PC19_S2:
|
|
|
|
return SignExtend64<21>(readShuffle<E>(Buf) << 2);
|
|
|
|
case R_MICROMIPS_PC21_S1:
|
|
|
|
return SignExtend64<22>(readShuffle<E>(Buf) << 1);
|
|
|
|
case R_MICROMIPS_PC23_S2:
|
|
|
|
return SignExtend64<25>(readShuffle<E>(Buf) << 2);
|
|
|
|
case R_MICROMIPS_PC26_S1:
|
|
|
|
return SignExtend64<27>(readShuffle<E>(Buf) << 1);
|
2017-10-12 11:14:06 +08:00
|
|
|
default:
|
|
|
|
return 0;
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::pair<uint32_t, uint64_t>
|
2017-10-12 06:49:24 +08:00
|
|
|
calculateMipsRelChain(uint8_t *Loc, RelType Type, uint64_t Val) {
|
2017-06-17 01:32:43 +08:00
|
|
|
// MIPS N64 ABI packs multiple relocations into the single relocation
|
|
|
|
// record. In general, all up to three relocations can have arbitrary
|
|
|
|
// types. In fact, Clang and GCC uses only a few combinations. For now,
|
|
|
|
// we support two of them. That is allow to pass at least all LLVM
|
|
|
|
// test suite cases.
|
|
|
|
// <any relocation> / R_MIPS_SUB / R_MIPS_HI16 | R_MIPS_LO16
|
|
|
|
// <any relocation> / R_MIPS_64 / R_MIPS_NONE
|
|
|
|
// The first relocation is a 'real' relocation which is calculated
|
|
|
|
// using the corresponding symbol's value. The second and the third
|
|
|
|
// relocations used to modify result of the first one: extend it to
|
|
|
|
// 64-bit, extract high or low part etc. For details, see part 2.9 Relocation
|
|
|
|
// at the https://dmz-portal.mips.com/mw/images/8/82/007-4658-001.pdf
|
2017-10-12 06:49:24 +08:00
|
|
|
RelType Type2 = (Type >> 8) & 0xff;
|
|
|
|
RelType Type3 = (Type >> 16) & 0xff;
|
2017-06-17 01:32:43 +08:00
|
|
|
if (Type2 == R_MIPS_NONE && Type3 == R_MIPS_NONE)
|
|
|
|
return std::make_pair(Type, Val);
|
|
|
|
if (Type2 == R_MIPS_64 && Type3 == R_MIPS_NONE)
|
|
|
|
return std::make_pair(Type2, Val);
|
|
|
|
if (Type2 == R_MIPS_SUB && (Type3 == R_MIPS_HI16 || Type3 == R_MIPS_LO16))
|
|
|
|
return std::make_pair(Type3, -Val);
|
2017-09-12 21:08:24 +08:00
|
|
|
if (Type2 == R_MICROMIPS_SUB &&
|
|
|
|
(Type3 == R_MICROMIPS_HI16 || Type3 == R_MICROMIPS_LO16))
|
|
|
|
return std::make_pair(Type3, -Val);
|
2017-06-17 01:32:43 +08:00
|
|
|
error(getErrorLocation(Loc) + "unsupported relocations combination " +
|
|
|
|
Twine(Type));
|
|
|
|
return std::make_pair(Type & 0xff, Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2017-10-12 06:49:24 +08:00
|
|
|
void MIPS<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
|
2017-06-17 01:32:43 +08:00
|
|
|
const endianness E = ELFT::TargetEndianness;
|
2017-10-12 11:14:06 +08:00
|
|
|
|
2018-01-18 23:59:05 +08:00
|
|
|
if (ELFT::Is64Bits || Config->MipsN32Abi)
|
|
|
|
std::tie(Type, Val) = calculateMipsRelChain(Loc, Type, Val);
|
|
|
|
|
2017-06-17 01:32:43 +08:00
|
|
|
// Thread pointer and DRP offsets from the start of TLS data area.
|
|
|
|
// https://www.linux-mips.org/wiki/NPTL
|
|
|
|
if (Type == R_MIPS_TLS_DTPREL_HI16 || Type == R_MIPS_TLS_DTPREL_LO16 ||
|
2017-09-12 21:08:24 +08:00
|
|
|
Type == R_MIPS_TLS_DTPREL32 || Type == R_MIPS_TLS_DTPREL64 ||
|
|
|
|
Type == R_MICROMIPS_TLS_DTPREL_HI16 ||
|
2017-10-12 11:14:06 +08:00
|
|
|
Type == R_MICROMIPS_TLS_DTPREL_LO16) {
|
2017-06-17 01:32:43 +08:00
|
|
|
Val -= 0x8000;
|
2017-10-12 11:14:06 +08:00
|
|
|
} else if (Type == R_MIPS_TLS_TPREL_HI16 || Type == R_MIPS_TLS_TPREL_LO16 ||
|
|
|
|
Type == R_MIPS_TLS_TPREL32 || Type == R_MIPS_TLS_TPREL64 ||
|
|
|
|
Type == R_MICROMIPS_TLS_TPREL_HI16 ||
|
|
|
|
Type == R_MICROMIPS_TLS_TPREL_LO16) {
|
2017-06-17 01:32:43 +08:00
|
|
|
Val -= 0x7000;
|
2017-10-12 11:14:06 +08:00
|
|
|
}
|
|
|
|
|
2017-06-17 01:32:43 +08:00
|
|
|
switch (Type) {
|
|
|
|
case R_MIPS_32:
|
|
|
|
case R_MIPS_GPREL32:
|
|
|
|
case R_MIPS_TLS_DTPREL32:
|
|
|
|
case R_MIPS_TLS_TPREL32:
|
|
|
|
write32<E>(Loc, Val);
|
|
|
|
break;
|
|
|
|
case R_MIPS_64:
|
|
|
|
case R_MIPS_TLS_DTPREL64:
|
|
|
|
case R_MIPS_TLS_TPREL64:
|
|
|
|
write64<E>(Loc, Val);
|
|
|
|
break;
|
|
|
|
case R_MIPS_26:
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 26, 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
|
|
|
case R_MIPS_GOT16:
|
|
|
|
// The R_MIPS_GOT16 relocation's value in "relocatable" linking mode
|
|
|
|
// is updated addend (not a GOT index). In that case write high 16 bits
|
|
|
|
// to store a correct addend value.
|
2017-09-05 00:16:41 +08:00
|
|
|
if (Config->Relocatable) {
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val + 0x8000, 16, 16);
|
2017-09-05 00:16:41 +08:00
|
|
|
} else {
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 16, Type);
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 16, 0);
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
break;
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_GOT16:
|
|
|
|
if (Config->Relocatable) {
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
|
2017-09-12 21:08:24 +08:00
|
|
|
} else {
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 16, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 16, 0);
|
2017-09-12 21:08:24 +08:00
|
|
|
}
|
|
|
|
break;
|
2017-10-07 00:15:59 +08:00
|
|
|
case R_MIPS_CALL16:
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_GOT_DISP:
|
|
|
|
case R_MIPS_GOT_PAGE:
|
|
|
|
case R_MIPS_GPREL16:
|
|
|
|
case R_MIPS_TLS_GD:
|
2017-10-07 00:15:59 +08:00
|
|
|
case R_MIPS_TLS_GOTTPREL:
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_TLS_LDM:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 16, Type);
|
2017-06-17 01:32:43 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case R_MIPS_CALL_LO16:
|
|
|
|
case R_MIPS_GOT_LO16:
|
|
|
|
case R_MIPS_GOT_OFST:
|
|
|
|
case R_MIPS_LO16:
|
|
|
|
case R_MIPS_PCLO16:
|
|
|
|
case R_MIPS_TLS_DTPREL_LO16:
|
|
|
|
case R_MIPS_TLS_TPREL_LO16:
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 16, 0);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_GOT_DISP:
|
|
|
|
case R_MICROMIPS_GOT_PAGE:
|
|
|
|
case R_MICROMIPS_GPREL16:
|
|
|
|
case R_MICROMIPS_TLS_GD:
|
|
|
|
case R_MICROMIPS_TLS_LDM:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 16, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 16, 0);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_CALL16:
|
|
|
|
case R_MICROMIPS_CALL_LO16:
|
|
|
|
case R_MICROMIPS_GOT_OFST:
|
|
|
|
case R_MICROMIPS_LO16:
|
|
|
|
case R_MICROMIPS_TLS_DTPREL_LO16:
|
|
|
|
case R_MICROMIPS_TLS_GOTTPREL:
|
|
|
|
case R_MICROMIPS_TLS_TPREL_LO16:
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 16, 0);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_GPREL7_S2:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 7, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 7, 2);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_CALL_HI16:
|
|
|
|
case R_MIPS_GOT_HI16:
|
|
|
|
case R_MIPS_HI16:
|
|
|
|
case R_MIPS_PCHI16:
|
|
|
|
case R_MIPS_TLS_DTPREL_HI16:
|
|
|
|
case R_MIPS_TLS_TPREL_HI16:
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val + 0x8000, 16, 16);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_CALL_HI16:
|
|
|
|
case R_MICROMIPS_GOT_HI16:
|
|
|
|
case R_MICROMIPS_HI16:
|
|
|
|
case R_MICROMIPS_TLS_DTPREL_HI16:
|
|
|
|
case R_MICROMIPS_TLS_TPREL_HI16:
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_HIGHER:
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val + 0x80008000, 16, 32);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
|
|
|
case R_MIPS_HIGHEST:
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val + 0x800080008000, 16, 48);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_HIGHER:
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val + 0x80008000, 16, 32);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_HIGHEST:
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val + 0x800080008000, 16, 48);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
2017-06-17 01:32:43 +08:00
|
|
|
case R_MIPS_JALR:
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_JALR:
|
2017-06-17 01:32:43 +08:00
|
|
|
// Ignore this optimization relocation for now
|
|
|
|
break;
|
|
|
|
case R_MIPS_PC16:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkAlignment(Loc, Val, 4, Type);
|
|
|
|
checkInt(Loc, Val, 18, Type);
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 16, 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
|
|
|
case R_MIPS_PC19_S2:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkAlignment(Loc, Val, 4, Type);
|
|
|
|
checkInt(Loc, Val, 21, Type);
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 19, 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
|
|
|
case R_MIPS_PC21_S2:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkAlignment(Loc, Val, 4, Type);
|
|
|
|
checkInt(Loc, Val, 23, Type);
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 21, 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
|
|
|
case R_MIPS_PC26_S2:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkAlignment(Loc, Val, 4, Type);
|
|
|
|
checkInt(Loc, Val, 28, Type);
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 26, 2);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
|
|
|
case R_MIPS_PC32:
|
2018-01-18 23:59:10 +08:00
|
|
|
writeValue<E>(Loc, Val, 32, 0);
|
2017-06-17 01:32:43 +08:00
|
|
|
break;
|
2017-09-12 21:08:24 +08:00
|
|
|
case R_MICROMIPS_26_S1:
|
|
|
|
case R_MICROMIPS_PC26_S1:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 27, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 26, 1);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_PC7_S1:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 8, Type);
|
2017-09-12 21:08:24 +08:00
|
|
|
writeMicroRelocation16<E>(Loc, Val, 7, 1);
|
|
|
|
break;
|
|
|
|
case R_MICROMIPS_PC10_S1:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 11, Type);
|
2017-09-12 21:08:24 +08:00
|
|
|
writeMicroRelocation16<E>(Loc, Val, 10, 1);
|
|
|
|
break;
|
|
|
|
case R_MICROMIPS_PC16_S1:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 17, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 16, 1);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_PC18_S3:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 21, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 18, 3);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_PC19_S2:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 21, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 19, 2);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_PC21_S1:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 22, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 21, 1);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
|
|
|
case R_MICROMIPS_PC23_S2:
|
2018-03-30 06:40:52 +08:00
|
|
|
checkInt(Loc, Val, 25, Type);
|
2018-01-29 22:00:51 +08:00
|
|
|
writeShuffleValue<E>(Loc, Val, 23, 2);
|
2017-09-12 21:08:24 +08:00
|
|
|
break;
|
2017-06-17 01:32:43 +08:00
|
|
|
default:
|
|
|
|
error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 06:49:24 +08:00
|
|
|
template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType Type) const {
|
2017-09-12 21:08:24 +08:00
|
|
|
return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST ||
|
|
|
|
Type == R_MICROMIPS_LO16 || Type == R_MICROMIPS_GOT_OFST;
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
2017-11-07 08:04:22 +08:00
|
|
|
// Return true if the symbol is a PIC function.
|
|
|
|
template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {
|
2018-05-05 04:48:53 +08:00
|
|
|
if (!Sym->isFunc())
|
2017-11-07 08:04:22 +08:00
|
|
|
return false;
|
|
|
|
|
2018-05-05 04:48:53 +08:00
|
|
|
if (Sym->StOther & STO_MIPS_PIC)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!Sym->Section)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ObjFile<ELFT> *File =
|
|
|
|
cast<InputSectionBase>(Sym->Section)->template getFile<ELFT>();
|
2018-05-04 01:33:10 +08:00
|
|
|
if (!File)
|
|
|
|
return false;
|
|
|
|
|
2018-05-05 04:48:53 +08:00
|
|
|
return File->getObj().getHeader()->e_flags & EF_MIPS_PIC;
|
2017-11-07 08:04:22 +08:00
|
|
|
}
|
|
|
|
|
2017-06-17 04:15:03 +08:00
|
|
|
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {
|
|
|
|
static MIPS<ELFT> Target;
|
|
|
|
return &Target;
|
2017-06-17 01:32:43 +08:00
|
|
|
}
|
|
|
|
|
2017-06-17 04:15:03 +08:00
|
|
|
template TargetInfo *elf::getMipsTargetInfo<ELF32LE>();
|
|
|
|
template TargetInfo *elf::getMipsTargetInfo<ELF32BE>();
|
|
|
|
template TargetInfo *elf::getMipsTargetInfo<ELF64LE>();
|
|
|
|
template TargetInfo *elf::getMipsTargetInfo<ELF64BE>();
|
2017-11-07 08:04:22 +08:00
|
|
|
|
|
|
|
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 *);
|