aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp')
-rw-r--r--llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp66
1 files changed, 38 insertions, 28 deletions
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index f2d4a6a5bf26..ad8f5f0a0974 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "MCTargetDesc/MipsFixupKinds.h"
+#include "MCTargetDesc/MipsMCAsmInfo.h"
#include "MCTargetDesc/MipsMCTargetDesc.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/BinaryFormat/ELF.h"
@@ -15,6 +16,7 @@
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSymbolELF.h"
+#include "llvm/MC/MCValue.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
@@ -47,12 +49,10 @@ public:
~MipsELFObjectWriter() override = default;
- unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
- const MCFixup &Fixup, bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
- void sortRelocs(const MCAssembler &Asm,
- std::vector<ELFRelocationEntry> &Relocs) override;
+ unsigned getRelocType(const MCFixup &, const MCValue &,
+ bool IsPCRel) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
+ void sortRelocs(std::vector<ELFRelocationEntry> &Relocs) override;
};
/// The possible results of the Predicate function used by find_best.
@@ -152,21 +152,32 @@ MipsELFObjectWriter::MipsELFObjectWriter(uint8_t OSABI,
bool HasRelocationAddend, bool Is64)
: MCELFObjectTargetWriter(Is64, OSABI, ELF::EM_MIPS, HasRelocationAddend) {}
-unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
+unsigned MipsELFObjectWriter::getRelocType(const MCFixup &Fixup,
const MCValue &Target,
- const MCFixup &Fixup,
bool IsPCRel) const {
// Determine the type of the relocation.
- unsigned Kind = Fixup.getTargetKind();
- if (Kind >= FirstLiteralRelocationKind)
- return Kind - FirstLiteralRelocationKind;
+ auto Kind = Fixup.getKind();
+ switch (Target.getSpecifier()) {
+ case Mips::S_DTPREL:
+ case Mips::S_DTPREL_HI:
+ case Mips::S_DTPREL_LO:
+ case Mips::S_TLSLDM:
+ case Mips::S_TLSGD:
+ case Mips::S_GOTTPREL:
+ case Mips::S_TPREL_HI:
+ case Mips::S_TPREL_LO:
+ if (auto *SA = Target.getAddSym())
+ cast<MCSymbolELF>(SA)->setType(ELF::STT_TLS);
+ break;
+ default:
+ break;
+ }
switch (Kind) {
case FK_NONE:
return ELF::R_MIPS_NONE;
case FK_Data_1:
- Ctx.reportError(Fixup.getLoc(),
- "MIPS does not support one byte relocations");
+ reportError(Fixup.getLoc(), "MIPS does not support one byte relocations");
return ELF::R_MIPS_NONE;
case Mips::fixup_Mips_16:
case FK_Data_2:
@@ -218,15 +229,15 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
}
switch (Kind) {
- case FK_DTPRel_4:
+ case Mips::fixup_Mips_DTPREL32:
return ELF::R_MIPS_TLS_DTPREL32;
- case FK_DTPRel_8:
+ case Mips::fixup_Mips_DTPREL64:
return ELF::R_MIPS_TLS_DTPREL64;
- case FK_TPRel_4:
+ case Mips::fixup_Mips_TPREL32:
return ELF::R_MIPS_TLS_TPREL32;
- case FK_TPRel_8:
+ case Mips::fixup_Mips_TPREL64:
return ELF::R_MIPS_TLS_TPREL64;
- case FK_GPRel_4:
+ case Mips::fixup_Mips_GPREL32:
return setRTypes(ELF::R_MIPS_GPREL32,
is64Bit() ? ELF::R_MIPS_64 : ELF::R_MIPS_NONE,
ELF::R_MIPS_NONE);
@@ -328,7 +339,8 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
return ELF::R_MICROMIPS_JALR;
}
- llvm_unreachable("invalid fixup kind!");
+ reportError(Fixup.getLoc(), "unsupported relocation type");
+ return ELF::R_MIPS_NONE;
}
/// Sort relocation table entries by offset except where another order is
@@ -366,8 +378,7 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
/// It should also be noted that this function is not affected by whether
/// the symbol was kept or rewritten into a section-relative equivalent. We
/// always match using the expressions from the source.
-void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
- std::vector<ELFRelocationEntry> &Relocs) {
+void MipsELFObjectWriter::sortRelocs(std::vector<ELFRelocationEntry> &Relocs) {
// We do not need to sort the relocation table for RELA relocations which
// N32/N64 uses as the relocation addend contains the value we require,
// rather than it being split across a pair of relocations.
@@ -429,15 +440,14 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
Relocs[CopyTo++] = R.R;
}
-bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
- const MCSymbol &Sym,
+bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
unsigned Type) const {
// If it's a compound relocation for N64 then we need the relocation if any
// sub-relocation needs it.
if (!isUInt<8>(Type))
- return needsRelocateWithSymbol(Val, Sym, Type & 0xff) ||
- needsRelocateWithSymbol(Val, Sym, (Type >> 8) & 0xff) ||
- needsRelocateWithSymbol(Val, Sym, (Type >> 16) & 0xff);
+ return needsRelocateWithSymbol(V, Type & 0xff) ||
+ needsRelocateWithSymbol(V, (Type >> 8) & 0xff) ||
+ needsRelocateWithSymbol(V, (Type >> 16) & 0xff);
switch (Type) {
default:
@@ -470,7 +480,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
// FIXME: It should be safe to return false for the STO_MIPS_MICROMIPS but
// we neglect to handle the adjustment to the LSB of the addend that
// it causes in applyFixup() and similar.
- if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
+ if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
return true;
return false;
@@ -481,7 +491,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
case ELF::R_MIPS_16:
case ELF::R_MIPS_32:
case ELF::R_MIPS_GPREL32:
- if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
+ if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
return true;
[[fallthrough]];
case ELF::R_MIPS_26: