LLVM  9.0.0svn
Go to the documentation of this file.
1 //===- MCSectionCOFF.h - COFF Machine Code Sections -------------*- C++ -*-===//
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 //
9 // This file declares the MCSectionCOFF class.
10 //
11 //===----------------------------------------------------------------------===//
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/MC/MCSection.h"
18 #include "llvm/MC/SectionKind.h"
19 #include <cassert>
21 namespace llvm {
23 class MCSymbol;
25 /// This represents a section on Windows
26 class MCSectionCOFF final : public MCSection {
27  // The memory for this string is stored in the same MCContext as *this.
30  // FIXME: The following fields should not be mutable, but are for now so the
31  // asm parser can honor the .linkonce directive.
33  /// This is the Characteristics field of a section, drawn from the enums
34  /// below.
35  mutable unsigned Characteristics;
37  /// The unique IDs used with the .pdata and .xdata sections created internally
38  /// by the assembler. This ID is used to ensure that for every .text section,
39  /// there is exactly one .pdata and one .xdata section, which is required by
40  /// the Microsoft incremental linker. This data is mutable because this ID is
41  /// not notionally part of the section.
42  mutable unsigned WinCFISectionID = ~0U;
44  /// The COMDAT symbol of this section. Only valid if this is a COMDAT section.
45  /// Two COMDAT sections are merged if they have the same COMDAT symbol.
46  MCSymbol *COMDATSymbol;
48  /// This is the Selection field for the section symbol, if it is a COMDAT
49  /// section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0
50  mutable int Selection;
52 private:
53  friend class MCContext;
54  MCSectionCOFF(StringRef Section, unsigned Characteristics,
55  MCSymbol *COMDATSymbol, int Selection, SectionKind K,
56  MCSymbol *Begin)
57  : MCSection(SV_COFF, K, Begin), SectionName(Section),
58  Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
59  Selection(Selection) {
60  assert((Characteristics & 0x00F00000) == 0 &&
61  "alignment must not be set upon section creation");
62  }
64 public:
67  /// Decides whether a '.section' directive should be printed before the
68  /// section name
69  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
71  StringRef getSectionName() const { return SectionName; }
72  unsigned getCharacteristics() const { return Characteristics; }
73  MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
74  int getSelection() const { return Selection; }
76  void setSelection(int Selection) const;
78  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
79  raw_ostream &OS,
80  const MCExpr *Subsection) const override;
81  bool UseCodeAlign() const override;
82  bool isVirtualSection() const override;
84  unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
85  if (WinCFISectionID == ~0U)
86  WinCFISectionID = (*NextID)++;
87  return WinCFISectionID;
88  }
91  return Name.startswith(".debug");
92  }
94  static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
95 };
97 } // end namespace llvm
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
void setSelection(int Selection) const
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
amdgpu Simplify well known AMD library false Value Value const Twine & Name
unsigned getOrAssignWinCFISectionID(unsigned *NextID) const
Definition: MCSectionCOFF.h:84
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.
Context object for machine code objects.
Definition: MCContext.h:62
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:266
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:72
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:55
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
SectionVariant getVariant() const
Definition: MCSection.h:107
StringRef getSectionName() const
Definition: MCSectionCOFF.h:71
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
MCSymbol * getCOMDATSymbol() const
Definition: MCSectionCOFF.h:73
int getSelection() const
Definition: MCSectionCOFF.h:74
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
static bool classof(const MCSection *S)
Definition: MCSectionCOFF.h:94
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:322
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:90
const char SectionName[]
Definition: AMDGPUPTNote.h:23
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