Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- MCSectionCOFF.h - COFF Machine Code Sections -------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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 | // The memory for this string is stored in the same MCContext as *this. |
| 28 | StringRef SectionName; |
| 29 | |
| 30 | // FIXME: The following fields should not be mutable, but are for now so the |
| 31 | // asm parser can honor the .linkonce directive. |
| 32 | |
| 33 | /// This is the Characteristics field of a section, drawn from the enums |
| 34 | /// below. |
| 35 | mutable unsigned Characteristics; |
| 36 | |
| 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; |
| 43 | |
| 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; |
| 47 | |
| 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; |
| 51 | |
| 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 | } |
| 63 | |
| 64 | public: |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 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, const Triple &T, |
| 77 | raw_ostream &OS, |
| 78 | const MCExpr *Subsection) const override; |
| 79 | bool UseCodeAlign() const override; |
| 80 | bool isVirtualSection() const override; |
| 81 | |
| 82 | unsigned getOrAssignWinCFISectionID(unsigned *NextID) const { |
| 83 | if (WinCFISectionID == ~0U) |
| 84 | WinCFISectionID = (*NextID)++; |
| 85 | return WinCFISectionID; |
| 86 | } |
| 87 | |
| 88 | static bool isImplicitlyDiscardable(StringRef Name) { |
| 89 | return Name.startswith(".debug"); |
| 90 | } |
| 91 | |
| 92 | static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; } |
| 93 | }; |
| 94 | |
| 95 | } // end namespace llvm |
| 96 | |
| 97 | #endif // LLVM_MC_MCSECTIONCOFF_H |