1 //===---------- M68kELFObjectWriter.cpp - M68k ELF Writer ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file contains definitions for M68k ELF Writers
12 //===----------------------------------------------------------------------===//
14 #include "MCTargetDesc/M68kFixupKinds.h"
15 #include "MCTargetDesc/M68kMCTargetDesc.h"
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCELFObjectWriter.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCValue.h"
23 #include "llvm/Support/ErrorHandling.h"
28 class M68kELFObjectWriter
: public MCELFObjectTargetWriter
{
30 M68kELFObjectWriter(uint8_t OSABI
);
32 ~M68kELFObjectWriter() override
;
35 unsigned getRelocType(MCContext
&Ctx
, const MCValue
&Target
,
36 const MCFixup
&Fixup
, bool IsPCRel
) const override
;
40 M68kELFObjectWriter::M68kELFObjectWriter(uint8_t OSABI
)
41 : MCELFObjectTargetWriter(false, OSABI
, ELF::EM_68K
, /* RELA */ true) {}
43 M68kELFObjectWriter::~M68kELFObjectWriter() {}
45 enum M68kRelType
{ RT_32
, RT_16
, RT_8
};
48 getType(unsigned Kind
, MCSymbolRefExpr::VariantKind
&Modifier
, bool &IsPCRel
) {
60 llvm_unreachable("Unimplemented");
63 unsigned M68kELFObjectWriter::getRelocType(MCContext
&Ctx
,
64 const MCValue
&Target
,
67 MCSymbolRefExpr::VariantKind Modifier
= Target
.getAccessVariant();
68 unsigned Kind
= Fixup
.getKind();
69 M68kRelType Type
= getType(Kind
, Modifier
, IsPCRel
);
72 llvm_unreachable("Unimplemented");
73 case MCSymbolRefExpr::VK_None
:
76 return IsPCRel
? ELF::R_68K_PC32
: ELF::R_68K_32
;
78 return IsPCRel
? ELF::R_68K_PC16
: ELF::R_68K_16
;
80 return IsPCRel
? ELF::R_68K_PC8
: ELF::R_68K_8
;
82 llvm_unreachable("Unrecognized size");
83 case MCSymbolRefExpr::VK_GOTPCREL
:
86 return ELF::R_68K_GOTPCREL32
;
88 return ELF::R_68K_GOTPCREL16
;
90 return ELF::R_68K_GOTPCREL8
;
92 llvm_unreachable("Unrecognized size");
93 case MCSymbolRefExpr::VK_GOTOFF
:
97 return ELF::R_68K_GOTOFF32
;
99 return ELF::R_68K_GOTOFF16
;
101 return ELF::R_68K_GOTOFF8
;
103 llvm_unreachable("Unrecognized size");
104 case MCSymbolRefExpr::VK_PLT
:
107 return ELF::R_68K_PLT32
;
109 return ELF::R_68K_PLT16
;
111 return ELF::R_68K_PLT8
;
113 llvm_unreachable("Unrecognized size");
117 std::unique_ptr
<MCObjectTargetWriter
>
118 llvm::createM68kELFObjectWriter(uint8_t OSABI
) {
119 return std::make_unique
<M68kELFObjectWriter
>(OSABI
);