LLVM  14.0.0git
MCSectionCOFF.h
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 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_MC_MCSECTIONCOFF_H
14 #define LLVM_MC_MCSECTIONCOFF_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/MC/MCSection.h"
18 #include "llvm/MC/SectionKind.h"
19 #include <cassert>
20 
21 namespace llvm {
22 
23 class MCSymbol;
24 
25 /// This represents a section on Windows
26 class MCSectionCOFF final : public MCSection {
27  // FIXME: The following fields should not be mutable, but are for now so the
28  // asm parser can honor the .linkonce directive.
29 
30  /// This is the Characteristics field of a section, drawn from the enums
31  /// below.
32  mutable unsigned Characteristics;
33 
34  /// The unique IDs used with the .pdata and .xdata sections created internally
35  /// by the assembler. This ID is used to ensure that for every .text section,
36  /// there is exactly one .pdata and one .xdata section, which is required by
37  /// the Microsoft incremental linker. This data is mutable because this ID is
38  /// not notionally part of the section.
39  mutable unsigned WinCFISectionID = ~0U;
40 
41  /// The COMDAT symbol of this section. Only valid if this is a COMDAT section.
42  /// Two COMDAT sections are merged if they have the same COMDAT symbol.
43  MCSymbol *COMDATSymbol;
44 
45  /// This is the Selection field for the section symbol, if it is a COMDAT
46  /// section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0
47  mutable int Selection;
48 
49 private:
50  friend class MCContext;
51  // The storage of Name is owned by MCContext's COFFUniquingMap.
53  MCSymbol *COMDATSymbol, int Selection, SectionKind K,
54  MCSymbol *Begin)
56  COMDATSymbol(COMDATSymbol), Selection(Selection) {
57  assert((Characteristics & 0x00F00000) == 0 &&
58  "alignment must not be set upon section creation");
59  }
60 
61 public:
62  /// Decides whether a '.section' directive should be printed before the
63  /// section name
64  bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
65 
66  unsigned getCharacteristics() const { return Characteristics; }
67  MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
68  int getSelection() const { return Selection; }
69 
70  void setSelection(int Selection) const;
71 
72  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
73  raw_ostream &OS,
74  const MCExpr *Subsection) const override;
75  bool UseCodeAlign() const override;
76  bool isVirtualSection() const override;
77  StringRef getVirtualSectionKind() const override;
78 
79  unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
80  if (WinCFISectionID == ~0U)
81  WinCFISectionID = (*NextID)++;
82  return WinCFISectionID;
83  }
84 
86  return Name.startswith(".debug");
87  }
88 
89  static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
90 };
91 
92 } // end namespace llvm
93 
94 #endif // LLVM_MC_MCSECTIONCOFF_H
llvm::MCSection::Name
StringRef Name
Definition: MCSection.h:111
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:286
llvm::MCSectionCOFF::getSelection
int getSelection() const
Definition: MCSectionCOFF.h:68
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSection::SV_COFF
@ SV_COFF
Definition: MCSection.h:44
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCSectionCOFF::classof
static bool classof(const MCSection *S)
Definition: MCSectionCOFF.h:89
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::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
StringRef.h
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::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::MCSectionCOFF::setSelection
void setSelection(int Selection) const
Definition: MCSectionCOFF.cpp:31
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::MCSectionCOFF::getVirtualSectionKind
StringRef getVirtualSectionKind() const override
Definition: MCSectionCOFF.cpp:115
llvm::MCSectionCOFF::getCharacteristics
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:66
llvm::MCSectionCOFF::getCOMDATSymbol
MCSymbol * getCOMDATSymbol() const
Definition: MCSectionCOFF.h:67
llvm::MCSectionCOFF::PrintSwitchToSection
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionCOFF.cpp:37
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCSectionCOFF
This represents a section on Windows.
Definition: MCSectionCOFF.h:26
MCSection.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::MCSectionCOFF::isImplicitlyDiscardable
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:85
SectionKind.h
Selection
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
Definition: AMDGPUISelDAGToDAG.cpp:383
Characteristics
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:326
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
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
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::MCSectionCOFF::getOrAssignWinCFISectionID
unsigned getOrAssignWinCFISectionID(unsigned *NextID) const
Definition: MCSectionCOFF.h:79