Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCSectionCOFF.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===//
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 "llvm/MC/MCSectionCOFF.h"
10
#include "llvm/BinaryFormat/COFF.h"
11
#include "llvm/MC/MCSymbol.h"
12
#include "llvm/Support/raw_ostream.h"
13
#include <cassert>
14
15
using namespace llvm;
16
17
// ShouldOmitSectionDirective - Decides whether a '.section' directive
18
// should be printed before the section name
19
bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
20
2.80k
                                               const MCAsmInfo &MAI) const {
21
2.80k
  if (COMDATSymbol)
22
385
    return false;
23
2.42k
24
2.42k
  // FIXME: Does .section .bss/.data/.text work everywhere??
25
2.42k
  if (Name == ".text" || 
Name == ".data"894
||
Name == ".bss"847
)
26
1.64k
    return true;
27
783
28
783
  return false;
29
783
}
30
31
31
void MCSectionCOFF::setSelection(int Selection) const {
32
31
  assert(Selection != 0 && "invalid COMDAT selection type");
33
31
  this->Selection = Selection;
34
31
  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
35
31
}
36
37
void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
38
                                         raw_ostream &OS,
39
2.80k
                                         const MCExpr *Subsection) const {
40
2.80k
  // standard sections don't require the '.section'
41
2.80k
  if (ShouldOmitSectionDirective(SectionName, MAI)) {
42
1.64k
    OS << '\t' << getSectionName() << '\n';
43
1.64k
    return;
44
1.64k
  }
45
1.16k
46
1.16k
  OS << "\t.section\t" << getSectionName() << ",\"";
47
1.16k
  if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
48
1.03k
    OS << 'd';
49
1.16k
  if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
50
13
    OS << 'b';
51
1.16k
  if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
52
93
    OS << 'x';
53
1.16k
  if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
54
71
    OS << 'w';
55
1.09k
  else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
56
1.06k
    OS << 'r';
57
28
  else
58
28
    OS << 'y';
59
1.16k
  if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
60
28
    OS << 'n';
61
1.16k
  if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
62
1
    OS << 's';
63
1.16k
  if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
64
1.16k
      
!isImplicitlyDiscardable(SectionName)393
)
65
12
    OS << 'D';
66
1.16k
  OS << '"';
67
1.16k
68
1.16k
  if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
69
386
    if (COMDATSymbol)
70
385
      OS << ",";
71
1
    else
72
1
      OS << "\n\t.linkonce\t";
73
386
    switch (Selection) {
74
386
      case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
75
35
        OS << "one_only";
76
35
        break;
77
386
      case COFF::IMAGE_COMDAT_SELECT_ANY:
78
276
        OS << "discard";
79
276
        break;
80
386
      case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
81
2
        OS << "same_size";
82
2
        break;
83
386
      case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
84
1
        OS << "same_contents";
85
1
        break;
86
386
      case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:
87
55
        OS << "associative";
88
55
        break;
89
386
      case COFF::IMAGE_COMDAT_SELECT_LARGEST:
90
17
        OS << "largest";
91
17
        break;
92
386
      case COFF::IMAGE_COMDAT_SELECT_NEWEST:
93
0
        OS << "newest";
94
0
        break;
95
386
      default:
96
0
        assert(false && "unsupported COFF selection type");
97
0
        break;
98
386
    }
99
386
    if (COMDATSymbol) {
100
385
      OS << ",";
101
385
      COMDATSymbol->print(OS, &MAI);
102
385
    }
103
386
  }
104
1.16k
  OS << '\n';
105
1.16k
}
106
107
20.0k
bool MCSectionCOFF::UseCodeAlign() const {
108
20.0k
  return getKind().isText();
109
20.0k
}
110
111
9.30k
bool MCSectionCOFF::isVirtualSection() const {
112
9.30k
  return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
113
9.30k
}