diff options
Diffstat (limited to 'contrib/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp')
-rw-r--r-- | contrib/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/contrib/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/contrib/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 3c67743947cb..3dc753772e5f 100644 --- a/contrib/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/contrib/llvm/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, @@ -331,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); @@ -338,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: @@ -384,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!"); @@ -436,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 @@ -455,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 && @@ -490,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"); @@ -658,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); } |