LLVM  8.0.1
MCSectionCOFF.cpp
Go to the documentation of this file.
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"
14 #include <cassert>
15 
16 using namespace llvm;
17 
18 MCSectionCOFF::~MCSectionCOFF() = default; // anchor.
19 
20 // ShouldOmitSectionDirective - Decides whether a '.section' directive
21 // should be printed before the section name
23  const MCAsmInfo &MAI) const {
24  if (COMDATSymbol)
25  return false;
26 
27  // FIXME: Does .section .bss/.data/.text work everywhere??
28  if (Name == ".text" || Name == ".data" || Name == ".bss")
29  return true;
30 
31  return false;
32 }
33 
34 void MCSectionCOFF::setSelection(int Selection) const {
35  assert(Selection != 0 && "invalid COMDAT selection type");
36  this->Selection = Selection;
37  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
38 }
39 
41  raw_ostream &OS,
42  const MCExpr *Subsection) const {
43  // standard sections don't require the '.section'
45  OS << '\t' << getSectionName() << '\n';
46  return;
47  }
48 
49  OS << "\t.section\t" << getSectionName() << ",\"";
51  OS << 'd';
53  OS << 'b';
55  OS << 'x';
57  OS << 'w';
59  OS << 'r';
60  else
61  OS << 'y';
63  OS << 'n';
65  OS << 's';
68  OS << 'D';
69  OS << '"';
70 
72  if (COMDATSymbol)
73  OS << ",";
74  else
75  OS << "\n\t.linkonce\t";
76  switch (Selection) {
78  OS << "one_only";
79  break;
81  OS << "discard";
82  break;
84  OS << "same_size";
85  break;
87  OS << "same_contents";
88  break;
90  OS << "associative";
91  break;
93  OS << "largest";
94  break;
96  OS << "newest";
97  break;
98  default:
99  assert(false && "unsupported COFF selection type");
100  break;
101  }
102  if (COMDATSymbol) {
103  OS << ",";
104  COMDATSymbol->print(OS, &MAI);
105  }
106  }
107  OS << '\n';
108 }
109 
111  return getKind().isText();
112 }
113 
116 }
SectionKind getKind() const
Definition: MCSection.h:106
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void setSelection(int Selection) const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
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:119
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:73
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:72
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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:91
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:60