1 //===-- LanaiELFObjectWriter.cpp - Lanai ELF Writer -----------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "MCTargetDesc/LanaiBaseInfo.h"
10 #include "MCTargetDesc/LanaiFixupKinds.h"
11 #include "llvm/BinaryFormat/ELF.h"
12 #include "llvm/MC/MCELFObjectWriter.h"
13 #include "llvm/MC/MCObjectWriter.h"
14 #include "llvm/Support/ErrorHandling.h"
20 class LanaiELFObjectWriter
: public MCELFObjectTargetWriter
{
22 explicit LanaiELFObjectWriter(uint8_t OSABI
);
24 ~LanaiELFObjectWriter() override
= default;
27 unsigned getRelocType(MCContext
&Ctx
, const MCValue
&Target
,
28 const MCFixup
&Fixup
, bool IsPCRel
) const override
;
29 bool needsRelocateWithSymbol(const MCSymbol
&SD
,
30 unsigned Type
) const override
;
33 } // end anonymous namespace
35 LanaiELFObjectWriter::LanaiELFObjectWriter(uint8_t OSABI
)
36 : MCELFObjectTargetWriter(/*Is64Bit_=*/false, OSABI
, ELF::EM_LANAI
,
37 /*HasRelocationAddend_=*/true) {}
39 unsigned LanaiELFObjectWriter::getRelocType(MCContext
& /*Ctx*/,
40 const MCValue
& /*Target*/,
42 bool /*IsPCRel*/) const {
44 unsigned Kind
= static_cast<unsigned>(Fixup
.getKind());
46 case Lanai::FIXUP_LANAI_21
:
47 Type
= ELF::R_LANAI_21
;
49 case Lanai::FIXUP_LANAI_21_F
:
50 Type
= ELF::R_LANAI_21_F
;
52 case Lanai::FIXUP_LANAI_25
:
53 Type
= ELF::R_LANAI_25
;
55 case Lanai::FIXUP_LANAI_32
:
57 Type
= ELF::R_LANAI_32
;
59 case Lanai::FIXUP_LANAI_HI16
:
60 Type
= ELF::R_LANAI_HI16
;
62 case Lanai::FIXUP_LANAI_LO16
:
63 Type
= ELF::R_LANAI_LO16
;
65 case Lanai::FIXUP_LANAI_NONE
:
66 Type
= ELF::R_LANAI_NONE
;
70 llvm_unreachable("Invalid fixup kind!");
75 bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCSymbol
& /*SD*/,
76 unsigned Type
) const {
79 case ELF::R_LANAI_21_F
:
82 case ELF::R_LANAI_HI16
:
89 std::unique_ptr
<MCObjectTargetWriter
>
90 llvm::createLanaiELFObjectWriter(uint8_t OSABI
) {
91 return std::make_unique
<LanaiELFObjectWriter
>(OSABI
);