Differential D132108 Diff 454155 llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
//===-- LoongArchELFObjectWriter.cpp - LoongArch ELF Writer ---*- C++ -*---===// | //===-- LoongArchELFObjectWriter.cpp - LoongArch ELF Writer ---*- C++ -*---===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "MCTargetDesc/LoongArchFixupKinds.h" | |||||
#include "MCTargetDesc/LoongArchMCTargetDesc.h" | #include "MCTargetDesc/LoongArchMCTargetDesc.h" | ||||
#include "llvm/BinaryFormat/ELF.h" | |||||
#include "llvm/MC/MCContext.h" | #include "llvm/MC/MCContext.h" | ||||
#include "llvm/MC/MCELFObjectWriter.h" | #include "llvm/MC/MCELFObjectWriter.h" | ||||
#include "llvm/MC/MCFixup.h" | #include "llvm/MC/MCFixup.h" | ||||
#include "llvm/MC/MCObjectWriter.h" | #include "llvm/MC/MCObjectWriter.h" | ||||
#include "llvm/Support/ErrorHandling.h" | #include "llvm/Support/ErrorHandling.h" | ||||
using namespace llvm; | using namespace llvm; | ||||
Show All 29 Lines | unsigned LoongArchELFObjectWriter::getRelocType(MCContext &Ctx, | ||||
bool IsPCRel) const { | bool IsPCRel) const { | ||||
// Determine the type of the relocation | // Determine the type of the relocation | ||||
unsigned Kind = Fixup.getTargetKind(); | unsigned Kind = Fixup.getTargetKind(); | ||||
if (Kind >= FirstLiteralRelocationKind) | if (Kind >= FirstLiteralRelocationKind) | ||||
return Kind - FirstLiteralRelocationKind; | return Kind - FirstLiteralRelocationKind; | ||||
switch (Kind) { | switch (Kind) { | ||||
// TODO: Implement this when we defined fixup kind. | |||||
default: | default: | ||||
Ctx.reportError(Fixup.getLoc(), "Unsupported relocation type"); | |||||
return ELF::R_LARCH_NONE; | return ELF::R_LARCH_NONE; | ||||
case FK_Data_1: | |||||
Ctx.reportError(Fixup.getLoc(), "1-byte data relocations not supported"); | |||||
return ELF::R_LARCH_NONE; | |||||
case FK_Data_2: | |||||
Ctx.reportError(Fixup.getLoc(), "2-byte data relocations not supported"); | |||||
return ELF::R_LARCH_NONE; | |||||
case FK_Data_4: | |||||
return ELF::R_LARCH_32; | |||||
case FK_Data_8: | |||||
return ELF::R_LARCH_64; | |||||
case LoongArch::fixup_loongarch_pcala_hi20: | |||||
return ELF::R_LARCH_PCALA_HI20; | |||||
case LoongArch::fixup_loongarch_pcala_lo12: | |||||
return ELF::R_LARCH_PCALA_LO12; | |||||
case LoongArch::fixup_loongarch_b26: | |||||
return ELF::R_LARCH_B26; | |||||
// TODO: Handle more fixup-kinds. | |||||
} | } | ||||
} | } | ||||
std::unique_ptr<MCObjectTargetWriter> | std::unique_ptr<MCObjectTargetWriter> | ||||
llvm::createLoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit) { | llvm::createLoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit) { | ||||
return std::make_unique<LoongArchELFObjectWriter>(OSABI, Is64Bit); | return std::make_unique<LoongArchELFObjectWriter>(OSABI, Is64Bit); | ||||
} | } |