LLVM  6.0.0svn
HexagonELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- HexagonELFObjectWriter.cpp - Hexagon Target Descriptions ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "Hexagon.h"
12 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCObjectWriter.h"
15 #include "llvm/MC/MCValue.h"
16 #include "llvm/Support/Debug.h"
18 
19 #define DEBUG_TYPE "hexagon-elf-writer"
20 
21 using namespace llvm;
22 using namespace Hexagon;
23 
24 namespace {
25 
26 class HexagonELFObjectWriter : public MCELFObjectTargetWriter {
27 private:
28  StringRef CPU;
29 
30 public:
31  HexagonELFObjectWriter(uint8_t OSABI, StringRef C);
32 
33  unsigned getRelocType(MCContext &Ctx, MCValue const &Target,
34  MCFixup const &Fixup, bool IsPCRel) const override;
35 };
36 }
37 
38 HexagonELFObjectWriter::HexagonELFObjectWriter(uint8_t OSABI, StringRef C)
39  : MCELFObjectTargetWriter(/*Is64bit*/ false, OSABI, ELF::EM_HEXAGON,
40  /*HasRelocationAddend*/ true),
41  CPU(C) {}
42 
44  MCValue const &Target,
45  MCFixup const &Fixup,
46  bool IsPCRel) const {
48  switch ((unsigned)Fixup.getKind()) {
49  default:
50  report_fatal_error("Unrecognized relocation type");
51  break;
52  case FK_Data_4:
53  switch(Variant) {
54  case MCSymbolRefExpr::VariantKind::VK_DTPREL:
55  return ELF::R_HEX_DTPREL_32;
56  case MCSymbolRefExpr::VariantKind::VK_GOT:
57  return ELF::R_HEX_GOT_32;
58  case MCSymbolRefExpr::VariantKind::VK_GOTREL:
59  return ELF::R_HEX_GOTREL_32;
60  case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
61  return ELF::R_HEX_GD_GOT_32;
62  case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE:
63  return ELF::R_HEX_IE_32;
64  case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
65  return ELF::R_HEX_IE_GOT_32;
66  case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
67  return ELF::R_HEX_LD_GOT_32;
68  case MCSymbolRefExpr::VariantKind::VK_Hexagon_PCREL:
69  return ELF::R_HEX_32_PCREL;
70  case MCSymbolRefExpr::VariantKind::VK_TPREL:
71  return ELF::R_HEX_TPREL_32;
72  case MCSymbolRefExpr::VariantKind::VK_None:
73  return IsPCRel ? ELF::R_HEX_32_PCREL : ELF::R_HEX_32;
74  default:
75  report_fatal_error("Unrecognized variant type");
76  };
77  case FK_PCRel_4:
78  return ELF::R_HEX_32_PCREL;
79  case FK_Data_2:
80  switch(Variant) {
81  case MCSymbolRefExpr::VariantKind::VK_DTPREL:
82  return ELF::R_HEX_DTPREL_16;
83  case MCSymbolRefExpr::VariantKind::VK_GOT:
84  return ELF::R_HEX_GOT_16;
85  case MCSymbolRefExpr::VariantKind::VK_Hexagon_GD_GOT:
86  return ELF::R_HEX_GD_GOT_16;
87  case MCSymbolRefExpr::VariantKind::VK_Hexagon_IE_GOT:
88  return ELF::R_HEX_IE_GOT_16;
89  case MCSymbolRefExpr::VariantKind::VK_Hexagon_LD_GOT:
90  return ELF::R_HEX_LD_GOT_16;
91  case MCSymbolRefExpr::VariantKind::VK_TPREL:
92  return ELF::R_HEX_TPREL_16;
93  case MCSymbolRefExpr::VariantKind::VK_None:
94  return ELF::R_HEX_16;
95  default:
96  report_fatal_error("Unrecognized variant type");
97  };
98  case FK_Data_1:
99  return ELF::R_HEX_8;
101  return ELF::R_HEX_B22_PCREL;
103  return ELF::R_HEX_B15_PCREL;
105  return ELF::R_HEX_B7_PCREL;
106  case fixup_Hexagon_LO16:
107  return ELF::R_HEX_LO16;
108  case fixup_Hexagon_HI16:
109  return ELF::R_HEX_HI16;
110  case fixup_Hexagon_32:
111  return ELF::R_HEX_32;
112  case fixup_Hexagon_16:
113  return ELF::R_HEX_16;
114  case fixup_Hexagon_8:
115  return ELF::R_HEX_8;
117  return ELF::R_HEX_GPREL16_0;
119  return ELF::R_HEX_GPREL16_1;
121  return ELF::R_HEX_GPREL16_2;
123  return ELF::R_HEX_GPREL16_3;
124  case fixup_Hexagon_HL16:
125  return ELF::R_HEX_HL16;
127  return ELF::R_HEX_B13_PCREL;
129  return ELF::R_HEX_B9_PCREL;
131  return ELF::R_HEX_B32_PCREL_X;
133  return ELF::R_HEX_32_6_X;
135  return ELF::R_HEX_B22_PCREL_X;
137  return ELF::R_HEX_B15_PCREL_X;
139  return ELF::R_HEX_B13_PCREL_X;
141  return ELF::R_HEX_B9_PCREL_X;
143  return ELF::R_HEX_B7_PCREL_X;
144  case fixup_Hexagon_16_X:
145  return ELF::R_HEX_16_X;
146  case fixup_Hexagon_12_X:
147  return ELF::R_HEX_12_X;
148  case fixup_Hexagon_11_X:
149  return ELF::R_HEX_11_X;
150  case fixup_Hexagon_10_X:
151  return ELF::R_HEX_10_X;
152  case fixup_Hexagon_9_X:
153  return ELF::R_HEX_9_X;
154  case fixup_Hexagon_8_X:
155  return ELF::R_HEX_8_X;
156  case fixup_Hexagon_7_X:
157  return ELF::R_HEX_7_X;
158  case fixup_Hexagon_6_X:
159  return ELF::R_HEX_6_X;
161  return ELF::R_HEX_32_PCREL;
162  case fixup_Hexagon_COPY:
163  return ELF::R_HEX_COPY;
165  return ELF::R_HEX_GLOB_DAT;
167  return ELF::R_HEX_JMP_SLOT;
169  return ELF::R_HEX_RELATIVE;
171  return ELF::R_HEX_PLT_B22_PCREL;
173  return ELF::R_HEX_GOTREL_LO16;
175  return ELF::R_HEX_GOTREL_HI16;
177  return ELF::R_HEX_GOTREL_32;
179  return ELF::R_HEX_GOT_LO16;
181  return ELF::R_HEX_GOT_HI16;
183  return ELF::R_HEX_GOT_32;
185  return ELF::R_HEX_GOT_16;
187  return ELF::R_HEX_DTPMOD_32;
189  return ELF::R_HEX_DTPREL_LO16;
191  return ELF::R_HEX_DTPREL_HI16;
193  return ELF::R_HEX_DTPREL_32;
195  return ELF::R_HEX_DTPREL_16;
197  return ELF::R_HEX_GD_PLT_B22_PCREL;
199  return ELF::R_HEX_LD_PLT_B22_PCREL;
201  return ELF::R_HEX_GD_GOT_LO16;
203  return ELF::R_HEX_GD_GOT_HI16;
205  return ELF::R_HEX_GD_GOT_32;
207  return ELF::R_HEX_GD_GOT_16;
209  return ELF::R_HEX_LD_GOT_LO16;
211  return ELF::R_HEX_LD_GOT_HI16;
213  return ELF::R_HEX_LD_GOT_32;
215  return ELF::R_HEX_LD_GOT_16;
217  return ELF::R_HEX_IE_LO16;
219  return ELF::R_HEX_IE_HI16;
220  case fixup_Hexagon_IE_32:
221  return ELF::R_HEX_IE_32;
223  return ELF::R_HEX_IE_GOT_LO16;
225  return ELF::R_HEX_IE_GOT_HI16;
227  return ELF::R_HEX_IE_GOT_32;
229  return ELF::R_HEX_IE_GOT_16;
231  return ELF::R_HEX_TPREL_LO16;
233  return ELF::R_HEX_TPREL_HI16;
235  return ELF::R_HEX_TPREL_32;
237  return ELF::R_HEX_TPREL_16;
239  return ELF::R_HEX_6_PCREL_X;
241  return ELF::R_HEX_GOTREL_32_6_X;
243  return ELF::R_HEX_GOTREL_16_X;
245  return ELF::R_HEX_GOTREL_11_X;
247  return ELF::R_HEX_GOT_32_6_X;
249  return ELF::R_HEX_GOT_16_X;
251  return ELF::R_HEX_GOT_11_X;
253  return ELF::R_HEX_DTPREL_32_6_X;
255  return ELF::R_HEX_DTPREL_16_X;
257  return ELF::R_HEX_DTPREL_11_X;
259  return ELF::R_HEX_GD_GOT_32_6_X;
261  return ELF::R_HEX_GD_GOT_16_X;
263  return ELF::R_HEX_GD_GOT_11_X;
265  return ELF::R_HEX_LD_GOT_32_6_X;
267  return ELF::R_HEX_LD_GOT_16_X;
269  return ELF::R_HEX_LD_GOT_11_X;
271  return ELF::R_HEX_IE_32_6_X;
273  return ELF::R_HEX_IE_16_X;
275  return ELF::R_HEX_IE_GOT_32_6_X;
277  return ELF::R_HEX_IE_GOT_16_X;
279  return ELF::R_HEX_IE_GOT_11_X;
281  return ELF::R_HEX_TPREL_32_6_X;
283  return ELF::R_HEX_TPREL_16_X;
285  return ELF::R_HEX_TPREL_11_X;
287  return ELF::R_HEX_23_REG;
289  return ELF::R_HEX_27_REG;
291  return ELF::R_HEX_GD_PLT_B22_PCREL_X;
293  return ELF::R_HEX_GD_PLT_B32_PCREL_X;
295  return ELF::R_HEX_LD_PLT_B22_PCREL_X;
297  return ELF::R_HEX_LD_PLT_B32_PCREL_X;
298  }
299 }
300 
301 std::unique_ptr<MCObjectWriter>
303  StringRef CPU) {
304  auto MOTW = llvm::make_unique<HexagonELFObjectWriter>(OSABI, CPU);
305  return createELFObjectWriter(std::move(MOTW), OS, /*IsLittleEndian*/ true);
306 }
std::unique_ptr< MCObjectWriter > createHexagonELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI, StringRef CPU)
uint64_t CallInst * C
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:115
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
MCSymbolRefExpr::VariantKind getAccessVariant() const
Definition: MCValue.cpp:46
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:66
static unsigned getRelocType(const MCValue &Target, const MCFixupKind FixupKind, const bool IsPCRel)
Translates generic PPC fixup kind to Mach-O/PPC relocation type enum.
A four-byte fixup.
Definition: MCFixup.h:26
Context object for machine code objects.
Definition: MCContext.h:59
std::unique_ptr< MCObjectWriter > createELFObjectWriter(std::unique_ptr< MCELFObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
A one-byte fixup.
Definition: MCFixup.h:24
PowerPC TLS Dynamic Call Fixup
A four-byte pc relative fixup.
Definition: MCFixup.h:30
Target - Wrapper for Target specific information.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:337
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A two-byte fixup.
Definition: MCFixup.h:25
MCFixupKind getKind() const
Definition: MCFixup.h:93