LLVM  14.0.0git
AVRELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- AVRELFObjectWriter.cpp - AVR 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 
10 #include "MCTargetDesc/AVRMCExpr.h"
12 
13 #include "llvm/MC/MCAssembler.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCObjectWriter.h"
17 #include "llvm/MC/MCSection.h"
18 #include "llvm/MC/MCValue.h"
20 
21 namespace llvm {
22 
23 /// Writes AVR machine code into an ELF32 object file.
25 public:
26  AVRELFObjectWriter(uint8_t OSABI);
27 
28  virtual ~AVRELFObjectWriter() {}
29 
30  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
31  const MCFixup &Fixup, bool IsPCRel) const override;
32 };
33 
35  : MCELFObjectTargetWriter(false, OSABI, ELF::EM_AVR, true) {}
36 
38  const MCFixup &Fixup,
39  bool IsPCRel) const {
40  MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();
41  switch ((unsigned)Fixup.getKind()) {
42  case FK_Data_1:
43  switch (Modifier) {
44  default:
45  llvm_unreachable("Unsupported Modifier");
47  return ELF::R_AVR_8;
49  return ELF::R_AVR_DIFF8;
51  return ELF::R_AVR_8_LO8;
53  return ELF::R_AVR_8_HI8;
55  return ELF::R_AVR_8_HLO8;
56  }
57  case FK_Data_4:
58  switch (Modifier) {
59  default:
60  llvm_unreachable("Unsupported Modifier");
62  return ELF::R_AVR_32;
64  return ELF::R_AVR_DIFF32;
65  }
66  case FK_Data_2:
67  switch (Modifier) {
68  default:
69  llvm_unreachable("Unsupported Modifier");
71  return ELF::R_AVR_16;
74  return ELF::R_AVR_16_PM;
76  return ELF::R_AVR_DIFF16;
77  }
78  case AVR::fixup_32:
79  return ELF::R_AVR_32;
80  case AVR::fixup_7_pcrel:
81  return ELF::R_AVR_7_PCREL;
83  return ELF::R_AVR_13_PCREL;
84  case AVR::fixup_16:
85  return ELF::R_AVR_16;
86  case AVR::fixup_16_pm:
87  return ELF::R_AVR_16_PM;
88  case AVR::fixup_lo8_ldi:
89  return ELF::R_AVR_LO8_LDI;
90  case AVR::fixup_hi8_ldi:
91  return ELF::R_AVR_HI8_LDI;
92  case AVR::fixup_hh8_ldi:
93  return ELF::R_AVR_HH8_LDI;
95  return ELF::R_AVR_LO8_LDI_NEG;
97  return ELF::R_AVR_HI8_LDI_NEG;
99  return ELF::R_AVR_HH8_LDI_NEG;
101  return ELF::R_AVR_LO8_LDI_PM;
103  return ELF::R_AVR_HI8_LDI_PM;
105  return ELF::R_AVR_HH8_LDI_PM;
107  return ELF::R_AVR_LO8_LDI_PM_NEG;
109  return ELF::R_AVR_HI8_LDI_PM_NEG;
111  return ELF::R_AVR_HH8_LDI_PM_NEG;
112  case AVR::fixup_call:
113  return ELF::R_AVR_CALL;
114  case AVR::fixup_ldi:
115  return ELF::R_AVR_LDI;
116  case AVR::fixup_6:
117  return ELF::R_AVR_6;
118  case AVR::fixup_6_adiw:
119  return ELF::R_AVR_6_ADIW;
120  case AVR::fixup_ms8_ldi:
121  return ELF::R_AVR_MS8_LDI;
123  return ELF::R_AVR_MS8_LDI_NEG;
125  return ELF::R_AVR_LO8_LDI_GS;
127  return ELF::R_AVR_HI8_LDI_GS;
128  case AVR::fixup_8:
129  return ELF::R_AVR_8;
130  case AVR::fixup_8_lo8:
131  return ELF::R_AVR_8_LO8;
132  case AVR::fixup_8_hi8:
133  return ELF::R_AVR_8_HI8;
134  case AVR::fixup_8_hlo8:
135  return ELF::R_AVR_8_HLO8;
136  case AVR::fixup_diff8:
137  return ELF::R_AVR_DIFF8;
138  case AVR::fixup_diff16:
139  return ELF::R_AVR_DIFF16;
140  case AVR::fixup_diff32:
141  return ELF::R_AVR_DIFF32;
143  return ELF::R_AVR_LDS_STS_16;
144  case AVR::fixup_port6:
145  return ELF::R_AVR_PORT6;
146  case AVR::fixup_port5:
147  return ELF::R_AVR_PORT5;
148  default:
149  llvm_unreachable("invalid fixup kind!");
150  }
151 }
152 
153 std::unique_ptr<MCObjectTargetWriter> createAVRELFObjectWriter(uint8_t OSABI) {
154  return std::make_unique<AVRELFObjectWriter>(OSABI);
155 }
156 
157 } // end of namespace llvm
llvm::MCSymbolRefExpr::VK_AVR_HI8
@ VK_AVR_HI8
Definition: MCExpr.h:240
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbolRefExpr::VK_AVR_NONE
@ VK_AVR_NONE
Definition: MCExpr.h:238
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCSymbolRefExpr::VK_AVR_DIFF8
@ VK_AVR_DIFF8
Definition: MCExpr.h:242
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::AVR::fixup_lds_sts_16
@ fixup_lds_sts_16
Definition: AVRFixupKinds.h:121
llvm::AVR::fixup_diff8
@ fixup_diff8
Definition: AVRFixupKinds.h:117
ErrorHandling.h
MCAssembler.h
llvm::AVR::fixup_hh8_ldi_neg
@ fixup_hh8_ldi_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated negat...
Definition: AVRFixupKinds.h:72
llvm::AVR::fixup_lo8_ldi_pm_neg
@ fixup_lo8_ldi_pm_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the lower 8 bits of a negated 16-bi...
Definition: AVRFixupKinds.h:92
llvm::AVR::fixup_port5
@ fixup_port5
A 5-bit port address.
Definition: AVRFixupKinds.h:126
llvm::AVR::fixup_hh8_ldi_pm
@ fixup_hh8_ldi_pm
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 24-bit progra...
Definition: AVRFixupKinds.h:87
llvm::AVR::fixup_hh8_ldi
@ fixup_hh8_ldi
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 24-bit value ...
Definition: AVRFixupKinds.h:59
AVRMCExpr.h
llvm::AVRELFObjectWriter
Writes AVR machine code into an ELF32 object file.
Definition: AVRELFObjectWriter.cpp:24
llvm::AVR::fixup_lo8_ldi
@ fixup_lo8_ldi
Replaces the immediate operand of a 16-bit Rd, K instruction with the lower 8 bits of a 16-bit value ...
Definition: AVRFixupKinds.h:53
llvm::AVR::fixup_hi8_ldi_neg
@ fixup_hi8_ldi_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated 16-bi...
Definition: AVRFixupKinds.h:69
llvm::createAVRELFObjectWriter
std::unique_ptr< MCObjectTargetWriter > createAVRELFObjectWriter(uint8_t OSABI)
Creates an ELF object writer for AVR.
Definition: AVRELFObjectWriter.cpp:153
llvm::AVRELFObjectWriter::getRelocType
unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const override
Definition: AVRELFObjectWriter.cpp:37
llvm::FK_Data_4
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
llvm::AVR::fixup_13_pcrel
@ fixup_13_pcrel
A 12-bit PC-relative fixup for the family of branches which take 12-bit targets (RJMP,...
Definition: AVRFixupKinds.h:41
llvm::MCSymbolRefExpr::VK_AVR_HLO8
@ VK_AVR_HLO8
Definition: MCExpr.h:241
llvm::AVR::fixup_8
@ fixup_8
Definition: AVRFixupKinds.h:112
llvm::AVR::fixup_32
@ fixup_32
A 32-bit AVR fixup.
Definition: AVRFixupKinds.h:28
llvm::AVRELFObjectWriter::~AVRELFObjectWriter
virtual ~AVRELFObjectWriter()
Definition: AVRELFObjectWriter.cpp:28
false
Definition: StackSlotColoring.cpp:142
llvm::AVR::fixup_port6
@ fixup_port6
A 6-bit port address.
Definition: AVRFixupKinds.h:124
llvm::MCELFObjectTargetWriter
Definition: MCELFObjectWriter.h:53
llvm::MCSymbolRefExpr::VK_AVR_DIFF32
@ VK_AVR_DIFF32
Definition: MCExpr.h:244
llvm::AVR::fixup_lo8_ldi_pm
@ fixup_lo8_ldi_pm
Replaces the immediate operand of a 16-bit Rd, K instruction with the lower 8 bits of a 16-bit progra...
Definition: AVRFixupKinds.h:79
llvm::AVR::fixup_6
@ fixup_6
Definition: AVRFixupKinds.h:105
llvm::AVR::fixup_lo8_ldi_neg
@ fixup_lo8_ldi_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the lower 8 bits of a negated 16-bi...
Definition: AVRFixupKinds.h:66
llvm::AVR::fixup_ms8_ldi_neg
@ fixup_ms8_ldi_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated negat...
Definition: AVRFixupKinds.h:75
llvm::AVR::fixup_hi8_ldi_pm
@ fixup_hi8_ldi_pm
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 16-bit progra...
Definition: AVRFixupKinds.h:83
llvm::MCSymbolRefExpr::VK_AVR_LO8
@ VK_AVR_LO8
Definition: MCExpr.h:239
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition: MCExpr.h:194
MCELFObjectWriter.h
llvm::AVR::fixup_diff32
@ fixup_diff32
Definition: AVRFixupKinds.h:119
llvm::AVR::fixup_8_lo8
@ fixup_8_lo8
Definition: AVRFixupKinds.h:113
llvm::AVR::fixup_call
@ fixup_call
A 22-bit fixup for the target of a CALL k or JMP k instruction.
Definition: AVRFixupKinds.h:103
llvm::AVR::fixup_8_hlo8
@ fixup_8_hlo8
Definition: AVRFixupKinds.h:115
AVRMCTargetDesc.h
llvm::FK_Data_1
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:23
MCSection.h
llvm::AVR::fixup_hi8_ldi_gs
@ fixup_hi8_ldi_gs
Definition: AVRFixupKinds.h:110
llvm::AVR::fixup_8_hi8
@ fixup_8_hi8
Definition: AVRFixupKinds.h:114
llvm::MCSymbolRefExpr::VK_AVR_PM
@ VK_AVR_PM
Definition: MCExpr.h:245
AVRFixupKinds.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:136
llvm::AVR::fixup_ldi
@ fixup_ldi
Replaces the 8-bit immediate with another value.
Definition: AVRFixupKinds.h:49
llvm::AVRELFObjectWriter::AVRELFObjectWriter
AVRELFObjectWriter(uint8_t OSABI)
Definition: AVRELFObjectWriter.cpp:34
MCObjectWriter.h
llvm::AVR::fixup_7_pcrel
@ fixup_7_pcrel
A 7-bit PC-relative fixup for the family of conditional branches which take 7-bit targets (BRNE,...
Definition: AVRFixupKinds.h:32
llvm::AVR::fixup_16
@ fixup_16
A 16-bit address.
Definition: AVRFixupKinds.h:44
llvm::AVR::fixup_6_adiw
@ fixup_6_adiw
A symbol+addr fixup for the `LDD <x>+<n>, <r>" family of instructions.
Definition: AVRFixupKinds.h:107
MCValue.h
llvm::AVR::fixup_ms8_ldi
@ fixup_ms8_ldi
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 32-bit value ...
Definition: AVRFixupKinds.h:62
llvm::MCSymbolRefExpr::VK_AVR_DIFF16
@ VK_AVR_DIFF16
Definition: MCExpr.h:243
llvm::AVR::fixup_hi8_ldi
@ fixup_hi8_ldi
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 16-bit value ...
Definition: AVRFixupKinds.h:56
llvm::ELF::EM_AVR
@ EM_AVR
Definition: ELF.h:200
llvm::AVR::fixup_hh8_ldi_pm_neg
@ fixup_hh8_ldi_pm_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated 24-bi...
Definition: AVRFixupKinds.h:100
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
llvm::FK_Data_2
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24
llvm::AVR::fixup_16_pm
@ fixup_16_pm
A 16-bit program memory address.
Definition: AVRFixupKinds.h:46
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::AVR::fixup_lo8_ldi_gs
@ fixup_lo8_ldi_gs
Definition: AVRFixupKinds.h:109
MCExpr.h
llvm::AVR::fixup_diff16
@ fixup_diff16
Definition: AVRFixupKinds.h:118
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::AVR::fixup_hi8_ldi_pm_neg
@ fixup_hi8_ldi_pm_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated 16-bi...
Definition: AVRFixupKinds.h:96