LLVM  4.0.0
MCSectionCOFF.h
Go to the documentation of this file.
1 //===- MCSectionCOFF.h - COFF Machine Code Sections -------------*- C++ -*-===//
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 // This file declares the MCSectionCOFF class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MC_MCSECTIONCOFF_H
15 #define LLVM_MC_MCSECTIONCOFF_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/MC/MCSection.h"
19 
20 namespace llvm {
21 class MCSymbol;
22 
23 /// This represents a section on Windows
24 class MCSectionCOFF final : public MCSection {
25  // The memory for this string is stored in the same MCContext as *this.
26  StringRef SectionName;
27 
28  // FIXME: The following fields should not be mutable, but are for now so the
29  // asm parser can honor the .linkonce directive.
30 
31  /// This is the Characteristics field of a section, drawn from the enums
32  /// below.
33  mutable unsigned Characteristics;
34 
35  /// The unique IDs used with the .pdata and .xdata sections created internally
36  /// by the assembler. This ID is used to ensure that for every .text section,
37  /// there is exactly one .pdata and one .xdata section, which is required by
38  /// the Microsoft incremental linker. This data is mutable because this ID is
39  /// not notionally part of the section.
40  mutable unsigned WinCFISectionID = ~0U;
41 
42  /// The COMDAT symbol of this section. Only valid if this is a COMDAT section.
43  /// Two COMDAT sections are merged if they have the same COMDAT symbol.
44  MCSymbol *COMDATSymbol;
45 
46  /// This is the Selection field for the section symbol, if it is a COMDAT
47  /// section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0
48  mutable int Selection;
49 
50 private:
51  friend class MCContext;
53  MCSymbol *COMDATSymbol, int Selection, SectionKind K,
54  MCSymbol *Begin)
55  : MCSection(SV_COFF, K, Begin), SectionName(Section),
56  Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
57  Selection(Selection) {
58  assert((Characteristics & 0x00F00000) == 0 &&
59  "alignment must not be set upon section creation");
60  }
61 
62 public:
64 
65  /// Decides whether a '.section' directive should be printed before the
66  /// section name
67  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
68 
69  StringRef getSectionName() const { return SectionName; }
70  unsigned getCharacteristics() const { return Characteristics; }
71  MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
72  int getSelection() const { return Selection; }
73 
74  void setSelection(int Selection) const;
75 
76  void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
77  const MCExpr *Subsection) const override;
78  bool UseCodeAlign() const override;
79  bool isVirtualSection() const override;
80 
81  unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
82  if (WinCFISectionID == ~0U)
83  WinCFISectionID = (*NextID)++;
84  return WinCFISectionID;
85  }
86 
88  return Name.startswith(".debug");
89  }
90 
91  static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
92 };
93 
94 } // end namespace llvm
95 
96 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
SectionVariant getVariant() const
Definition: MCSection.h:104
unsigned getOrAssignWinCFISectionID(unsigned *NextID) const
Definition: MCSectionCOFF.h:81
void setSelection(int Selection) const
int getSelection() const
Definition: MCSectionCOFF.h:72
This represents a section on Windows.
Definition: MCSectionCOFF.h:24
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a '.section' directive should be printed before the section name. ...
Context object for machine code objects.
Definition: MCContext.h:51
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:264
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:57
void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const override
MCSymbol * getCOMDATSymbol() const
Definition: MCSectionCOFF.h:71
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:70
StringRef getSectionName() const
Definition: MCSectionCOFF.h:69
static bool classof(const MCSection *S)
Definition: MCSectionCOFF.h:91
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:270
const char SectionName[]
Definition: AMDGPUPTNote.h:24
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:87
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47