/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/MC/MCSectionCOFF.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | |
10 | | #include "llvm/MC/MCSectionCOFF.h" |
11 | | #include "llvm/BinaryFormat/COFF.h" |
12 | | #include "llvm/MC/MCSymbol.h" |
13 | | #include "llvm/Support/raw_ostream.h" |
14 | | #include <cassert> |
15 | | |
16 | | using namespace llvm; |
17 | | |
18 | 33.8k | MCSectionCOFF::~MCSectionCOFF() = default; // anchor. |
19 | | |
20 | | // ShouldOmitSectionDirective - Decides whether a '.section' directive |
21 | | // should be printed before the section name |
22 | | bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name, |
23 | 1.55k | const MCAsmInfo &MAI) const { |
24 | 1.55k | if (COMDATSymbol) |
25 | 129 | return false; |
26 | 1.42k | |
27 | 1.42k | // FIXME: Does .section .bss/.data/.text work everywhere?? |
28 | 1.42k | if (1.42k Name == ".text" || 1.42k Name == ".data"495 || Name == ".bss"464 ) |
29 | 996 | return true; |
30 | 431 | |
31 | 431 | return false; |
32 | 431 | } |
33 | | |
34 | 19 | void MCSectionCOFF::setSelection(int Selection) const { |
35 | 19 | assert(Selection != 0 && "invalid COMDAT selection type"); |
36 | 19 | this->Selection = Selection; |
37 | 19 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
38 | 19 | } |
39 | | |
40 | | void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, |
41 | | raw_ostream &OS, |
42 | 1.55k | const MCExpr *Subsection) const { |
43 | 1.55k | // standard sections don't require the '.section' |
44 | 1.55k | if (ShouldOmitSectionDirective(SectionName, MAI)1.55k ) { |
45 | 996 | OS << '\t' << getSectionName() << '\n'; |
46 | 996 | return; |
47 | 996 | } |
48 | 560 | |
49 | 560 | OS << "\t.section\t" << getSectionName() << ",\""; |
50 | 560 | if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA) |
51 | 503 | OS << 'd'; |
52 | 560 | if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) |
53 | 13 | OS << 'b'; |
54 | 560 | if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE) |
55 | 20 | OS << 'x'; |
56 | 560 | if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE) |
57 | 46 | OS << 'w'; |
58 | 514 | else if (514 getCharacteristics() & COFF::IMAGE_SCN_MEM_READ514 ) |
59 | 491 | OS << 'r'; |
60 | 514 | else |
61 | 23 | OS << 'y'; |
62 | 560 | if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE) |
63 | 23 | OS << 'n'; |
64 | 560 | if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED) |
65 | 1 | OS << 's'; |
66 | 560 | if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) && |
67 | 210 | !isImplicitlyDiscardable(SectionName)) |
68 | 12 | OS << 'D'; |
69 | 560 | OS << '"'; |
70 | 560 | |
71 | 560 | if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT560 ) { |
72 | 129 | OS << ","; |
73 | 129 | switch (Selection) { |
74 | 25 | case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES: |
75 | 25 | OS << "one_only,"; |
76 | 25 | break; |
77 | 80 | case COFF::IMAGE_COMDAT_SELECT_ANY: |
78 | 80 | OS << "discard,"; |
79 | 80 | break; |
80 | 2 | case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE: |
81 | 2 | OS << "same_size,"; |
82 | 2 | break; |
83 | 1 | case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH: |
84 | 1 | OS << "same_contents,"; |
85 | 1 | break; |
86 | 19 | case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE: |
87 | 19 | OS << "associative,"; |
88 | 19 | break; |
89 | 2 | case COFF::IMAGE_COMDAT_SELECT_LARGEST: |
90 | 2 | OS << "largest,"; |
91 | 2 | break; |
92 | 0 | case COFF::IMAGE_COMDAT_SELECT_NEWEST: |
93 | 0 | OS << "newest,"; |
94 | 0 | break; |
95 | 0 | default: |
96 | 0 | assert(false && "unsupported COFF selection type"); |
97 | 0 | break; |
98 | 129 | } |
99 | 129 | assert(COMDATSymbol); |
100 | 129 | COMDATSymbol->print(OS, &MAI); |
101 | 129 | } |
102 | 560 | OS << '\n'; |
103 | 560 | } |
104 | | |
105 | 159 | bool MCSectionCOFF::UseCodeAlign() const { |
106 | 159 | return getKind().isText(); |
107 | 159 | } |
108 | | |
109 | 4.30k | bool MCSectionCOFF::isVirtualSection() const { |
110 | 4.30k | return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; |
111 | 4.30k | } |