LLVM  8.0.1
AVRELFObjectWriter.cpp
Go to the documentation of this file.
1 //===-- AVRELFObjectWriter.cpp - AVR ELF Writer ---------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
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,
31  const MCValue &Target,
32  const MCFixup &Fixup,
33  bool IsPCRel) const override;
34 };
35 
37  : MCELFObjectTargetWriter(false, OSABI, ELF::EM_AVR, true) {}
38 
40  const MCValue &Target,
41  const MCFixup &Fixup,
42  bool IsPCRel) const {
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;
76  return ELF::R_AVR_16_PM;
78  return ELF::R_AVR_DIFF16;
79  }
80  case AVR::fixup_32:
81  return ELF::R_AVR_32;
82  case AVR::fixup_7_pcrel:
83  return ELF::R_AVR_7_PCREL;
85  return ELF::R_AVR_13_PCREL;
86  case AVR::fixup_16:
87  return ELF::R_AVR_16;
88  case AVR::fixup_16_pm:
89  return ELF::R_AVR_16_PM;
90  case AVR::fixup_lo8_ldi:
91  return ELF::R_AVR_LO8_LDI;
92  case AVR::fixup_hi8_ldi:
93  return ELF::R_AVR_HI8_LDI;
94  case AVR::fixup_hh8_ldi:
95  return ELF::R_AVR_HH8_LDI;
97  return ELF::R_AVR_LO8_LDI_NEG;
99  return ELF::R_AVR_HI8_LDI_NEG;
101  return ELF::R_AVR_HH8_LDI_NEG;
103  return ELF::R_AVR_LO8_LDI_PM;
105  return ELF::R_AVR_HI8_LDI_PM;
107  return ELF::R_AVR_HH8_LDI_PM;
109  return ELF::R_AVR_LO8_LDI_PM_NEG;
111  return ELF::R_AVR_HI8_LDI_PM_NEG;
113  return ELF::R_AVR_HH8_LDI_PM_NEG;
114  case AVR::fixup_call:
115  return ELF::R_AVR_CALL;
116  case AVR::fixup_ldi:
117  return ELF::R_AVR_LDI;
118  case AVR::fixup_6:
119  return ELF::R_AVR_6;
120  case AVR::fixup_6_adiw:
121  return ELF::R_AVR_6_ADIW;
122  case AVR::fixup_ms8_ldi:
123  return ELF::R_AVR_MS8_LDI;
125  return ELF::R_AVR_MS8_LDI_NEG;
127  return ELF::R_AVR_LO8_LDI_GS;
129  return ELF::R_AVR_HI8_LDI_GS;
130  case AVR::fixup_8:
131  return ELF::R_AVR_8;
132  case AVR::fixup_8_lo8:
133  return ELF::R_AVR_8_LO8;
134  case AVR::fixup_8_hi8:
135  return ELF::R_AVR_8_HI8;
136  case AVR::fixup_8_hlo8:
137  return ELF::R_AVR_8_HLO8;
138  case AVR::fixup_diff8:
139  return ELF::R_AVR_DIFF8;
140  case AVR::fixup_diff16:
141  return ELF::R_AVR_DIFF16;
142  case AVR::fixup_diff32:
143  return ELF::R_AVR_DIFF32;
145  return ELF::R_AVR_LDS_STS_16;
146  case AVR::fixup_port6:
147  return ELF::R_AVR_PORT6;
148  case AVR::fixup_port5:
149  return ELF::R_AVR_PORT5;
150  default:
151  llvm_unreachable("invalid fixup kind!");
152  }
153 }
154 
155 std::unique_ptr<MCObjectTargetWriter> createAVRELFObjectWriter(uint8_t OSABI) {
156  return make_unique<AVRELFObjectWriter>(OSABI);
157 }
158 
159 } // end of namespace llvm
160 
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:70
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
Replaces the immediate operand of a 16-bit Rd, K instruction with the lower 8 bits of a 16-bit progra...
Definition: AVRFixupKinds.h:80
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated 16-bi...
Definition: AVRFixupKinds.h:97
block Block Frequency true
MCSymbolRefExpr::VariantKind getAccessVariant() const
Definition: MCValue.cpp:47
Replaces the immediate operand of a 16-bit Rd, K instruction with the lower 8 bits of a negated 16-bi...
Definition: AVRFixupKinds.h:67
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:76
Replaces the immediate operand of a 16-bit Rd, K instruction with the lower 8 bits of a 16-bit value ...
Definition: AVRFixupKinds.h:54
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:42
Context object for machine code objects.
Definition: MCContext.h:63
A 7-bit PC-relative fixup for the family of conditional branches which take 7-bit targets (BRNE...
Definition: AVRFixupKinds.h:33
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a negated negat...
Definition: AVRFixupKinds.h:73
A 5-bit port address.
A 16-bit address.
Definition: AVRFixupKinds.h:45
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:47
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 16-bit progra...
Definition: AVRFixupKinds.h:84
#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:57
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:93
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 32-bit value ...
Definition: AVRFixupKinds.h:63
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:88
Replaces the immediate operand of a 16-bit Rd, K instruction with the upper 8 bits of a 24-bit value ...
Definition: AVRFixupKinds.h:60
Replaces the 8-bit immediate with another value.
Definition: AVRFixupKinds.h:50
A two-byte fixup.
Definition: MCFixup.h:25
A 32-bit AVR fixup.
Definition: AVRFixupKinds.h:29
MCFixupKind getKind() const
Definition: MCFixup.h:123