LLVM  14.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"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCObjectWriter.h"
15 #include "llvm/MC/MCValue.h"
17 
18 using namespace llvm;
19 
20 namespace {
21 class VEELFObjectWriter : public MCELFObjectTargetWriter {
22 public:
23  VEELFObjectWriter(uint8_t OSABI)
24  : MCELFObjectTargetWriter(/* Is64Bit */ true, OSABI, ELF::EM_VE,
25  /* HasRelocationAddend */ true) {}
26 
27  ~VEELFObjectWriter() override {}
28 
29 protected:
30  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
31  const MCFixup &Fixup, bool IsPCRel) const override;
32 
33  bool needsRelocateWithSymbol(const MCSymbol &Sym,
34  unsigned Type) const override;
35 };
36 } // namespace
37 
38 unsigned VEELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
39  const MCFixup &Fixup,
40  bool IsPCRel) const {
41  if (const VEMCExpr *SExpr = dyn_cast<VEMCExpr>(Fixup.getValue())) {
42  if (SExpr->getKind() == VEMCExpr::VK_VE_PC_LO32)
43  return ELF::R_VE_PC_LO32;
44  }
45 
46  if (IsPCRel) {
47  switch (Fixup.getTargetKind()) {
48  default:
49  llvm_unreachable("Unimplemented fixup -> relocation");
50  case FK_PCRel_1:
51  llvm_unreachable("Unimplemented fixup fk_data_1 -> relocation");
52  case FK_PCRel_2:
53  llvm_unreachable("Unimplemented fixup fk_data_2 -> relocation");
54  // FIXME: relative kind?
55  case FK_PCRel_4:
56  return ELF::R_VE_REFLONG;
57  case FK_PCRel_8:
58  return ELF::R_VE_REFQUAD;
60  return ELF::R_VE_PC_HI32;
62  return ELF::R_VE_PC_LO32;
63  }
64  }
65 
66  switch (Fixup.getTargetKind()) {
67  default:
68  llvm_unreachable("Unimplemented fixup -> relocation");
69  case FK_Data_1:
70  llvm_unreachable("Unimplemented fixup fk_data_1 -> relocation");
71  case FK_Data_2:
72  llvm_unreachable("Unimplemented fixup fk_data_2 -> relocation");
73  case FK_Data_4:
74  return ELF::R_VE_REFLONG;
75  case FK_Data_8:
76  return ELF::R_VE_REFQUAD;
78  return ELF::R_VE_REFLONG;
79  case VE::fixup_ve_hi32:
80  return ELF::R_VE_HI32;
81  case VE::fixup_ve_lo32:
82  return ELF::R_VE_LO32;
84  llvm_unreachable("Unimplemented fixup pc_hi32 -> relocation");
86  llvm_unreachable("Unimplemented fixup pc_lo32 -> relocation");
88  return ELF::R_VE_GOT_HI32;
90  return ELF::R_VE_GOT_LO32;
92  return ELF::R_VE_GOTOFF_HI32;
94  return ELF::R_VE_GOTOFF_LO32;
96  return ELF::R_VE_PLT_HI32;
98  return ELF::R_VE_PLT_LO32;
100  return ELF::R_VE_TLS_GD_HI32;
102  return ELF::R_VE_TLS_GD_LO32;
104  return ELF::R_VE_TPOFF_HI32;
106  return ELF::R_VE_TPOFF_LO32;
107  }
108 
109  return ELF::R_VE_NONE;
110 }
111 
112 bool VEELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
113  unsigned Type) const {
114  switch (Type) {
115  default:
116  return false;
117 
118  // All relocations that use a GOT need a symbol, not an offset, as
119  // the offset of the symbol within the section is irrelevant to
120  // where the GOT entry is. Don't need to list all the TLS entries,
121  // as they're all marked as requiring a symbol anyways.
122  case ELF::R_VE_GOT_HI32:
123  case ELF::R_VE_GOT_LO32:
124  case ELF::R_VE_GOTOFF_HI32:
125  case ELF::R_VE_GOTOFF_LO32:
126  case ELF::R_VE_TLS_GD_HI32:
127  case ELF::R_VE_TLS_GD_LO32:
128  return true;
129  }
130 }
131 
132 std::unique_ptr<MCObjectTargetWriter>
134  return std::make_unique<VEELFObjectWriter>(OSABI);
135 }
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:45
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:30
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
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:72
llvm::createVEELFObjectWriter
std::unique_ptr< MCObjectTargetWriter > createVEELFObjectWriter(uint8_t OSABI)
Definition: VEELFObjectWriter.cpp:133
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
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:27
ErrorHandling.h
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:50
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
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:24
llvm::MCELFObjectTargetWriter
Definition: MCELFObjectWriter.h:53
llvm::ELF::EM_VE
@ EM_VE
Definition: ELF.h:321
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:49
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:42
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:39
llvm::VE::fixup_ve_hi32
@ fixup_ve_hi32
fixup_ve_hi32 - 32-bit fixup corresponding to foo@hi
Definition: VEFixupKinds.h:21
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:36
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:33
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:235
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
MCObjectWriter.h
VEMCExpr.h
llvm::VE::fixup_ve_tpoff_lo32
@ fixup_ve_tpoff_lo32
Definition: VEFixupKinds.h:52
llvm::VE::fixup_ve_plt_lo32
@ fixup_ve_plt_lo32
Definition: VEFixupKinds.h:46
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:51
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::FK_Data_2
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
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