LLVM  9.0.0svn
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 
11 
12 #include "llvm/MC/MCAssembler.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"
19 
20 namespace llvm {
21 
22 /// Writes AVR machine code into an ELF32 object file.
24 public:
25  AVRELFObjectWriter(uint8_t OSABI);
26 
27  virtual ~AVRELFObjectWriter() {}
28 
29  unsigned getRelocType(MCContext &Ctx,
30  const MCValue &Target,
31  const MCFixup &Fixup,
32  bool IsPCRel) const override;
33 };
34 
36  : MCELFObjectTargetWriter(false, OSABI, ELF::EM_AVR, true) {}
37 
39  const MCValue &Target,
40  const MCFixup &Fixup,
41  bool IsPCRel) const {
43  switch ((unsigned) Fixup.getKind()) {
44  case FK_Data_1:
45  switch (Modifier) {
46  default:
47  llvm_unreachable("Unsupported Modifier");
49  return ELF::R_AVR_8;
51  return ELF::R_AVR_DIFF8;
53  return ELF::R_AVR_8_LO8;
55  return ELF::R_AVR_8_HI8;
57  return ELF::R_AVR_8_HLO8;
58  }
59  case FK_Data_4:
60  switch (Modifier) {
61  default:
62  llvm_unreachable("Unsupported Modifier");
64  return ELF::R_AVR_32;
66  return ELF::R_AVR_DIFF32;
67  }
68  case FK_Data_2:
69  switch (Modifier) {
70  default:
71  llvm_unreachable("Unsupported Modifier");
73  return ELF::R_AVR_16;
75  return ELF::R_AVR_16_PM;
77  return ELF::R_AVR_DIFF16;
78  }
79  case AVR::fixup_32:
80  return ELF::R_AVR_32;
81  case AVR::fixup_7_pcrel:
82  return ELF::R_AVR_7_PCREL;
84  return ELF::R_AVR_13_PCREL;
85  case AVR::fixup_16:
86  return ELF::R_AVR_16;
87  case AVR::fixup_16_pm:
88  return ELF::R_AVR_16_PM;
89  case AVR::fixup_lo8_ldi:
90  return ELF::R_AVR_LO8_LDI;
91  case AVR::fixup_hi8_ldi:
92  return ELF::R_AVR_HI8_LDI;
93  case AVR::fixup_hh8_ldi:
94  return ELF::R_AVR_HH8_LDI;
96  return ELF::R_AVR_LO8_LDI_NEG;
98  return ELF::R_AVR_HI8_LDI_NEG;
100  return ELF::R_AVR_HH8_LDI_NEG;
102  return ELF::R_AVR_LO8_LDI_PM;
104  return ELF::R_AVR_HI8_LDI_PM;
106  return ELF::R_AVR_HH8_LDI_PM;
108  return ELF::R_AVR_LO8_LDI_PM_NEG;
110  return ELF::R_AVR_HI8_LDI_PM_NEG;
112  return ELF::R_AVR_HH8_LDI_PM_NEG;
113  case AVR::fixup_call:
114  return ELF::R_AVR_CALL;
115  case AVR::fixup_ldi:
116  return ELF::R_AVR_LDI;
117  case AVR::fixup_6:
118  return ELF::R_AVR_6;
119  case AVR::fixup_6_adiw:
120  return ELF::R_AVR_6_ADIW;
121  case AVR::fixup_ms8_ldi:
122  return ELF::R_AVR_MS8_LDI;
124  return ELF::R_AVR_MS8_LDI_NEG;
126  return ELF::R_AVR_LO8_LDI_GS;
128  return ELF::R_AVR_HI8_LDI_GS;
129  case AVR::fixup_8:
130  return ELF::R_AVR_8;
131  case AVR::fixup_8_lo8:
132  return ELF::R_AVR_8_LO8;
133  case AVR::fixup_8_hi8:
134  return ELF::R_AVR_8_HI8;
135  case AVR::fixup_8_hlo8:
136  return ELF::R_AVR_8_HLO8;
137  case AVR::fixup_diff8:
138  return ELF::R_AVR_DIFF8;
139  case AVR::fixup_diff16:
140  return ELF::R_AVR_DIFF16;
141  case AVR::fixup_diff32:
142  return ELF::R_AVR_DIFF32;
144  return ELF::R_AVR_LDS_STS_16;
145  case AVR::fixup_port6:
146  return ELF::R_AVR_PORT6;
147  case AVR::fixup_port5:
148  return ELF::R_AVR_PORT5;
149  default:
150  llvm_unreachable("invalid fixup kind!");
151  }
152 }
153 
154 std::unique_ptr<MCObjectTargetWriter> createAVRELFObjectWriter(uint8_t OSABI) {
155  return make_unique<AVRELFObjectWriter>(OSABI);
156 }
157 
158 } // end of namespace llvm
159 
std::unique_ptr< MCObjectTargetWriter > createAVRELFObjectWriter(uint8_t OSABI)
Creates an ELF object writer for AVR.
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 class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
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
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
block Block Frequency true
MCSymbolRefExpr::VariantKind getAccessVariant() const
Definition: MCValue.cpp:46
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
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:74
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated negat...
Definition: AVRFixupKinds.h:75
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
A four-byte fixup.
Definition: MCFixup.h:26
A 12-bit PC-relative fixup for the family of branches which take 12-bit targets (RJMP,RCALL,etc).
Definition: AVRFixupKinds.h:41
Context object for machine code objects.
Definition: MCContext.h:64
A 7-bit PC-relative fixup for the family of conditional branches which take 7-bit targets (BRNE...
Definition: AVRFixupKinds.h:32
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated negat...
Definition: AVRFixupKinds.h:72
A 5-bit port address.
A 16-bit address.
Definition: AVRFixupKinds.h:44
unsigned getRelocType(MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const override
A symbol+addr fixup for the `LDD <x>+<n>, <r>" family of instructions.
A 16-bit program memory address.
Definition: AVRFixupKinds.h:46
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
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A one-byte fixup.
Definition: MCFixup.h:24
PowerPC TLS Dynamic Call Fixup
A 6-bit port address.
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated 24-bi...
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
Writes AVR machine code into an ELF32 object file.
Target - Wrapper for Target specific information.
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
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
A 22-bit fixup for the target of a CALL k or JMP k instruction.
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
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
Replaces the 8-bit immediate with another value.
Definition: AVRFixupKinds.h:49
A two-byte fixup.
Definition: MCFixup.h:25
A 32-bit AVR fixup.
Definition: AVRFixupKinds.h:28
MCFixupKind getKind() const
Definition: MCFixup.h:123