LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/MC/MCAsmInfo.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCSymbol.h"
15 using namespace llvm;
16 
17 MCSectionCOFF::~MCSectionCOFF() {} // anchor.
18 
19 // ShouldOmitSectionDirective - Decides whether a '.section' directive
20 // should be printed before the section name
22  const MCAsmInfo &MAI) const {
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,
32  const MCSectionCOFF *Assoc) const {
33  assert(Selection != 0 && "invalid COMDAT selection type");
34  assert((Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) ==
35  (Assoc != 0) &&
36  "associative COMDAT section must have an associated section");
37  this->Selection = Selection;
38  this->Assoc = Assoc;
39  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
40 }
41 
43  raw_ostream &OS,
44  const MCExpr *Subsection) const {
45 
46  // standard sections don't require the '.section'
47  if (ShouldOmitSectionDirective(SectionName, MAI)) {
48  OS << '\t' << getSectionName() << '\n';
49  return;
50  }
51 
52  OS << "\t.section\t" << getSectionName() << ",\"";
53  if (getKind().isText())
54  OS << 'x';
55  if (getKind().isWriteable())
56  OS << 'w';
57  else
58  OS << 'r';
59  if (getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE)
60  OS << 'n';
61  OS << "\"\n";
62 
63  if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
64  switch (Selection) {
66  OS << "\t.linkonce one_only\n";
67  break;
69  OS << "\t.linkonce discard\n";
70  break;
72  OS << "\t.linkonce same_size\n";
73  break;
75  OS << "\t.linkonce same_contents\n";
76  break;
78  OS << "\t.linkonce associative " << Assoc->getSectionName() << "\n";
79  break;
81  OS << "\t.linkonce largest\n";
82  break;
84  OS << "\t.linkonce newest\n";
85  break;
86  default:
87  assert (0 && "unsupported COFF selection type");
88  break;
89  }
90  }
91 }
92 
94  return getKind().isText();
95 }
96 
98  return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
99 }
MCSectionCOFF - This represents a section on Windows.
Definition: MCSectionCOFF.h:24
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
virtual bool isVirtualSection() const
bool isText() const
Definition: SectionKind.h:138
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:70
SectionKind getKind() const
Definition: MCSection.h:47
StringRef getSectionName() const
Definition: MCSectionCOFF.h:63
void setSelection(int Selection, const MCSectionCOFF *Assoc=0) const
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const
virtual bool UseCodeAlign() const