LLVM 22.0.0git
LanaiELFObjectWriter.cpp
Go to the documentation of this file.
1//===-- LanaiELFObjectWriter.cpp - Lanai ELF Writer -----------------------===//
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
15
16using namespace llvm;
17
18namespace {
19
20class LanaiELFObjectWriter : public MCELFObjectTargetWriter {
21public:
22 explicit LanaiELFObjectWriter(uint8_t OSABI);
23
24 ~LanaiELFObjectWriter() override = default;
25
26protected:
27 unsigned getRelocType(const MCFixup &, const MCValue &,
28 bool IsPCRel) const override;
29 bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
30};
31
32} // end anonymous namespace
33
34LanaiELFObjectWriter::LanaiELFObjectWriter(uint8_t OSABI)
35 : MCELFObjectTargetWriter(/*Is64Bit_=*/false, OSABI, ELF::EM_LANAI,
36 /*HasRelocationAddend_=*/true) {}
37
38unsigned LanaiELFObjectWriter::getRelocType(const MCFixup &Fixup,
39 const MCValue &, bool) const {
40 unsigned Type;
41 unsigned Kind = static_cast<unsigned>(Fixup.getKind());
42 switch (Kind) {
44 Type = ELF::R_LANAI_21;
45 break;
47 Type = ELF::R_LANAI_21_F;
48 break;
50 Type = ELF::R_LANAI_25;
51 break;
53 case FK_Data_4:
54 Type = ELF::R_LANAI_32;
55 break;
57 Type = ELF::R_LANAI_HI16;
58 break;
60 Type = ELF::R_LANAI_LO16;
61 break;
63 Type = ELF::R_LANAI_NONE;
64 break;
65
66 default:
67 llvm_unreachable("Invalid fixup kind!");
68 }
69 return Type;
70}
71
72bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
73 unsigned Type) const {
74 switch (Type) {
75 case ELF::R_LANAI_21:
76 case ELF::R_LANAI_21_F:
77 case ELF::R_LANAI_25:
78 case ELF::R_LANAI_32:
79 case ELF::R_LANAI_HI16:
80 return true;
81 default:
82 return false;
83 }
84}
85
86std::unique_ptr<MCObjectTargetWriter>
88 return std::make_unique<LanaiELFObjectWriter>(OSABI);
89}
PowerPC TLS Dynamic Call Fixup
virtual unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target, bool IsPCRel) const =0
virtual bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:61
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ EM_LANAI
Definition: ELF.h:323
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:36
std::unique_ptr< MCObjectTargetWriter > createLanaiELFObjectWriter(uint8_t OSABI)