Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/MSP430/MCTargetDesc/MSP430ELFObjectWriter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- MSP430ELFObjectWriter.cpp - MSP430 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/MSP430FixupKinds.h"
10
#include "MCTargetDesc/MSP430MCTargetDesc.h"
11
12
#include "MCTargetDesc/MSP430MCTargetDesc.h"
13
#include "llvm/MC/MCELFObjectWriter.h"
14
#include "llvm/MC/MCFixup.h"
15
#include "llvm/MC/MCObjectWriter.h"
16
#include "llvm/MC/MCValue.h"
17
#include "llvm/Support/ErrorHandling.h"
18
19
using namespace llvm;
20
21
namespace {
22
class MSP430ELFObjectWriter : public MCELFObjectTargetWriter {
23
public:
24
  MSP430ELFObjectWriter(uint8_t OSABI)
25
    : MCELFObjectTargetWriter(false, OSABI, ELF::EM_MSP430,
26
86
                              /*HasRelocationAddend*/ true) {}
27
28
86
  ~MSP430ELFObjectWriter() override {}
29
30
protected:
31
  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
32
13
                        const MCFixup &Fixup, bool IsPCRel) const override {
33
13
    // Translate fixup kind to ELF relocation type.
34
13
    switch ((unsigned)Fixup.getKind()) {
35
13
    
case FK_Data_1: return ELF::R_MSP430_81
;
36
13
    
case FK_Data_2: return ELF::R_MSP430_16_BYTE2
;
37
13
    
case FK_Data_4: return ELF::R_MSP430_321
;
38
13
    
case MSP430::fixup_32: return ELF::R_MSP430_320
;
39
13
    
case MSP430::fixup_10_pcrel: return ELF::R_MSP430_10_PCREL2
;
40
13
    
case MSP430::fixup_16: return ELF::R_MSP430_160
;
41
13
    
case MSP430::fixup_16_pcrel: return ELF::R_MSP430_16_PCREL0
;
42
13
    
case MSP430::fixup_16_byte: return ELF::R_MSP430_16_BYTE3
;
43
13
    
case MSP430::fixup_16_pcrel_byte: return ELF::R_MSP430_16_PCREL_BYTE4
;
44
13
    
case MSP430::fixup_2x_pcrel: return ELF::R_MSP430_2X_PCREL0
;
45
13
    
case MSP430::fixup_rl_pcrel: return ELF::R_MSP430_RL_PCREL0
;
46
13
    
case MSP430::fixup_8: return ELF::R_MSP430_80
;
47
13
    
case MSP430::fixup_sym_diff: return ELF::R_MSP430_SYM_DIFF0
;
48
13
    default:
49
0
      llvm_unreachable("Invalid fixup kind");
50
13
    }
51
13
  }
52
};
53
} // end of anonymous namespace
54
55
std::unique_ptr<MCObjectTargetWriter>
56
86
llvm::createMSP430ELFObjectWriter(uint8_t OSABI) {
57
86
  return llvm::make_unique<MSP430ELFObjectWriter>(OSABI);
58
86
}