LLVM 18.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
12
13#include "llvm/MC/MCAssembler.h"
15#include "llvm/MC/MCExpr.h"
17#include "llvm/MC/MCSection.h"
18#include "llvm/MC/MCValue.h"
20
21namespace llvm {
22
23/// Writes AVR machine code into an ELF32 object file.
25public:
26 AVRELFObjectWriter(uint8_t OSABI);
27
28 virtual ~AVRELFObjectWriter() = default;
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 const unsigned Kind = Fixup.getTargetKind();
42 return Kind - FirstLiteralRelocationKind;
43 MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();
44 switch ((unsigned)Fixup.getKind()) {
45 case FK_Data_1:
46 switch (Modifier) {
47 default:
48 llvm_unreachable("Unsupported Modifier");
50 return ELF::R_AVR_8;
52 return ELF::R_AVR_DIFF8;
54 return ELF::R_AVR_8_LO8;
56 return ELF::R_AVR_8_HI8;
58 return ELF::R_AVR_8_HLO8;
59 }
60 case FK_Data_4:
61 switch (Modifier) {
62 default:
63 llvm_unreachable("Unsupported Modifier");
65 return ELF::R_AVR_32;
67 return ELF::R_AVR_DIFF32;
68 }
69 case FK_Data_2:
70 switch (Modifier) {
71 default:
72 llvm_unreachable("Unsupported Modifier");
74 return ELF::R_AVR_16;
77 return ELF::R_AVR_16_PM;
79 return ELF::R_AVR_DIFF16;
80 }
81 case AVR::fixup_32:
82 return ELF::R_AVR_32;
84 return ELF::R_AVR_7_PCREL;
86 return ELF::R_AVR_13_PCREL;
87 case AVR::fixup_16:
88 return ELF::R_AVR_16;
90 return ELF::R_AVR_16_PM;
92 return ELF::R_AVR_LO8_LDI;
94 return ELF::R_AVR_HI8_LDI;
96 return ELF::R_AVR_HH8_LDI;
98 return ELF::R_AVR_LO8_LDI_NEG;
100 return ELF::R_AVR_HI8_LDI_NEG;
102 return ELF::R_AVR_HH8_LDI_NEG;
104 return ELF::R_AVR_LO8_LDI_PM;
106 return ELF::R_AVR_HI8_LDI_PM;
108 return ELF::R_AVR_HH8_LDI_PM;
110 return ELF::R_AVR_LO8_LDI_PM_NEG;
112 return ELF::R_AVR_HI8_LDI_PM_NEG;
114 return ELF::R_AVR_HH8_LDI_PM_NEG;
115 case AVR::fixup_call:
116 return ELF::R_AVR_CALL;
117 case AVR::fixup_ldi:
118 return ELF::R_AVR_LDI;
119 case AVR::fixup_6:
120 return ELF::R_AVR_6;
122 return ELF::R_AVR_6_ADIW;
124 return ELF::R_AVR_MS8_LDI;
126 return ELF::R_AVR_MS8_LDI_NEG;
128 return ELF::R_AVR_LO8_LDI_GS;
130 return ELF::R_AVR_HI8_LDI_GS;
131 case AVR::fixup_8:
132 return ELF::R_AVR_8;
133 case AVR::fixup_8_lo8:
134 return ELF::R_AVR_8_LO8;
135 case AVR::fixup_8_hi8:
136 return ELF::R_AVR_8_HI8;
138 return ELF::R_AVR_8_HLO8;
139 case AVR::fixup_diff8:
140 return ELF::R_AVR_DIFF8;
142 return ELF::R_AVR_DIFF16;
144 return ELF::R_AVR_DIFF32;
146 return ELF::R_AVR_LDS_STS_16;
147 case AVR::fixup_port6:
148 return ELF::R_AVR_PORT6;
149 case AVR::fixup_port5:
150 return ELF::R_AVR_PORT5;
151 default:
152 llvm_unreachable("invalid fixup kind!");
153 }
154}
155
156std::unique_ptr<MCObjectTargetWriter> createAVRELFObjectWriter(uint8_t OSABI) {
157 return std::make_unique<AVRELFObjectWriter>(OSABI);
158}
159
160} // end of namespace llvm
basic Basic Alias true
PowerPC TLS Dynamic Call Fixup
Writes AVR machine code into an ELF32 object file.
unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const override
virtual ~AVRELFObjectWriter()=default
Context object for machine code objects.
Definition: MCContext.h:76
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:70
This represents an "assembler immediate".
Definition: MCValue.h:36
Target - Wrapper for Target specific information.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ fixup_16_pm
A 16-bit program memory address.
Definition: AVRFixupKinds.h:46
@ fixup_16
A 16-bit address.
Definition: AVRFixupKinds.h:44
@ fixup_call
A 22-bit fixup for the target of a CALL k or JMP k instruction.
@ 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
@ fixup_ms8_ldi_neg
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated 32-bi...
Definition: AVRFixupKinds.h:75
@ fixup_32
A 32-bit AVR fixup.
Definition: AVRFixupKinds.h:28
@ 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
@ fixup_6_adiw
A symbol+addr fixup for the `LDD <x>+<n>, <r>" family of instructions.
@ 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
@ 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
@ fixup_ldi
Replaces the 8-bit immediate with another value.
Definition: AVRFixupKinds.h:49
@ 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
@ 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
@ 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
@ 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
@ fixup_port6
A 6-bit port address.
@ fixup_hh8_ldi_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:72
@ 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
@ fixup_port5
A 5-bit port address.
@ 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
@ 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
@ 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...
@ fixup_13_pcrel
A 12-bit PC-relative fixup for the family of branches which take 12-bit targets (RJMP,...
Definition: AVRFixupKinds.h:41
@ 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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ FirstLiteralRelocationKind
The range [FirstLiteralRelocationKind, MaxTargetFixupKind) is used for relocations coming from ....
Definition: MCFixup.h:49
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:23
@ FK_Data_4
A four-byte fixup.
Definition: MCFixup.h:25
@ FK_Data_2
A two-byte fixup.
Definition: MCFixup.h:24
std::unique_ptr< MCObjectTargetWriter > createAVRELFObjectWriter(uint8_t OSABI)
Creates an ELF object writer for AVR.