/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- LanaiELFObjectWriter.cpp - Lanai ELF Writer -----------------------===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
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" |
15 | | |
16 | | using namespace llvm; |
17 | | |
18 | | namespace { |
19 | | |
20 | | class LanaiELFObjectWriter : public MCELFObjectTargetWriter { |
21 | | public: |
22 | | explicit LanaiELFObjectWriter(uint8_t OSABI); |
23 | | |
24 | 27 | ~LanaiELFObjectWriter() override = default; |
25 | | |
26 | | protected: |
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; |
31 | | }; |
32 | | |
33 | | } // end anonymous namespace |
34 | | |
35 | | LanaiELFObjectWriter::LanaiELFObjectWriter(uint8_t OSABI) |
36 | | : MCELFObjectTargetWriter(/*Is64Bit_=*/false, OSABI, ELF::EM_LANAI, |
37 | 27 | /*HasRelocationAddend_=*/true) {} |
38 | | |
39 | | unsigned LanaiELFObjectWriter::getRelocType(MCContext & /*Ctx*/, |
40 | | const MCValue & /*Target*/, |
41 | | const MCFixup &Fixup, |
42 | 0 | bool /*IsPCRel*/) const { |
43 | 0 | unsigned Type; |
44 | 0 | unsigned Kind = static_cast<unsigned>(Fixup.getKind()); |
45 | 0 | switch (Kind) { |
46 | 0 | case Lanai::FIXUP_LANAI_21: |
47 | 0 | Type = ELF::R_LANAI_21; |
48 | 0 | break; |
49 | 0 | case Lanai::FIXUP_LANAI_21_F: |
50 | 0 | Type = ELF::R_LANAI_21_F; |
51 | 0 | break; |
52 | 0 | case Lanai::FIXUP_LANAI_25: |
53 | 0 | Type = ELF::R_LANAI_25; |
54 | 0 | break; |
55 | 0 | case Lanai::FIXUP_LANAI_32: |
56 | 0 | case FK_Data_4: |
57 | 0 | Type = ELF::R_LANAI_32; |
58 | 0 | break; |
59 | 0 | case Lanai::FIXUP_LANAI_HI16: |
60 | 0 | Type = ELF::R_LANAI_HI16; |
61 | 0 | break; |
62 | 0 | case Lanai::FIXUP_LANAI_LO16: |
63 | 0 | Type = ELF::R_LANAI_LO16; |
64 | 0 | break; |
65 | 0 | case Lanai::FIXUP_LANAI_NONE: |
66 | 0 | Type = ELF::R_LANAI_NONE; |
67 | 0 | break; |
68 | 0 |
|
69 | 0 | default: |
70 | 0 | llvm_unreachable("Invalid fixup kind!"); |
71 | 0 | } |
72 | 0 | return Type; |
73 | 0 | } |
74 | | |
75 | | bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCSymbol & /*SD*/, |
76 | | unsigned Type) const { |
77 | | switch (Type) { |
78 | | case ELF::R_LANAI_21: |
79 | | case ELF::R_LANAI_21_F: |
80 | | case ELF::R_LANAI_25: |
81 | | case ELF::R_LANAI_32: |
82 | | case ELF::R_LANAI_HI16: |
83 | | return true; |
84 | | default: |
85 | | return false; |
86 | | } |
87 | | } |
88 | | |
89 | | std::unique_ptr<MCObjectTargetWriter> |
90 | 27 | llvm::createLanaiELFObjectWriter(uint8_t OSABI) { |
91 | 27 | return llvm::make_unique<LanaiELFObjectWriter>(OSABI); |
92 | 27 | } |