Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- XCoreTargetObjectFile.cpp - XCore object files --------------------===//
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 "XCoreTargetObjectFile.h"
10
#include "XCoreSubtarget.h"
11
#include "llvm/BinaryFormat/ELF.h"
12
#include "llvm/IR/DataLayout.h"
13
#include "llvm/MC/MCContext.h"
14
#include "llvm/MC/MCSectionELF.h"
15
#include "llvm/Target/TargetMachine.h"
16
17
using namespace llvm;
18
19
20
70
void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
21
70
  TargetLoweringObjectFileELF::Initialize(Ctx, TM);
22
70
23
70
  BSSSection = Ctx.getELFSection(".dp.bss", ELF::SHT_NOBITS,
24
70
                                 ELF::SHF_ALLOC | ELF::SHF_WRITE |
25
70
                                     ELF::XCORE_SHF_DP_SECTION);
26
70
  BSSSectionLarge = Ctx.getELFSection(".dp.bss.large", ELF::SHT_NOBITS,
27
70
                                      ELF::SHF_ALLOC | ELF::SHF_WRITE |
28
70
                                          ELF::XCORE_SHF_DP_SECTION);
29
70
  DataSection = Ctx.getELFSection(".dp.data", ELF::SHT_PROGBITS,
30
70
                                  ELF::SHF_ALLOC | ELF::SHF_WRITE |
31
70
                                      ELF::XCORE_SHF_DP_SECTION);
32
70
  DataSectionLarge = Ctx.getELFSection(".dp.data.large", ELF::SHT_PROGBITS,
33
70
                                       ELF::SHF_ALLOC | ELF::SHF_WRITE |
34
70
                                           ELF::XCORE_SHF_DP_SECTION);
35
70
  DataRelROSection = Ctx.getELFSection(".dp.rodata", ELF::SHT_PROGBITS,
36
70
                                       ELF::SHF_ALLOC | ELF::SHF_WRITE |
37
70
                                           ELF::XCORE_SHF_DP_SECTION);
38
70
  DataRelROSectionLarge = Ctx.getELFSection(
39
70
      ".dp.rodata.large", ELF::SHT_PROGBITS,
40
70
      ELF::SHF_ALLOC | ELF::SHF_WRITE | ELF::XCORE_SHF_DP_SECTION);
41
70
  ReadOnlySection =
42
70
      Ctx.getELFSection(".cp.rodata", ELF::SHT_PROGBITS,
43
70
                        ELF::SHF_ALLOC | ELF::XCORE_SHF_CP_SECTION);
44
70
  ReadOnlySectionLarge =
45
70
      Ctx.getELFSection(".cp.rodata.large", ELF::SHT_PROGBITS,
46
70
                        ELF::SHF_ALLOC | ELF::XCORE_SHF_CP_SECTION);
47
70
  MergeableConst4Section = Ctx.getELFSection(
48
70
      ".cp.rodata.cst4", ELF::SHT_PROGBITS,
49
70
      ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::XCORE_SHF_CP_SECTION, 4, "");
50
70
  MergeableConst8Section = Ctx.getELFSection(
51
70
      ".cp.rodata.cst8", ELF::SHT_PROGBITS,
52
70
      ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::XCORE_SHF_CP_SECTION, 8, "");
53
70
  MergeableConst16Section = Ctx.getELFSection(
54
70
      ".cp.rodata.cst16", ELF::SHT_PROGBITS,
55
70
      ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::XCORE_SHF_CP_SECTION, 16, "");
56
70
  CStringSection =
57
70
      Ctx.getELFSection(".cp.rodata.string", ELF::SHT_PROGBITS,
58
70
                        ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS |
59
70
                            ELF::XCORE_SHF_CP_SECTION);
60
70
  // TextSection       - see MObjectFileInfo.cpp
61
70
  // StaticCtorSection - see MObjectFileInfo.cpp
62
70
  // StaticDtorSection - see MObjectFileInfo.cpp
63
70
 }
64
65
7
static unsigned getXCoreSectionType(SectionKind K) {
66
7
  if (K.isBSS())
67
0
    return ELF::SHT_NOBITS;
68
7
  return ELF::SHT_PROGBITS;
69
7
}
70
71
7
static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel) {
72
7
  unsigned Flags = 0;
73
7
74
7
  if (!K.isMetadata())
75
7
    Flags |= ELF::SHF_ALLOC;
76
7
77
7
  if (K.isText())
78
0
    Flags |= ELF::SHF_EXECINSTR;
79
7
  else if (IsCPRel)
80
4
    Flags |= ELF::XCORE_SHF_CP_SECTION;
81
3
  else
82
3
    Flags |= ELF::XCORE_SHF_DP_SECTION;
83
7
84
7
  if (K.isWriteable())
85
3
    Flags |= ELF::SHF_WRITE;
86
7
87
7
  if (K.isMergeableCString() || K.isMergeableConst4() ||
88
7
      K.isMergeableConst8() || K.isMergeableConst16())
89
0
    Flags |= ELF::SHF_MERGE;
90
7
91
7
  if (K.isMergeableCString())
92
0
    Flags |= ELF::SHF_STRINGS;
93
7
94
7
  return Flags;
95
7
}
96
97
MCSection *XCoreTargetObjectFile::getExplicitSectionGlobal(
98
7
    const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
99
7
  StringRef SectionName = GO->getSection();
100
7
  // Infer section flags from the section name if we can.
101
7
  bool IsCPRel = SectionName.startswith(".cp.");
102
7
  if (IsCPRel && 
!Kind.isReadOnly()4
)
103
0
    report_fatal_error("Using .cp. section for writeable object.");
104
7
  return getContext().getELFSection(SectionName, getXCoreSectionType(Kind),
105
7
                                    getXCoreSectionFlags(Kind, IsCPRel));
106
7
}
107
108
MCSection *XCoreTargetObjectFile::SelectSectionForGlobal(
109
324
    const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
110
324
111
324
  bool UseCPRel = GO->hasLocalLinkage();
112
324
113
324
  if (Kind.isText())                    
return TextSection279
;
114
45
  if (UseCPRel) {
115
13
    if (Kind.isMergeable1ByteCString()) 
return CStringSection0
;
116
13
    if (Kind.isMergeableConst4())       
return MergeableConst4Section0
;
117
13
    if (Kind.isMergeableConst8())       
return MergeableConst8Section0
;
118
13
    if (Kind.isMergeableConst16())      
return MergeableConst16Section0
;
119
45
  }
120
45
  Type *ObjType = GO->getValueType();
121
45
  auto &DL = GO->getParent()->getDataLayout();
122
45
  if (TM.getCodeModel() == CodeModel::Small || 
!ObjType->isSized()6
||
123
45
      
DL.getTypeAllocSize(ObjType) < CodeModelLargeSize6
) {
124
42
    if (Kind.isReadOnly())              
return UseCPRel18
?
ReadOnlySection10
125
18
                                                       : 
DataRelROSection8
;
126
24
    if (Kind.isBSS() || 
Kind.isCommon()9
)
return BSSSection17
;
127
7
    if (Kind.isData())
128
7
      return DataSection;
129
0
    if (Kind.isReadOnlyWithRel())       return DataRelROSection;
130
3
  } else {
131
3
    if (Kind.isReadOnly())              
return UseCPRel2
?
ReadOnlySectionLarge1
132
2
                                                       : 
DataRelROSectionLarge1
;
133
1
    if (Kind.isBSS() || 
Kind.isCommon()0
)return BSSSectionLarge;
134
0
    if (Kind.isData())
135
0
      return DataSectionLarge;
136
0
    if (Kind.isReadOnlyWithRel())       return DataRelROSectionLarge;
137
0
  }
138
0
139
0
  assert((Kind.isThreadLocal() || Kind.isCommon()) && "Unknown section kind");
140
0
  report_fatal_error("Target does not support TLS or Common sections");
141
0
}
142
143
MCSection *XCoreTargetObjectFile::getSectionForConstant(const DataLayout &DL,
144
                                                        SectionKind Kind,
145
                                                        const Constant *C,
146
28
                                                        unsigned &Align) const {
147
28
  if (Kind.isMergeableConst4())           
return MergeableConst4Section20
;
148
8
  if (Kind.isMergeableConst8())           
return MergeableConst8Section0
;
149
8
  if (Kind.isMergeableConst16())          
return MergeableConst16Section0
;
150
8
  assert((Kind.isReadOnly() || Kind.isReadOnlyWithRel()) &&
151
8
         "Unknown section kind");
152
8
  // We assume the size of the object is never greater than CodeModelLargeSize.
153
8
  // To handle CodeModelLargeSize changes to AsmPrinter would be required.
154
8
  return ReadOnlySection;
155
8
}