1 //===-- AVRELFObjectWriter.cpp - AVR ELF Writer ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/AVRFixupKinds.h"
11 #include "MCTargetDesc/AVRMCTargetDesc.h"
13 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCELFObjectWriter.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCSection.h"
17 #include "llvm/MC/MCValue.h"
18 #include "llvm/Support/ErrorHandling.h"
22 /// Writes AVR machine code into an ELF32 object file.
23 class AVRELFObjectWriter : public MCELFObjectTargetWriter {
25 AVRELFObjectWriter(uint8_t OSABI);
27 virtual ~AVRELFObjectWriter() {}
29 unsigned getRelocType(MCContext &Ctx,
30 const MCValue &Target,
32 bool IsPCRel) const override;
35 AVRELFObjectWriter::AVRELFObjectWriter(uint8_t OSABI)
36 : MCELFObjectTargetWriter(false, OSABI, ELF::EM_AVR, true, false) {}
38 unsigned AVRELFObjectWriter::getRelocType(MCContext &Ctx,
39 const MCValue &Target,
42 switch ((unsigned) Fixup.getKind()) {
45 llvm_unreachable("unsupported relocation type");
47 return ELF::R_AVR_16_PM;
50 case AVR::fixup_7_pcrel:
51 return ELF::R_AVR_7_PCREL;
52 case AVR::fixup_13_pcrel:
53 return ELF::R_AVR_13_PCREL;
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;
64 case AVR::fixup_lo8_ldi_neg:
65 return ELF::R_AVR_LO8_LDI_NEG;
66 case AVR::fixup_hi8_ldi_neg:
67 return ELF::R_AVR_HI8_LDI_NEG;
68 case AVR::fixup_hh8_ldi_neg:
69 return ELF::R_AVR_HH8_LDI_NEG;
70 case AVR::fixup_lo8_ldi_pm:
71 return ELF::R_AVR_LO8_LDI_PM;
72 case AVR::fixup_hi8_ldi_pm:
73 return ELF::R_AVR_HI8_LDI_PM;
74 case AVR::fixup_hh8_ldi_pm:
75 return ELF::R_AVR_HH8_LDI_PM;
76 case AVR::fixup_lo8_ldi_pm_neg:
77 return ELF::R_AVR_LO8_LDI_PM_NEG;
78 case AVR::fixup_hi8_ldi_pm_neg:
79 return ELF::R_AVR_HI8_LDI_PM_NEG;
80 case AVR::fixup_hh8_ldi_pm_neg:
81 return ELF::R_AVR_HH8_LDI_PM_NEG;
83 return ELF::R_AVR_CALL;
85 return ELF::R_AVR_LDI;
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;
92 case AVR::fixup_ms8_ldi_neg:
93 return ELF::R_AVR_MS8_LDI_NEG;
94 case AVR::fixup_lo8_ldi_gs:
95 return ELF::R_AVR_LO8_LDI_GS;
96 case AVR::fixup_hi8_ldi_gs:
97 return ELF::R_AVR_HI8_LDI_GS;
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;
110 case AVR::fixup_lds_sts_16:
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;
117 llvm_unreachable("invalid fixup kind!");
121 MCObjectWriter *createAVRELFObjectWriter(raw_pwrite_stream &OS, uint8_t OSABI) {
122 MCELFObjectTargetWriter *MOTW = new AVRELFObjectWriter(OSABI);
123 return createELFObjectWriter(MOTW, OS, true);
126 } // end of namespace llvm