LLVM  14.0.0git
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 
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'
41  if (ShouldOmitSectionDirective(getName(), MAI)) {
42  OS << '\t' << getName() << '\n';
43  return;
44  }
45 
46  OS << "\t.section\t" << getName() << ",\"";
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 }
114 
116  return "IMAGE_SCN_CNT_UNINITIALIZED_DATA";
117 }
llvm::SectionKind::isText
bool isText() const
Definition: SectionKind.h:121
llvm::COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
Definition: COFF.h:410
llvm::MCSection::Name
StringRef Name
Definition: MCSection.h:111
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
Definition: COFF.h:290
llvm::MCSectionCOFF::UseCodeAlign
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
Definition: MCSectionCOFF.cpp:107
llvm::COFF::IMAGE_COMDAT_SELECT_NODUPLICATES
@ IMAGE_COMDAT_SELECT_NODUPLICATES
Definition: COFF.h:407
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_MEM_DISCARDABLE
Definition: COFF.h:316
MCSectionCOFF.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
COFF.h
llvm::COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
Definition: COFF.h:411
llvm::MCSectionCOFF::setSelection
void setSelection(int Selection) const
Definition: MCSectionCOFF.cpp:31
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_SCN_CNT_INITIALIZED_DATA
Definition: COFF.h:289
llvm::COFF::IMAGE_COMDAT_SELECT_NEWEST
@ IMAGE_COMDAT_SELECT_NEWEST
Definition: COFF.h:413
llvm::COFF::IMAGE_COMDAT_SELECT_SAME_SIZE
@ IMAGE_COMDAT_SELECT_SAME_SIZE
Definition: COFF.h:409
llvm::COFF::IMAGE_SCN_LNK_REMOVE
@ IMAGE_SCN_LNK_REMOVE
Definition: COFF.h:293
llvm::COFF::IMAGE_SCN_MEM_READ
@ IMAGE_SCN_MEM_READ
Definition: COFF.h:321
MCSymbol.h
llvm::MCSectionCOFF::isVirtualSection
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSectionCOFF.cpp:111
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCSymbol::print
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59
llvm::MCSectionCOFF::getVirtualSectionKind
StringRef getVirtualSectionKind() const override
Definition: MCSectionCOFF.cpp:115
llvm::MCSectionCOFF::getCharacteristics
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:66
llvm::MCSectionCOFF::PrintSwitchToSection
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionCOFF.cpp:37
llvm::COFF::IMAGE_SCN_MEM_SHARED
@ IMAGE_SCN_MEM_SHARED
Definition: COFF.h:319
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::COFF::IMAGE_SCN_LNK_COMDAT
@ IMAGE_SCN_LNK_COMDAT
Definition: COFF.h:294
llvm::COFF::IMAGE_COMDAT_SELECT_LARGEST
@ IMAGE_COMDAT_SELECT_LARGEST
Definition: COFF.h:412
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:122
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::MCSectionCOFF::isImplicitlyDiscardable
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:85
Selection
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
Definition: AMDGPUISelDAGToDAG.cpp:383
llvm::MCSection::getKind
SectionKind getKind() const
Definition: MCSection.h:123
llvm::COFF::IMAGE_SCN_MEM_EXECUTE
@ IMAGE_SCN_MEM_EXECUTE
Definition: COFF.h:320
raw_ostream.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::COFF::IMAGE_COMDAT_SELECT_ANY
@ IMAGE_COMDAT_SELECT_ANY
Definition: COFF.h:408
llvm::COFF::IMAGE_SCN_MEM_WRITE
@ IMAGE_SCN_MEM_WRITE
Definition: COFF.h:322
llvm::MCSectionCOFF::ShouldOmitSectionDirective
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a '.section' directive should be printed before the section name.
Definition: MCSectionCOFF.cpp:19