LLVM 20.0.0git
VEELFObjectWriter.cpp
Go to the documentation of this file.
1//===-- VEELFObjectWriter.cpp - VE 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
9#include "VEFixupKinds.h"
10#include "VEMCExpr.h"
11#include "VEMCTargetDesc.h"
12#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCExpr.h"
16#include "llvm/MC/MCValue.h"
18
19using namespace llvm;
20
21namespace {
22class VEELFObjectWriter : public MCELFObjectTargetWriter {
23public:
24 VEELFObjectWriter(uint8_t OSABI)
25 : MCELFObjectTargetWriter(/* Is64Bit */ true, OSABI, ELF::EM_VE,
26 /* HasRelocationAddend */ true) {}
27
28 ~VEELFObjectWriter() override = default;
29
30protected:
31 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
32 const MCFixup &Fixup, bool IsPCRel) const override;
33
34 bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
35 unsigned Type) const override;
36};
37} // namespace
38
39unsigned VEELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
40 const MCFixup &Fixup,
41 bool IsPCRel) const {
42 if (const VEMCExpr *SExpr = dyn_cast<VEMCExpr>(Fixup.getValue())) {
43 if (SExpr->getKind() == VEMCExpr::VK_VE_PC_LO32)
44 return ELF::R_VE_PC_LO32;
45 }
46
47 if (IsPCRel) {
48 switch (Fixup.getTargetKind()) {
49 default:
50 Ctx.reportError(Fixup.getLoc(), "Unsupported pc-relative fixup kind");
51 return ELF::R_VE_NONE;
52 case FK_Data_1:
53 case FK_PCRel_1:
54 Ctx.reportError(Fixup.getLoc(),
55 "1-byte pc-relative data relocation is not supported");
56 return ELF::R_VE_NONE;
57 case FK_Data_2:
58 case FK_PCRel_2:
59 Ctx.reportError(Fixup.getLoc(),
60 "2-byte pc-relative data relocation is not supported");
61 return ELF::R_VE_NONE;
62 case FK_Data_4:
63 case FK_PCRel_4:
64 return ELF::R_VE_SREL32;
65 case FK_Data_8:
66 case FK_PCRel_8:
67 Ctx.reportError(Fixup.getLoc(),
68 "8-byte pc-relative data relocation is not supported");
69 return ELF::R_VE_NONE;
72 return ELF::R_VE_SREL32;
74 return ELF::R_VE_PC_HI32;
76 return ELF::R_VE_PC_LO32;
77 }
78 }
79
80 switch (Fixup.getTargetKind()) {
81 default:
82 Ctx.reportError(Fixup.getLoc(), "Unknown ELF relocation type");
83 return ELF::R_VE_NONE;
84 case FK_Data_1:
85 Ctx.reportError(Fixup.getLoc(), "1-byte data relocation is not supported");
86 return ELF::R_VE_NONE;
87 case FK_Data_2:
88 Ctx.reportError(Fixup.getLoc(), "2-byte data relocation is not supported");
89 return ELF::R_VE_NONE;
90 case FK_Data_4:
91 return ELF::R_VE_REFLONG;
92 case FK_Data_8:
93 return ELF::R_VE_REFQUAD;
95 return ELF::R_VE_REFLONG;
97 Ctx.reportError(Fixup.getLoc(),
98 "A non pc-relative srel32 relocation is not supported");
99 return ELF::R_VE_NONE;
101 return ELF::R_VE_HI32;
103 return ELF::R_VE_LO32;
105 Ctx.reportError(Fixup.getLoc(),
106 "A non pc-relative pc_hi32 relocation is not supported");
107 return ELF::R_VE_NONE;
109 Ctx.reportError(Fixup.getLoc(),
110 "A non pc-relative pc_lo32 relocation is not supported");
111 return ELF::R_VE_NONE;
113 return ELF::R_VE_GOT_HI32;
115 return ELF::R_VE_GOT_LO32;
117 return ELF::R_VE_GOTOFF_HI32;
119 return ELF::R_VE_GOTOFF_LO32;
121 return ELF::R_VE_PLT_HI32;
123 return ELF::R_VE_PLT_LO32;
125 return ELF::R_VE_TLS_GD_HI32;
127 return ELF::R_VE_TLS_GD_LO32;
129 return ELF::R_VE_TPOFF_HI32;
131 return ELF::R_VE_TPOFF_LO32;
132 }
133
134 return ELF::R_VE_NONE;
135}
136
137bool VEELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
138 const MCSymbol &,
139 unsigned Type) const {
140 switch (Type) {
141 default:
142 return false;
143
144 // All relocations that use a GOT need a symbol, not an offset, as
145 // the offset of the symbol within the section is irrelevant to
146 // where the GOT entry is. Don't need to list all the TLS entries,
147 // as they're all marked as requiring a symbol anyways.
148 case ELF::R_VE_GOT_HI32:
149 case ELF::R_VE_GOT_LO32:
150 case ELF::R_VE_GOTOFF_HI32:
151 case ELF::R_VE_GOTOFF_LO32:
152 case ELF::R_VE_TLS_GD_HI32:
153 case ELF::R_VE_TLS_GD_LO32:
154 return true;
155 }
156}
157
158std::unique_ptr<MCObjectTargetWriter>
160 return std::make_unique<VEELFObjectWriter>(OSABI);
161}
basic Basic Alias true
Symbol * Sym
Definition: ELF_riscv.cpp:479
PowerPC TLS Dynamic Call Fixup
Context object for machine code objects.
Definition: MCContext.h:83
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1068
virtual bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym, unsigned Type) const
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:71
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
This represents an "assembler immediate".
Definition: MCValue.h:36
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
@ EM_VE
Definition: ELF.h:321
@ fixup_ve_tpoff_hi32
Definition: VEFixupKinds.h:54
@ fixup_ve_srel32
fixup_ve_srel32 - 32-bit fixup corresponding to foo for relative branch
Definition: VEFixupKinds.h:21
@ fixup_ve_plt_lo32
Definition: VEFixupKinds.h:49
@ fixup_ve_got_hi32
fixup_ve_got_hi32 - 32-bit fixup corresponding to foo@got_hi
Definition: VEFixupKinds.h:36
@ fixup_ve_gotoff_hi32
fixup_ve_gotoff_hi32 - 32-bit fixup corresponding to foo@gotoff_hi
Definition: VEFixupKinds.h:42
@ fixup_ve_got_lo32
fixup_ve_got_lo32 - 32-bit fixup corresponding to foo@got_lo
Definition: VEFixupKinds.h:39
@ fixup_ve_pc_hi32
fixup_ve_pc_hi32 - 32-bit fixup corresponding to foo@pc_hi
Definition: VEFixupKinds.h:30
@ fixup_ve_lo32
fixup_ve_lo32 - 32-bit fixup corresponding to foo@lo
Definition: VEFixupKinds.h:27
@ fixup_ve_gotoff_lo32
fixup_ve_gotoff_lo32 - 32-bit fixup corresponding to foo@gotoff_lo
Definition: VEFixupKinds.h:45
@ fixup_ve_hi32
fixup_ve_hi32 - 32-bit fixup corresponding to foo@hi
Definition: VEFixupKinds.h:24
@ fixup_ve_pc_lo32
fixup_ve_pc_lo32 - 32-bit fixup corresponding to foo@pc_lo
Definition: VEFixupKinds.h:33
@ fixup_ve_tpoff_lo32
Definition: VEFixupKinds.h:55
@ fixup_ve_plt_hi32
fixup_ve_plt_hi32/lo32
Definition: VEFixupKinds.h:48
@ fixup_ve_reflong
fixup_ve_reflong - 32-bit fixup corresponding to foo
Definition: VEFixupKinds.h:18
@ fixup_ve_tls_gd_lo32
Definition: VEFixupKinds.h:53
@ fixup_ve_tls_gd_hi32
fixups for Thread Local Storage
Definition: VEFixupKinds.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ FK_PCRel_4
A four-byte pc relative fixup.
Definition: MCFixup.h:30
@ FK_PCRel_2
A two-byte pc relative fixup.
Definition: MCFixup.h:29
@ 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_PCRel_8
A eight-byte pc relative fixup.
Definition: MCFixup.h:31
@ FK_PCRel_1
A one-byte pc relative fixup.
Definition: MCFixup.h:28
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24
std::unique_ptr< MCObjectTargetWriter > createVEELFObjectWriter(uint8_t OSABI)