| 1 | //===- MipsWinCOFFObjectWriter.cpp------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===---------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "MCTargetDesc/MipsFixupKinds.h" |
| 10 | #include "MCTargetDesc/MipsMCTargetDesc.h" |
| 11 | #include "llvm/BinaryFormat/COFF.h" |
| 12 | #include "llvm/MC/MCContext.h" |
| 13 | #include "llvm/MC/MCWinCOFFObjectWriter.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | class MipsWinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter { |
| 20 | public: |
| 21 | MipsWinCOFFObjectWriter(); |
| 22 | |
| 23 | unsigned getRelocType(MCContext &Ctx, const MCValue &Target, |
| 24 | const MCFixup &Fixup, bool IsCrossSection, |
| 25 | const MCAsmBackend &MAB) const override; |
| 26 | }; |
| 27 | |
| 28 | } // end anonymous namespace |
| 29 | |
| 30 | MipsWinCOFFObjectWriter::MipsWinCOFFObjectWriter() |
| 31 | : MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_R4000) {} |
| 32 | |
| 33 | unsigned MipsWinCOFFObjectWriter::getRelocType(MCContext &Ctx, |
| 34 | const MCValue &Target, |
| 35 | const MCFixup &Fixup, |
| 36 | bool IsCrossSection, |
| 37 | const MCAsmBackend &MAB) const { |
| 38 | unsigned FixupKind = Fixup.getKind(); |
| 39 | |
| 40 | switch (FixupKind) { |
| 41 | case FK_Data_4: |
| 42 | return COFF::IMAGE_REL_MIPS_REFWORD; |
| 43 | case FK_SecRel_2: |
| 44 | return COFF::IMAGE_REL_MIPS_SECTION; |
| 45 | case FK_SecRel_4: |
| 46 | return COFF::IMAGE_REL_MIPS_SECREL; |
| 47 | case Mips::fixup_Mips_26: |
| 48 | return COFF::IMAGE_REL_MIPS_JMPADDR; |
| 49 | case Mips::fixup_Mips_HI16: |
| 50 | return COFF::IMAGE_REL_MIPS_REFHI; |
| 51 | case Mips::fixup_Mips_LO16: |
| 52 | return COFF::IMAGE_REL_MIPS_REFLO; |
| 53 | default: |
| 54 | Ctx.reportError(L: Fixup.getLoc(), Msg: "unsupported relocation type" ); |
| 55 | return COFF::IMAGE_REL_MIPS_REFWORD; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | std::unique_ptr<MCObjectTargetWriter> llvm::createMipsWinCOFFObjectWriter() { |
| 60 | return std::make_unique<MipsWinCOFFObjectWriter>(); |
| 61 | } |
| 62 | |