LLVM  14.0.0git
M68kELFObjectWriter.cpp
Go to the documentation of this file.
1 //===---------- M68kELFObjectWriter.cpp - M68k ELF Writer ---*- C++ -*-===//
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 /// \file
10 /// This file contains definitions for M68k ELF Writers
11 ///
12 //===----------------------------------------------------------------------===//
13 
16 
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCValue.h"
24 
25 using namespace llvm;
26 
27 namespace {
28 class M68kELFObjectWriter : public MCELFObjectTargetWriter {
29 public:
30  M68kELFObjectWriter(uint8_t OSABI);
31 
32  ~M68kELFObjectWriter() override;
33 
34 protected:
35  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
36  const MCFixup &Fixup, bool IsPCRel) const override;
37 };
38 } // namespace
39 
40 M68kELFObjectWriter::M68kELFObjectWriter(uint8_t OSABI)
41  : MCELFObjectTargetWriter(false, OSABI, ELF::EM_68K, /* RELA */ true) {}
42 
43 M68kELFObjectWriter::~M68kELFObjectWriter() {}
44 
46 
47 static M68kRelType
48 getType(unsigned Kind, MCSymbolRefExpr::VariantKind &Modifier, bool &IsPCRel) {
49  switch (Kind) {
50  case FK_Data_4:
51  case FK_PCRel_4:
52  return RT_32;
53  case FK_PCRel_2:
54  case FK_Data_2:
55  return RT_16;
56  case FK_PCRel_1:
57  case FK_Data_1:
58  return RT_8;
59  }
60  llvm_unreachable("Unimplemented");
61 }
62 
63 unsigned M68kELFObjectWriter::getRelocType(MCContext &Ctx,
64  const MCValue &Target,
65  const MCFixup &Fixup,
66  bool IsPCRel) const {
67  MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();
68  unsigned Kind = Fixup.getKind();
69  M68kRelType Type = getType(Kind, Modifier, IsPCRel);
70  switch (Modifier) {
71  default:
72  llvm_unreachable("Unimplemented");
74  switch (Type) {
75  case RT_32:
76  return IsPCRel ? ELF::R_68K_PC32 : ELF::R_68K_32;
77  case RT_16:
78  return IsPCRel ? ELF::R_68K_PC16 : ELF::R_68K_16;
79  case RT_8:
80  return IsPCRel ? ELF::R_68K_PC8 : ELF::R_68K_8;
81  }
82  llvm_unreachable("Unrecognized size");
84  switch (Type) {
85  case RT_32:
86  return ELF::R_68K_GOTPCREL32;
87  case RT_16:
88  return ELF::R_68K_GOTPCREL16;
89  case RT_8:
90  return ELF::R_68K_GOTPCREL8;
91  }
92  llvm_unreachable("Unrecognized size");
94  assert(!IsPCRel);
95  switch (Type) {
96  case RT_32:
97  return ELF::R_68K_GOTOFF32;
98  case RT_16:
99  return ELF::R_68K_GOTOFF16;
100  case RT_8:
101  return ELF::R_68K_GOTOFF8;
102  }
103  llvm_unreachable("Unrecognized size");
105  switch (Type) {
106  case RT_32:
107  return ELF::R_68K_PLT32;
108  case RT_16:
109  return ELF::R_68K_PLT16;
110  case RT_8:
111  return ELF::R_68K_PLT8;
112  }
113  llvm_unreachable("Unrecognized size");
114  }
115 }
116 
117 std::unique_ptr<MCObjectTargetWriter>
119  return std::make_unique<M68kELFObjectWriter>(OSABI);
120 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
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::MCSymbolRefExpr::VK_GOTOFF
@ VK_GOTOFF
Definition: MCExpr.h:199
llvm::FK_PCRel_1
@ FK_PCRel_1
A one-byte pc relative fixup.
Definition: MCFixup.h:28
RT_32
@ RT_32
Definition: M68kELFObjectWriter.cpp:45
llvm::FK_Data_4
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
ELF.h
MCContext.h
false
Definition: StackSlotColoring.cpp:142
llvm::MCELFObjectTargetWriter
Definition: MCELFObjectWriter.h:53
llvm::ELF::EM_68K
@ EM_68K
Definition: ELF.h:138
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition: MCExpr.h:194
M68kMCTargetDesc.h
MCELFObjectWriter.h
llvm::MCSymbolRefExpr::VK_PLT
@ VK_PLT
Definition: MCExpr.h:207
M68kFixupKinds.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
getType
static M68kRelType getType(unsigned Kind, MCSymbolRefExpr::VariantKind &Modifier, bool &IsPCRel)
Definition: M68kELFObjectWriter.cpp:48
MCAsmInfo.h
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:134
llvm::MCSymbolRefExpr::VK_GOTPCREL
@ VK_GOTPCREL
Definition: MCExpr.h:202
RT_16
@ RT_16
Definition: M68kELFObjectWriter.cpp:45
llvm::createM68kELFObjectWriter
std::unique_ptr< MCObjectTargetWriter > createM68kELFObjectWriter(uint8_t OSABI)
Construct an M68k ELF object writer.
Definition: M68kELFObjectWriter.cpp:118
M68kRelType
M68kRelType
Definition: M68kELFObjectWriter.cpp:45
MCValue.h
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
RT_8
@ RT_8
Definition: M68kELFObjectWriter.cpp:45
llvm::FK_Data_2
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1927
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