LLVM  10.0.0svn
MCSectionCOFF.cpp
Go to the documentation of this file.
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 
10 #include "llvm/BinaryFormat/COFF.h"
11 #include "llvm/MC/MCSymbol.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
20  const MCAsmInfo &MAI) const {
21  if (COMDATSymbol)
22  return false;
23 
24  // FIXME: Does .section .bss/.data/.text work everywhere??
25  if (Name == ".text" || Name == ".data" || Name == ".bss")
26  return true;
27 
28  return false;
29 }
30 
31 void MCSectionCOFF::setSelection(int Selection) const {
32  assert(Selection != 0 && "invalid COMDAT selection type");
33  this->Selection = Selection;
34  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
35 }
36 
38  raw_ostream &OS,
39  const MCExpr *Subsection) const {
40  // standard sections don't require the '.section'
42  OS << '\t' << getSectionName() << '\n';
43  return;
44  }
45 
46  OS << "\t.section\t" << getSectionName() << ",\"";
48  OS << 'd';
50  OS << 'b';
52  OS << 'x';
54  OS << 'w';
56  OS << 'r';
57  else
58  OS << 'y';
60  OS << 'n';
62  OS << 's';
65  OS << 'D';
66  OS << '"';
67 
69  if (COMDATSymbol)
70  OS << ",";
71  else
72  OS << "\n\t.linkonce\t";
73  switch (Selection) {
75  OS << "one_only";
76  break;
78  OS << "discard";
79  break;
81  OS << "same_size";
82  break;
84  OS << "same_contents";
85  break;
87  OS << "associative";
88  break;
90  OS << "largest";
91  break;
93  OS << "newest";
94  break;
95  default:
96  assert(false && "unsupported COFF selection type");
97  break;
98  }
99  if (COMDATSymbol) {
100  OS << ",";
101  COMDATSymbol->print(OS, &MAI);
102  }
103  }
104  OS << '\n';
105 }
106 
108  return getKind().isText();
109 }
110 
113 }
SectionKind getKind() const
Definition: MCSection.h:106
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void setSelection(int Selection) const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a &#39;.section&#39; directive should be printed before the section name. ...
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
bool isText() const
Definition: SectionKind.h:118
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:70
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
StringRef getSectionName() const
Definition: MCSectionCOFF.h:69
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:88
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59