diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Notes
Diffstat (limited to 'lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp')
-rw-r--r-- | lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 6d2f098a6b32..3dc753772e5f 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -56,8 +56,7 @@ raw_ostream &operator<<(raw_ostream &OS, const MipsRelocationEntry &RHS) { class MipsELFObjectWriter : public MCELFObjectTargetWriter { public: - MipsELFObjectWriter(uint8_t OSABI, bool HasRelocationAddend, bool Is64, - bool IsLittleEndian); + MipsELFObjectWriter(uint8_t OSABI, bool HasRelocationAddend, bool Is64); ~MipsELFObjectWriter() override = default; @@ -116,15 +115,15 @@ static InputIt find_best(InputIt First, InputIt Last, UnaryPredicate Predicate, for (InputIt I = First; I != Last; ++I) { unsigned Matched = Predicate(*I); if (Matched != FindBest_NoMatch) { - DEBUG(dbgs() << std::distance(First, I) << " is a match ("; - I->print(dbgs()); dbgs() << ")\n"); + LLVM_DEBUG(dbgs() << std::distance(First, I) << " is a match ("; + I->print(dbgs()); dbgs() << ")\n"); if (Best == Last || BetterThan(*I, *Best)) { - DEBUG(dbgs() << ".. and it beats the last one\n"); + LLVM_DEBUG(dbgs() << ".. and it beats the last one\n"); Best = I; } } if (Matched == FindBest_PerfectMatch) { - DEBUG(dbgs() << ".. and it is unbeatable\n"); + LLVM_DEBUG(dbgs() << ".. and it is unbeatable\n"); break; } } @@ -148,7 +147,8 @@ static unsigned getMatchingLoType(const ELFRelocationEntry &Reloc) { if (Type == ELF::R_MIPS16_HI16) return ELF::R_MIPS16_LO16; - if (Reloc.OriginalSymbol->getBinding() != ELF::STB_LOCAL) + if (Reloc.OriginalSymbol && + Reloc.OriginalSymbol->getBinding() != ELF::STB_LOCAL) return ELF::R_MIPS_NONE; if (Type == ELF::R_MIPS_GOT16) @@ -211,8 +211,7 @@ static void dumpRelocs(const char *Prefix, const Container &Relocs) { #endif MipsELFObjectWriter::MipsELFObjectWriter(uint8_t OSABI, - bool HasRelocationAddend, bool Is64, - bool IsLittleEndian) + bool HasRelocationAddend, bool Is64) : MCELFObjectTargetWriter(Is64, OSABI, ELF::EM_MIPS, HasRelocationAddend) {} unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx, @@ -225,6 +224,8 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx, switch (Kind) { case Mips::fixup_Mips_NONE: return ELF::R_MIPS_NONE; + case FK_Data_1: + report_fatal_error("MIPS does not support one byte relocations"); case Mips::fixup_Mips_16: case FK_Data_2: return IsPCRel ? ELF::R_MIPS_PC16 : ELF::R_MIPS_16; @@ -329,6 +330,13 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx, Type = setRType3((unsigned)ELF::R_MIPS_HI16, Type); return Type; } + case Mips::fixup_MICROMIPS_GPOFF_HI: { + unsigned Type = (unsigned)ELF::R_MIPS_NONE; + Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type); + Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type); + Type = setRType3((unsigned)ELF::R_MICROMIPS_HI16, Type); + return Type; + } case Mips::fixup_Mips_GPOFF_LO: { unsigned Type = (unsigned)ELF::R_MIPS_NONE; Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type); @@ -336,6 +344,13 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx, Type = setRType3((unsigned)ELF::R_MIPS_LO16, Type); return Type; } + case Mips::fixup_MICROMIPS_GPOFF_LO: { + unsigned Type = (unsigned)ELF::R_MIPS_NONE; + Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type); + Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type); + Type = setRType3((unsigned)ELF::R_MICROMIPS_LO16, Type); + return Type; + } case Mips::fixup_Mips_HIGHER: return ELF::R_MIPS_HIGHER; case Mips::fixup_Mips_HIGHEST: @@ -382,6 +397,10 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx, return ELF::R_MICROMIPS_TLS_TPREL_LO16; case Mips::fixup_MICROMIPS_SUB: return ELF::R_MICROMIPS_SUB; + case Mips::fixup_MICROMIPS_HIGHER: + return ELF::R_MICROMIPS_HIGHER; + case Mips::fixup_MICROMIPS_HIGHEST: + return ELF::R_MICROMIPS_HIGHEST; } llvm_unreachable("invalid fixup kind!"); @@ -434,15 +453,15 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm, return; // Sort relocations by the address they are applied to. - std::sort(Relocs.begin(), Relocs.end(), - [](const ELFRelocationEntry &A, const ELFRelocationEntry &B) { - return A.Offset < B.Offset; - }); + llvm::sort(Relocs.begin(), Relocs.end(), + [](const ELFRelocationEntry &A, const ELFRelocationEntry &B) { + return A.Offset < B.Offset; + }); std::list<MipsRelocationEntry> Sorted; std::list<ELFRelocationEntry> Remainder; - DEBUG(dumpRelocs("R: ", Relocs)); + LLVM_DEBUG(dumpRelocs("R: ", Relocs)); // Separate the movable relocations (AHL relocations using the high bits) from // the immobile relocations (everything else). This does not preserve high/low @@ -453,7 +472,7 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm, }); for (auto &R : Remainder) { - DEBUG(dbgs() << "Matching: " << R << "\n"); + LLVM_DEBUG(dbgs() << "Matching: " << R << "\n"); unsigned MatchingType = getMatchingLoType(R); assert(MatchingType != ELF::R_MIPS_NONE && @@ -488,7 +507,7 @@ void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm, Sorted.insert(InsertionPoint, R)->Matched = true; } - DEBUG(dumpRelocs("S: ", Sorted)); + LLVM_DEBUG(dumpRelocs("S: ", Sorted)); assert(Relocs.size() == Sorted.size() && "Some relocs were not consumed"); @@ -656,13 +675,11 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym, } } -std::unique_ptr<MCObjectWriter> -llvm::createMipsELFObjectWriter(raw_pwrite_stream &OS, const Triple &TT, - bool IsN32) { +std::unique_ptr<MCObjectTargetWriter> +llvm::createMipsELFObjectWriter(const Triple &TT, bool IsN32) { uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS()); bool IsN64 = TT.isArch64Bit() && !IsN32; bool HasRelocationAddend = TT.isArch64Bit(); - auto MOTW = llvm::make_unique<MipsELFObjectWriter>( - OSABI, HasRelocationAddend, IsN64, TT.isLittleEndian()); - return createELFObjectWriter(std::move(MOTW), OS, TT.isLittleEndian()); + return llvm::make_unique<MipsELFObjectWriter>(OSABI, HasRelocationAddend, + IsN64); } |