LLVM 22.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"
18#include "llvm/MC/MCSection.h"
19#include "llvm/MC/SectionKind.h"
20#include <cassert>
21
22namespace llvm {
23
24class MCSymbol;
25
26/// This represents a section on Windows
27class MCSectionCOFF final : public MCSection {
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 unsigned UniqueID;
51
52private:
53 friend class MCContext;
54 friend class MCAsmInfoCOFF;
55 // The storage of Name is owned by MCContext's COFFUniquingMap.
57 MCSymbol *COMDATSymbol, int Selection, unsigned UniqueID,
58 MCSymbol *Begin)
59 : MCSection(Name, Characteristics & COFF::IMAGE_SCN_CNT_CODE,
60 Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA,
61 Begin),
62 Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
63 Selection(Selection), UniqueID(UniqueID) {
64 assert((Characteristics & 0x00F00000) == 0 &&
65 "alignment must not be set upon section creation");
66 }
67
68public:
69 /// Decides whether a '.section' directive should be printed before the
70 /// section name
72
73 unsigned getCharacteristics() const { return Characteristics; }
74 MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
75 int getSelection() const { return Selection; }
76
77 void setSelection(int Selection) const;
78
79 bool isUnique() const { return UniqueID != NonUniqueID; }
80 unsigned getUniqueID() const { return UniqueID; }
81
82 unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
83 if (WinCFISectionID == ~0U)
84 WinCFISectionID = (*NextID)++;
85 return WinCFISectionID;
86 }
87
89 return Name.starts_with(".debug");
90 }
91};
92
93} // end namespace llvm
94
95#endif // LLVM_MC_MCSECTIONCOFF_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:350
Context object for machine code objects.
Definition: MCContext.h:83
This represents a section on Windows.
Definition: MCSectionCOFF.h:27
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:88
MCSymbol * getCOMDATSymbol() const
Definition: MCSectionCOFF.h:74
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:73
bool shouldOmitSectionDirective(StringRef Name) const
Decides whether a '.section' directive should be printed before the section name.
unsigned getOrAssignWinCFISectionID(unsigned *NextID) const
Definition: MCSectionCOFF.h:82
unsigned getUniqueID() const
Definition: MCSectionCOFF.h:80
bool isUnique() const
Definition: MCSectionCOFF.h:79
int getSelection() const
Definition: MCSectionCOFF.h:75
void setSelection(int Selection) const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
static constexpr unsigned NonUniqueID
Definition: MCSection.h:501
StringRef Name
Definition: MCSection.h:557
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:269
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18