Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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
9#include "MCTargetDesc/AVRFixupKinds.h"
10#include "MCTargetDesc/AVRMCTargetDesc.h"
11
12#include "llvm/MC/MCAssembler.h"
13#include "llvm/MC/MCELFObjectWriter.h"
14#include "llvm/MC/MCExpr.h"
15#include "llvm/MC/MCObjectWriter.h"
16#include "llvm/MC/MCSection.h"
17#include "llvm/MC/MCValue.h"
18#include "llvm/Support/ErrorHandling.h"
19
20namespacellvm {
21
22/// Writes AVR machine code into an ELF32 object file.
23classAVRELFObjectWriter :publicMCELFObjectTargetWriter {
24public:
25AVRELFObjectWriter(uint8_t OSABI);
26
27virtual~AVRELFObjectWriter() =default;
28
29unsignedgetRelocType(MCContext &Ctx,constMCValue &Target,
30constMCFixup &Fixup,bool IsPCRel)const override;
31};
32
33AVRELFObjectWriter::AVRELFObjectWriter(uint8_t OSABI)
34 :MCELFObjectTargetWriter(false, OSABI, ELF::EM_AVR,true) {}
35
36unsignedAVRELFObjectWriter::getRelocType(MCContext &Ctx,constMCValue &Target,
37constMCFixup &Fixup,
38bool IsPCRel) const{
39constunsigned Kind =Fixup.getTargetKind();
40if (Kind >=FirstLiteralRelocationKind)
41return Kind -FirstLiteralRelocationKind;
42MCSymbolRefExpr::VariantKind Modifier =Target.getAccessVariant();
43switch ((unsigned)Fixup.getKind()) {
44caseFK_Data_1:
45switch (Modifier) {
46default:
47llvm_unreachable("Unsupported Modifier");
48caseMCSymbolRefExpr::VK_None:
49return ELF::R_AVR_8;
50caseMCSymbolRefExpr::VK_AVR_DIFF8:
51return ELF::R_AVR_DIFF8;
52caseMCSymbolRefExpr::VK_AVR_LO8:
53return ELF::R_AVR_8_LO8;
54caseMCSymbolRefExpr::VK_AVR_HI8:
55return ELF::R_AVR_8_HI8;
56caseMCSymbolRefExpr::VK_AVR_HLO8:
57return ELF::R_AVR_8_HLO8;
58 }
59caseFK_Data_4:
60switch (Modifier) {
61default:
62llvm_unreachable("Unsupported Modifier");
63caseMCSymbolRefExpr::VK_None:
64return ELF::R_AVR_32;
65caseMCSymbolRefExpr::VK_AVR_DIFF32:
66return ELF::R_AVR_DIFF32;
67 }
68caseFK_Data_2:
69switch (Modifier) {
70default:
71llvm_unreachable("Unsupported Modifier");
72caseMCSymbolRefExpr::VK_None:
73return ELF::R_AVR_16;
74caseMCSymbolRefExpr::VK_AVR_NONE:
75caseMCSymbolRefExpr::VK_AVR_PM:
76return ELF::R_AVR_16_PM;
77caseMCSymbolRefExpr::VK_AVR_DIFF16:
78return ELF::R_AVR_DIFF16;
79 }
80caseAVR::fixup_32:
81return ELF::R_AVR_32;
82caseAVR::fixup_7_pcrel:
83return ELF::R_AVR_7_PCREL;
84caseAVR::fixup_13_pcrel:
85return ELF::R_AVR_13_PCREL;
86caseAVR::fixup_16:
87return ELF::R_AVR_16;
88caseAVR::fixup_16_pm:
89return ELF::R_AVR_16_PM;
90caseAVR::fixup_lo8_ldi:
91return ELF::R_AVR_LO8_LDI;
92caseAVR::fixup_hi8_ldi:
93return ELF::R_AVR_HI8_LDI;
94caseAVR::fixup_hh8_ldi:
95return ELF::R_AVR_HH8_LDI;
96caseAVR::fixup_lo8_ldi_neg:
97return ELF::R_AVR_LO8_LDI_NEG;
98caseAVR::fixup_hi8_ldi_neg:
99return ELF::R_AVR_HI8_LDI_NEG;
100caseAVR::fixup_hh8_ldi_neg:
101return ELF::R_AVR_HH8_LDI_NEG;
102caseAVR::fixup_lo8_ldi_pm:
103return ELF::R_AVR_LO8_LDI_PM;
104caseAVR::fixup_hi8_ldi_pm:
105return ELF::R_AVR_HI8_LDI_PM;
106caseAVR::fixup_hh8_ldi_pm:
107return ELF::R_AVR_HH8_LDI_PM;
108caseAVR::fixup_lo8_ldi_pm_neg:
109return ELF::R_AVR_LO8_LDI_PM_NEG;
110caseAVR::fixup_hi8_ldi_pm_neg:
111return ELF::R_AVR_HI8_LDI_PM_NEG;
112caseAVR::fixup_hh8_ldi_pm_neg:
113return ELF::R_AVR_HH8_LDI_PM_NEG;
114caseAVR::fixup_call:
115return ELF::R_AVR_CALL;
116caseAVR::fixup_ldi:
117return ELF::R_AVR_LDI;
118caseAVR::fixup_6:
119return ELF::R_AVR_6;
120caseAVR::fixup_6_adiw:
121return ELF::R_AVR_6_ADIW;
122caseAVR::fixup_ms8_ldi:
123return ELF::R_AVR_MS8_LDI;
124caseAVR::fixup_ms8_ldi_neg:
125return ELF::R_AVR_MS8_LDI_NEG;
126caseAVR::fixup_lo8_ldi_gs:
127return ELF::R_AVR_LO8_LDI_GS;
128caseAVR::fixup_hi8_ldi_gs:
129return ELF::R_AVR_HI8_LDI_GS;
130caseAVR::fixup_8:
131return ELF::R_AVR_8;
132caseAVR::fixup_8_lo8:
133return ELF::R_AVR_8_LO8;
134caseAVR::fixup_8_hi8:
135return ELF::R_AVR_8_HI8;
136caseAVR::fixup_8_hlo8:
137return ELF::R_AVR_8_HLO8;
138caseAVR::fixup_diff8:
139return ELF::R_AVR_DIFF8;
140caseAVR::fixup_diff16:
141return ELF::R_AVR_DIFF16;
142caseAVR::fixup_diff32:
143return ELF::R_AVR_DIFF32;
144caseAVR::fixup_lds_sts_16:
145return ELF::R_AVR_LDS_STS_16;
146caseAVR::fixup_port6:
147return ELF::R_AVR_PORT6;
148caseAVR::fixup_port5:
149return ELF::R_AVR_PORT5;
150default:
151llvm_unreachable("invalid fixup kind!");
152 }
153}
154
155std::unique_ptr<MCObjectTargetWriter>createAVRELFObjectWriter(uint8_t OSABI) {
156return std::make_unique<AVRELFObjectWriter>(OSABI);
157}
158
159}// end of namespace llvm
AVRFixupKinds.h
AVRMCTargetDesc.h
true
basic Basic Alias true
Definition:BasicAliasAnalysis.cpp:1981
MCAssembler.h
MCELFObjectWriter.h
MCExpr.h
MCObjectWriter.h
MCSection.h
MCValue.h
Fixup
PowerPC TLS Dynamic Call Fixup
Definition:PPCTLSDynamicCall.cpp:339
llvm::AVRELFObjectWriter
Writes AVR machine code into an ELF32 object file.
Definition:AVRELFObjectWriter.cpp:23
llvm::AVRELFObjectWriter::AVRELFObjectWriter
AVRELFObjectWriter(uint8_t OSABI)
Definition:AVRELFObjectWriter.cpp:33
llvm::AVRELFObjectWriter::getRelocType
unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const override
Definition:AVRELFObjectWriter.cpp:36
llvm::AVRELFObjectWriter::~AVRELFObjectWriter
virtual ~AVRELFObjectWriter()=default
llvm::MCContext
Context object for machine code objects.
Definition:MCContext.h:83
llvm::MCELFObjectTargetWriter
Definition:MCELFObjectWriter.h:53
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition:MCFixup.h:71
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition:MCExpr.h:194
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition:MCExpr.h:195
llvm::MCSymbolRefExpr::VK_AVR_NONE
@ VK_AVR_NONE
Definition:MCExpr.h:246
llvm::MCSymbolRefExpr::VK_AVR_DIFF8
@ VK_AVR_DIFF8
Definition:MCExpr.h:250
llvm::MCSymbolRefExpr::VK_AVR_DIFF16
@ VK_AVR_DIFF16
Definition:MCExpr.h:251
llvm::MCSymbolRefExpr::VK_AVR_LO8
@ VK_AVR_LO8
Definition:MCExpr.h:247
llvm::MCSymbolRefExpr::VK_AVR_DIFF32
@ VK_AVR_DIFF32
Definition:MCExpr.h:252
llvm::MCSymbolRefExpr::VK_AVR_HLO8
@ VK_AVR_HLO8
Definition:MCExpr.h:249
llvm::MCSymbolRefExpr::VK_AVR_HI8
@ VK_AVR_HI8
Definition:MCExpr.h:248
llvm::MCSymbolRefExpr::VK_AVR_PM
@ VK_AVR_PM
Definition:MCExpr.h:253
llvm::MCValue
This represents an "assembler immediate".
Definition:MCValue.h:36
llvm::Target
Target - Wrapper for Target specific information.
Definition:TargetRegistry.h:144
uint8_t
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
false
Definition:StackSlotColoring.cpp:193
llvm::AVR::fixup_diff16
@ fixup_diff16
Definition:AVRFixupKinds.h:118
llvm::AVR::fixup_16_pm
@ fixup_16_pm
A 16-bit program memory address.
Definition:AVRFixupKinds.h:46
llvm::AVR::fixup_16
@ fixup_16
A 16-bit address.
Definition:AVRFixupKinds.h:44
llvm::AVR::fixup_hi8_ldi_gs
@ fixup_hi8_ldi_gs
Definition:AVRFixupKinds.h:110
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_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
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 32-bi...
Definition:AVRFixupKinds.h:75
llvm::AVR::fixup_32
@ fixup_32
A 32-bit AVR fixup.
Definition:AVRFixupKinds.h:28
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_diff8
@ fixup_diff8
Definition:AVRFixupKinds.h:117
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
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::AVR::fixup_8_hlo8
@ fixup_8_hlo8
Definition:AVRFixupKinds.h:115
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_ldi
@ fixup_ldi
Replaces the 8-bit immediate with another value.
Definition:AVRFixupKinds.h:49
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_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
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::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_port6
@ fixup_port6
A 6-bit port address.
Definition:AVRFixupKinds.h:124
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 24-bi...
Definition:AVRFixupKinds.h:72
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_8_lo8
@ fixup_8_lo8
Definition:AVRFixupKinds.h:113
llvm::AVR::fixup_port5
@ fixup_port5
A 5-bit port address.
Definition:AVRFixupKinds.h:126
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_lo8_ldi_gs
@ fixup_lo8_ldi_gs
Definition:AVRFixupKinds.h:109
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::AVR::fixup_8_hi8
@ fixup_8_hi8
Definition:AVRFixupKinds.h:114
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::AVR::fixup_8
@ fixup_8
Definition:AVRFixupKinds.h:112
llvm::AVR::fixup_diff32
@ fixup_diff32
Definition:AVRFixupKinds.h:119
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::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::AVR::fixup_6
@ fixup_6
Definition:AVRFixupKinds.h:105
llvm::AVR::fixup_lds_sts_16
@ fixup_lds_sts_16
Definition:AVRFixupKinds.h:121
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::FirstLiteralRelocationKind
@ FirstLiteralRelocationKind
The range [FirstLiteralRelocationKind, MaxTargetFixupKind) is used for relocations coming from ....
Definition:MCFixup.h:50
llvm::FK_Data_1
@ FK_Data_1
A one-byte fixup.
Definition:MCFixup.h:23
llvm::FK_Data_4
@ FK_Data_4
A four-byte fixup.
Definition:MCFixup.h:25
llvm::FK_Data_2
@ FK_Data_2
A two-byte fixup.
Definition:MCFixup.h:24
llvm::createAVRELFObjectWriter
std::unique_ptr< MCObjectTargetWriter > createAVRELFObjectWriter(uint8_t OSABI)
Creates an ELF object writer for AVR.
Definition:AVRELFObjectWriter.cpp:155

Generated on Sun Jul 20 2025 11:42:54 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp