LLVM  16.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"
15 #include "llvm/MC/MCObjectWriter.h"
16 #include "llvm/MC/MCValue.h"
18 
19 using namespace llvm;
20 
21 namespace {
22 class VEELFObjectWriter : public MCELFObjectTargetWriter {
23 public:
24  VEELFObjectWriter(uint8_t OSABI)
25  : MCELFObjectTargetWriter(/* Is64Bit */ true, OSABI, ELF::EM_VE,
26  /* HasRelocationAddend */ true) {}
27 
28  ~VEELFObjectWriter() override = default;
29 
30 protected:
31  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
32  const MCFixup &Fixup, bool IsPCRel) const override;
33 
34  bool needsRelocateWithSymbol(const MCSymbol &Sym,
35  unsigned Type) const override;
36 };
37 } // namespace
38 
39 unsigned 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;
100  case VE::fixup_ve_hi32:
101  return ELF::R_VE_HI32;
102  case VE::fixup_ve_lo32:
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 
137 bool VEELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
138  unsigned Type) const {
139  switch (Type) {
140  default:
141  return false;
142 
143  // All relocations that use a GOT need a symbol, not an offset, as
144  // the offset of the symbol within the section is irrelevant to
145  // where the GOT entry is. Don't need to list all the TLS entries,
146  // as they're all marked as requiring a symbol anyways.
147  case ELF::R_VE_GOT_HI32:
148  case ELF::R_VE_GOT_LO32:
149  case ELF::R_VE_GOTOFF_HI32:
150  case ELF::R_VE_GOTOFF_LO32:
151  case ELF::R_VE_TLS_GD_HI32:
152  case ELF::R_VE_TLS_GD_LO32:
153  return true;
154  }
155 }
156 
157 std::unique_ptr<MCObjectTargetWriter>
159  return std::make_unique<VEELFObjectWriter>(OSABI);
160 }
llvm::VE::fixup_ve_reflong
@ fixup_ve_reflong
fixup_ve_reflong - 32-bit fixup corresponding to foo
Definition: VEFixupKinds.h:18
llvm::VE::fixup_ve_plt_hi32
@ fixup_ve_plt_hi32
fixup_ve_plt_hi32/lo32
Definition: VEFixupKinds.h:48
llvm::VE::fixup_ve_pc_lo32
@ fixup_ve_pc_lo32
fixup_ve_pc_lo32 - 32-bit fixup corresponding to foo@pc_lo
Definition: VEFixupKinds.h:33
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::FK_PCRel_8
@ FK_PCRel_8
A eight-byte pc relative fixup.
Definition: MCFixup.h:31
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
llvm::createVEELFObjectWriter
std::unique_ptr< MCObjectTargetWriter > createVEELFObjectWriter(uint8_t OSABI)
Definition: VEELFObjectWriter.cpp:158
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:149
llvm::VE::fixup_ve_pc_hi32
@ fixup_ve_pc_hi32
fixup_ve_pc_hi32 - 32-bit fixup corresponding to foo@pc_hi
Definition: VEFixupKinds.h:30
ErrorHandling.h
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1793
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::VE::fixup_ve_tls_gd_lo32
@ fixup_ve_tls_gd_lo32
Definition: VEFixupKinds.h:53
VEFixupKinds.h
llvm::FK_PCRel_1
@ FK_PCRel_1
A one-byte pc relative fixup.
Definition: MCFixup.h:28
llvm::FK_Data_4
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
MCContext.h
llvm::VEMCExpr
Definition: VEMCExpr.h:23
llvm::VE::fixup_ve_lo32
@ fixup_ve_lo32
fixup_ve_lo32 - 32-bit fixup corresponding to foo@lo
Definition: VEFixupKinds.h:27
llvm::MCELFObjectTargetWriter
Definition: MCELFObjectWriter.h:53
VEMCTargetDesc.h
llvm::VEMCExpr::VK_VE_PC_LO32
@ VK_VE_PC_LO32
Definition: VEMCExpr.h:31
llvm::VE::fixup_ve_tls_gd_hi32
@ fixup_ve_tls_gd_hi32
fixups for Thread Local Storage
Definition: VEFixupKinds.h:52
MCELFObjectWriter.h
llvm::VE::fixup_ve_gotoff_lo32
@ fixup_ve_gotoff_lo32
fixup_ve_gotoff_lo32 - 32-bit fixup corresponding to foo@gotoff_lo
Definition: VEFixupKinds.h:45
llvm::VE::fixup_ve_gotoff_hi32
@ fixup_ve_gotoff_hi32
fixup_ve_gotoff_hi32 - 32-bit fixup corresponding to foo@gotoff_hi
Definition: VEFixupKinds.h:42
llvm::VE::fixup_ve_hi32
@ fixup_ve_hi32
fixup_ve_hi32 - 32-bit fixup corresponding to foo@hi
Definition: VEFixupKinds.h:24
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1056
llvm::VE::fixup_ve_got_lo32
@ fixup_ve_got_lo32
fixup_ve_got_lo32 - 32-bit fixup corresponding to foo@got_lo
Definition: VEFixupKinds.h:39
llvm::FK_PCRel_2
@ FK_PCRel_2
A two-byte pc relative fixup.
Definition: MCFixup.h:29
llvm::FK_Data_1
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:23
llvm::FK_PCRel_4
@ FK_PCRel_4
A four-byte pc relative fixup.
Definition: MCFixup.h:30
llvm::VE::fixup_ve_got_hi32
@ fixup_ve_got_hi32
fixup_ve_got_hi32 - 32-bit fixup corresponding to foo@got_hi
Definition: VEFixupKinds.h:36
llvm::logicalview::LVBinaryType::ELF
@ ELF
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:215
MCObjectWriter.h
VEMCExpr.h
llvm::VE::fixup_ve_tpoff_lo32
@ fixup_ve_tpoff_lo32
Definition: VEFixupKinds.h:55
llvm::VE::fixup_ve_plt_lo32
@ fixup_ve_plt_lo32
Definition: VEFixupKinds.h:49
MCValue.h
llvm::FK_Data_8
@ FK_Data_8
A eight-byte fixup.
Definition: MCFixup.h:26
llvm::VE::fixup_ve_tpoff_hi32
@ fixup_ve_tpoff_hi32
Definition: VEFixupKinds.h:54
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:36
llvm::ELF::EM_VE
@ EM_VE
Definition: ELF.h:320
llvm::VE::fixup_ve_srel32
@ fixup_ve_srel32
fixup_ve_srel32 - 32-bit fixup corresponding to foo for relative branch
Definition: VEFixupKinds.h:21
llvm::FK_Data_2
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24
MCExpr.h
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71