LLVM 22.0.0git
HexagonELFObjectWriter.cpp
Go to the documentation of this file.
1//===-- HexagonELFObjectWriter.cpp - Hexagon Target Descriptions ----------===//
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/MCAssembler.h"
15#include "llvm/MC/MCValue.h"
16
17#define DEBUG_TYPE "hexagon-elf-writer"
18
19using namespace llvm;
20using namespace Hexagon;
21
22namespace {
23
24class HexagonELFObjectWriter : public MCELFObjectTargetWriter {
25private:
26 StringRef CPU;
27
28public:
29 HexagonELFObjectWriter(uint8_t OSABI, StringRef C);
30
31 unsigned getRelocType(const MCFixup &, const MCValue &,
32 bool IsPCRel) const override;
33};
34}
35
36HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C)
37 : MCELFObjectTargetWriter(/*Is64bit*/ false, OSABI, ELF::EM_HEXAGON,
38 /*HasRelocationAddend*/ true),
39 CPU(C) {}
40
41unsigned HexagonELFObjectWriter::getRelocType(const MCFixup &Fixup,
42 const MCValue &Target,
43 bool IsPCRel) const {
44 auto Variant = HexagonMCExpr::VariantKind(Target.getSpecifier());
45 switch (Variant) {
53 if (auto *SA = const_cast<MCSymbol *>(Target.getAddSym()))
54 static_cast<MCSymbolELF *>(SA)->setType(ELF::STT_TLS);
55 break;
56 default:
57 break;
58 }
59 switch (Fixup.getKind()) {
60 default:
61 report_fatal_error("Unrecognized relocation type");
62 break;
63 case FK_Data_4:
64 switch (Variant) {
66 return ELF::R_HEX_DTPREL_32;
68 return ELF::R_HEX_GOT_32;
70 return ELF::R_HEX_GOTREL_32;
72 return ELF::R_HEX_GD_GOT_32;
74 return ELF::R_HEX_IE_32;
76 return ELF::R_HEX_IE_GOT_32;
78 return ELF::R_HEX_LD_GOT_32;
80 return ELF::R_HEX_32_PCREL;
82 return ELF::R_HEX_TPREL_32;
84 return IsPCRel ? ELF::R_HEX_32_PCREL : ELF::R_HEX_32;
85 default:
86 report_fatal_error("Unrecognized variant type");
87 };
88 case FK_Data_2:
89 switch(Variant) {
91 return ELF::R_HEX_DTPREL_16;
93 return ELF::R_HEX_GOT_16;
95 return ELF::R_HEX_GD_GOT_16;
97 return ELF::R_HEX_IE_GOT_16;
99 return ELF::R_HEX_LD_GOT_16;
101 return ELF::R_HEX_TPREL_16;
103 return ELF::R_HEX_16;
104 default:
105 report_fatal_error("Unrecognized variant type");
106 };
107 case FK_Data_1:
108 return ELF::R_HEX_8;
110 return ELF::R_HEX_B22_PCREL;
112 return ELF::R_HEX_B15_PCREL;
114 return ELF::R_HEX_B7_PCREL;
116 return ELF::R_HEX_LO16;
118 return ELF::R_HEX_HI16;
119 case fixup_Hexagon_32:
120 return ELF::R_HEX_32;
121 case fixup_Hexagon_16:
122 return ELF::R_HEX_16;
123 case fixup_Hexagon_8:
124 return ELF::R_HEX_8;
126 return ELF::R_HEX_GPREL16_0;
128 return ELF::R_HEX_GPREL16_1;
130 return ELF::R_HEX_GPREL16_2;
132 return ELF::R_HEX_GPREL16_3;
134 return ELF::R_HEX_HL16;
136 return ELF::R_HEX_B13_PCREL;
138 return ELF::R_HEX_B9_PCREL;
140 return ELF::R_HEX_B32_PCREL_X;
142 return ELF::R_HEX_32_6_X;
144 return ELF::R_HEX_B22_PCREL_X;
146 return ELF::R_HEX_B15_PCREL_X;
148 return ELF::R_HEX_B13_PCREL_X;
150 return ELF::R_HEX_B9_PCREL_X;
152 return ELF::R_HEX_B7_PCREL_X;
154 return ELF::R_HEX_16_X;
156 return ELF::R_HEX_12_X;
158 return ELF::R_HEX_11_X;
160 return ELF::R_HEX_10_X;
162 return ELF::R_HEX_9_X;
164 return ELF::R_HEX_8_X;
166 return ELF::R_HEX_7_X;
168 return ELF::R_HEX_6_X;
170 return ELF::R_HEX_32_PCREL;
172 return ELF::R_HEX_COPY;
174 return ELF::R_HEX_GLOB_DAT;
176 return ELF::R_HEX_JMP_SLOT;
178 return ELF::R_HEX_RELATIVE;
180 return ELF::R_HEX_PLT_B22_PCREL;
182 return ELF::R_HEX_GOTREL_LO16;
184 return ELF::R_HEX_GOTREL_HI16;
186 return ELF::R_HEX_GOTREL_32;
188 return ELF::R_HEX_GOT_LO16;
190 return ELF::R_HEX_GOT_HI16;
192 return ELF::R_HEX_GOT_32;
194 return ELF::R_HEX_GOT_16;
196 return ELF::R_HEX_DTPMOD_32;
198 return ELF::R_HEX_DTPREL_LO16;
200 return ELF::R_HEX_DTPREL_HI16;
202 return ELF::R_HEX_DTPREL_32;
204 return ELF::R_HEX_DTPREL_16;
206 return ELF::R_HEX_GD_PLT_B22_PCREL;
208 return ELF::R_HEX_LD_PLT_B22_PCREL;
210 return ELF::R_HEX_GD_GOT_LO16;
212 return ELF::R_HEX_GD_GOT_HI16;
214 return ELF::R_HEX_GD_GOT_32;
216 return ELF::R_HEX_GD_GOT_16;
218 return ELF::R_HEX_LD_GOT_LO16;
220 return ELF::R_HEX_LD_GOT_HI16;
222 return ELF::R_HEX_LD_GOT_32;
224 return ELF::R_HEX_LD_GOT_16;
226 return ELF::R_HEX_IE_LO16;
228 return ELF::R_HEX_IE_HI16;
230 return ELF::R_HEX_IE_32;
232 return ELF::R_HEX_IE_GOT_LO16;
234 return ELF::R_HEX_IE_GOT_HI16;
236 return ELF::R_HEX_IE_GOT_32;
238 return ELF::R_HEX_IE_GOT_16;
240 return ELF::R_HEX_TPREL_LO16;
242 return ELF::R_HEX_TPREL_HI16;
244 return ELF::R_HEX_TPREL_32;
246 return ELF::R_HEX_TPREL_16;
248 return ELF::R_HEX_6_PCREL_X;
250 return ELF::R_HEX_GOTREL_32_6_X;
252 return ELF::R_HEX_GOTREL_16_X;
254 return ELF::R_HEX_GOTREL_11_X;
256 return ELF::R_HEX_GOT_32_6_X;
258 return ELF::R_HEX_GOT_16_X;
260 return ELF::R_HEX_GOT_11_X;
262 return ELF::R_HEX_DTPREL_32_6_X;
264 return ELF::R_HEX_DTPREL_16_X;
266 return ELF::R_HEX_DTPREL_11_X;
268 return ELF::R_HEX_GD_GOT_32_6_X;
270 return ELF::R_HEX_GD_GOT_16_X;
272 return ELF::R_HEX_GD_GOT_11_X;
274 return ELF::R_HEX_LD_GOT_32_6_X;
276 return ELF::R_HEX_LD_GOT_16_X;
278 return ELF::R_HEX_LD_GOT_11_X;
280 return ELF::R_HEX_IE_32_6_X;
282 return ELF::R_HEX_IE_16_X;
284 return ELF::R_HEX_IE_GOT_32_6_X;
286 return ELF::R_HEX_IE_GOT_16_X;
288 return ELF::R_HEX_IE_GOT_11_X;
290 return ELF::R_HEX_TPREL_32_6_X;
292 return ELF::R_HEX_TPREL_16_X;
294 return ELF::R_HEX_TPREL_11_X;
296 return ELF::R_HEX_23_REG;
298 return ELF::R_HEX_27_REG;
300 return ELF::R_HEX_GD_PLT_B22_PCREL_X;
302 return ELF::R_HEX_GD_PLT_B32_PCREL_X;
304 return ELF::R_HEX_LD_PLT_B22_PCREL_X;
306 return ELF::R_HEX_LD_PLT_B32_PCREL_X;
307 }
308}
309
310std::unique_ptr<MCObjectTargetWriter>
312 return std::make_unique<HexagonELFObjectWriter>(OSABI, CPU);
313}
PowerPC TLS Dynamic Call Fixup
virtual unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target, bool IsPCRel) const =0
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:61
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Target - Wrapper for Target specific information.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ EM_HEXAGON
Definition: ELF.h:262
@ STT_TLS
Definition: ELF.h:1414
std::variant< std::monostate, Loc::Single, Loc::Multi, Loc::MMI, Loc::EntryValue > Variant
Alias for the std::variant specialization base class of DbgVariable.
Definition: DwarfDebug.h:190
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:34
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:36
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:35
std::unique_ptr< MCObjectTargetWriter > createHexagonELFObjectWriter(uint8_t OSABI, StringRef CPU)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167