Line data Source code
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 : #include "llvm/MC/SectionKind.h"
20 : #include <cassert>
21 :
22 : namespace llvm {
23 :
24 : class MCSymbol;
25 :
26 : /// This represents a section on Windows
27 50223 : class MCSectionCOFF final : public MCSection {
28 : // The memory for this string is stored in the same MCContext as *this.
29 : StringRef SectionName;
30 :
31 : // FIXME: The following fields should not be mutable, but are for now so the
32 : // asm parser can honor the .linkonce directive.
33 :
34 : /// This is the Characteristics field of a section, drawn from the enums
35 : /// below.
36 : mutable unsigned Characteristics;
37 :
38 : /// The unique IDs used with the .pdata and .xdata sections created internally
39 : /// by the assembler. This ID is used to ensure that for every .text section,
40 : /// there is exactly one .pdata and one .xdata section, which is required by
41 : /// the Microsoft incremental linker. This data is mutable because this ID is
42 : /// not notionally part of the section.
43 : mutable unsigned WinCFISectionID = ~0U;
44 :
45 : /// The COMDAT symbol of this section. Only valid if this is a COMDAT section.
46 : /// Two COMDAT sections are merged if they have the same COMDAT symbol.
47 : MCSymbol *COMDATSymbol;
48 :
49 : /// This is the Selection field for the section symbol, if it is a COMDAT
50 : /// section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0
51 : mutable int Selection;
52 :
53 : private:
54 : friend class MCContext;
55 : MCSectionCOFF(StringRef Section, unsigned Characteristics,
56 : MCSymbol *COMDATSymbol, int Selection, SectionKind K,
57 : MCSymbol *Begin)
58 50555 : : MCSection(SV_COFF, K, Begin), SectionName(Section),
59 : Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
60 50555 : Selection(Selection) {
61 : assert((Characteristics & 0x00F00000) == 0 &&
62 : "alignment must not be set upon section creation");
63 : }
64 :
65 : public:
66 : ~MCSectionCOFF();
67 :
68 : /// Decides whether a '.section' directive should be printed before the
69 : /// section name
70 : bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
71 :
72 0 : StringRef getSectionName() const { return SectionName; }
73 0 : unsigned getCharacteristics() const { return Characteristics; }
74 0 : MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
75 0 : int getSelection() const { return Selection; }
76 :
77 : void setSelection(int Selection) const;
78 :
79 : void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
80 : raw_ostream &OS,
81 : const MCExpr *Subsection) const override;
82 : bool UseCodeAlign() const override;
83 : bool isVirtualSection() const override;
84 :
85 0 : unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
86 116 : if (WinCFISectionID == ~0U)
87 42 : WinCFISectionID = (*NextID)++;
88 116 : return WinCFISectionID;
89 : }
90 :
91 : static bool isImplicitlyDiscardable(StringRef Name) {
92 : return Name.startswith(".debug");
93 : }
94 :
95 403 : static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
96 : };
97 :
98 : } // end namespace llvm
99 :
100 : #endif // LLVM_MC_MCSECTIONCOFF_H
|