LLVM  4.0.0
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/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, false) {}
37 
39  const MCValue &Target,
40  const MCFixup &Fixup,
41  bool IsPCRel) const {
42  switch ((unsigned) Fixup.getKind()) {
43  case FK_Data_1:
44  case FK_Data_4:
45  llvm_unreachable("unsupported relocation type");
46  case FK_Data_2:
47  return ELF::R_AVR_16_PM;
48  case AVR::fixup_32:
49  return ELF::R_AVR_32;
50  case AVR::fixup_7_pcrel:
51  return ELF::R_AVR_7_PCREL;
53  return ELF::R_AVR_13_PCREL;
54  case AVR::fixup_16:
55  return ELF::R_AVR_16;
56  case AVR::fixup_16_pm:
57  return ELF::R_AVR_16_PM;
58  case AVR::fixup_lo8_ldi:
59  return ELF::R_AVR_LO8_LDI;
60  case AVR::fixup_hi8_ldi:
61  return ELF::R_AVR_HI8_LDI;
62  case AVR::fixup_hh8_ldi:
63  return ELF::R_AVR_HH8_LDI;
65  return ELF::R_AVR_LO8_LDI_NEG;
67  return ELF::R_AVR_HI8_LDI_NEG;
69  return ELF::R_AVR_HH8_LDI_NEG;
71  return ELF::R_AVR_LO8_LDI_PM;
73  return ELF::R_AVR_HI8_LDI_PM;
75  return ELF::R_AVR_HH8_LDI_PM;
77  return ELF::R_AVR_LO8_LDI_PM_NEG;
79  return ELF::R_AVR_HI8_LDI_PM_NEG;
81  return ELF::R_AVR_HH8_LDI_PM_NEG;
82  case AVR::fixup_call:
83  return ELF::R_AVR_CALL;
84  case AVR::fixup_ldi:
85  return ELF::R_AVR_LDI;
86  case AVR::fixup_6:
87  return ELF::R_AVR_6;
88  case AVR::fixup_6_adiw:
89  return ELF::R_AVR_6_ADIW;
90  case AVR::fixup_ms8_ldi:
91  return ELF::R_AVR_MS8_LDI;
93  return ELF::R_AVR_MS8_LDI_NEG;
95  return ELF::R_AVR_LO8_LDI_GS;
97  return ELF::R_AVR_HI8_LDI_GS;
98  case AVR::fixup_8:
99  return ELF::R_AVR_8;
100  case AVR::fixup_8_lo8:
101  return ELF::R_AVR_8_LO8;
102  case AVR::fixup_8_hi8:
103  return ELF::R_AVR_8_HI8;
104  case AVR::fixup_8_hlo8:
105  return ELF::R_AVR_8_HLO8;
106  case AVR::fixup_sym_diff:
107  return ELF::R_AVR_SYM_DIFF;
108  case AVR::fixup_16_ldst:
109  return ELF::R_AVR_16_LDST;
111  return ELF::R_AVR_LDS_STS_16;
112  case AVR::fixup_port6:
113  return ELF::R_AVR_PORT6;
114  case AVR::fixup_port5:
115  return ELF::R_AVR_PORT5;
116  default:
117  llvm_unreachable("invalid fixup kind!");
118  }
119 }
120 
122  MCELFObjectTargetWriter *MOTW = new AVRELFObjectWriter(OSABI);
123  return createELFObjectWriter(MOTW, OS, true);
124 }
125 
126 } // end of namespace llvm
127 
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 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
Defines the object file and target independent interfaces used by the assembler backend to write nati...
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:66
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:51
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
Function Alias Analysis false
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
MCFixupKind getKind() const
Definition: MCFixup.h:93
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A one-byte fixup.
Definition: MCFixup.h:24
Fixup to calculate the difference between two symbols.
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
MCObjectWriter * createAVRELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI)
Creates an ELF object writer for AVR.
Writes AVR machine code into an ELF32 object file.
Target - Wrapper for Target specific information.
MCObjectWriter * createELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
Construct a new ELF writer instance.
Basic Alias true
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
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
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