LLVM 18.0.0git
LoongArchELFObjectWriter.cpp
Go to the documentation of this file.
1//===-- LoongArchELFObjectWriter.cpp - LoongArch ELF Writer ---*- 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
12#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCFixup.h"
17
18using namespace llvm;
19
20namespace {
21class LoongArchELFObjectWriter : public MCELFObjectTargetWriter {
22public:
23 LoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit);
24
25 ~LoongArchELFObjectWriter() override;
26
27protected:
28 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
29 const MCFixup &Fixup, bool IsPCRel) const override;
30};
31} // end namespace
32
33LoongArchELFObjectWriter::LoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit)
34 : MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_LOONGARCH,
35 /*HasRelocationAddend*/ true) {}
36
37LoongArchELFObjectWriter::~LoongArchELFObjectWriter() {}
38
39unsigned LoongArchELFObjectWriter::getRelocType(MCContext &Ctx,
40 const MCValue &Target,
41 const MCFixup &Fixup,
42 bool IsPCRel) const {
43 // Determine the type of the relocation
44 unsigned Kind = Fixup.getTargetKind();
45
48
49 switch (Kind) {
50 default:
51 Ctx.reportError(Fixup.getLoc(), "Unsupported relocation type");
52 return ELF::R_LARCH_NONE;
53 case FK_Data_1:
54 Ctx.reportError(Fixup.getLoc(), "1-byte data relocations not supported");
55 return ELF::R_LARCH_NONE;
56 case FK_Data_2:
57 Ctx.reportError(Fixup.getLoc(), "2-byte data relocations not supported");
58 return ELF::R_LARCH_NONE;
59 case FK_Data_4:
60 return IsPCRel ? ELF::R_LARCH_32_PCREL : ELF::R_LARCH_32;
61 case FK_Data_8:
62 return IsPCRel ? ELF::R_LARCH_64_PCREL : ELF::R_LARCH_64;
64 return ELF::R_LARCH_B16;
66 return ELF::R_LARCH_B21;
68 return ELF::R_LARCH_B26;
70 return ELF::R_LARCH_ABS_HI20;
72 return ELF::R_LARCH_ABS_LO12;
74 return ELF::R_LARCH_ABS64_LO20;
76 return ELF::R_LARCH_ABS64_HI12;
78 return ELF::R_LARCH_TLS_LE_HI20;
80 return ELF::R_LARCH_TLS_LE_LO12;
82 return ELF::R_LARCH_TLS_LE64_LO20;
84 return ELF::R_LARCH_TLS_LE64_HI12;
85 // TODO: Handle more fixup-kinds.
86 }
87}
88
89std::unique_ptr<MCObjectTargetWriter>
90llvm::createLoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit) {
91 return std::make_unique<LoongArchELFObjectWriter>(OSABI, Is64Bit);
92}
basic Basic Alias true
PowerPC TLS Dynamic Call Fixup
Context object for machine code objects.
Definition: MCContext.h:76
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1059
virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const =0
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:70
This represents an "assembler immediate".
Definition: MCValue.h:36
Target - Wrapper for Target specific information.
@ EM_LOONGARCH
Definition: ELF.h:322
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::unique_ptr< MCObjectTargetWriter > createLoongArchELFObjectWriter(uint8_t OSABI, bool Is64Bit)
@ FirstLiteralRelocationKind
The range [FirstLiteralRelocationKind, MaxTargetFixupKind) is used for relocations coming from ....
Definition: MCFixup.h:49
@ FK_Data_8
A eight-byte fixup.
Definition: MCFixup.h:26
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:23
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24