Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:14

0001 //===- MCSectionCOFF.h - COFF Machine Code Sections -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the MCSectionCOFF class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCSECTIONCOFF_H
0014 #define LLVM_MC_MCSECTIONCOFF_H
0015 
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/BinaryFormat/COFF.h"
0018 #include "llvm/MC/MCSection.h"
0019 #include "llvm/MC/SectionKind.h"
0020 #include <cassert>
0021 
0022 namespace llvm {
0023 
0024 class MCSymbol;
0025 
0026 /// This represents a section on Windows
0027 class MCSectionCOFF final : public MCSection {
0028   // FIXME: The following fields should not be mutable, but are for now so the
0029   // asm parser can honor the .linkonce directive.
0030 
0031   /// This is the Characteristics field of a section, drawn from the enums
0032   /// below.
0033   mutable unsigned Characteristics;
0034 
0035   /// The unique IDs used with the .pdata and .xdata sections created internally
0036   /// by the assembler. This ID is used to ensure that for every .text section,
0037   /// there is exactly one .pdata and one .xdata section, which is required by
0038   /// the Microsoft incremental linker. This data is mutable because this ID is
0039   /// not notionally part of the section.
0040   mutable unsigned WinCFISectionID = ~0U;
0041 
0042   /// The COMDAT symbol of this section. Only valid if this is a COMDAT section.
0043   /// Two COMDAT sections are merged if they have the same COMDAT symbol.
0044   MCSymbol *COMDATSymbol;
0045 
0046   /// This is the Selection field for the section symbol, if it is a COMDAT
0047   /// section (Characteristics & IMAGE_SCN_LNK_COMDAT) != 0
0048   mutable int Selection;
0049 
0050 private:
0051   friend class MCContext;
0052   // The storage of Name is owned by MCContext's COFFUniquingMap.
0053   MCSectionCOFF(StringRef Name, unsigned Characteristics,
0054                 MCSymbol *COMDATSymbol, int Selection, MCSymbol *Begin)
0055       : MCSection(SV_COFF, Name, Characteristics & COFF::IMAGE_SCN_CNT_CODE,
0056                   Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA,
0057                   Begin),
0058         Characteristics(Characteristics), COMDATSymbol(COMDATSymbol),
0059         Selection(Selection) {
0060     assert((Characteristics & 0x00F00000) == 0 &&
0061            "alignment must not be set upon section creation");
0062   }
0063 
0064 public:
0065   /// Decides whether a '.section' directive should be printed before the
0066   /// section name
0067   bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
0068 
0069   unsigned getCharacteristics() const { return Characteristics; }
0070   MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; }
0071   int getSelection() const { return Selection; }
0072 
0073   void setSelection(int Selection) const;
0074 
0075   void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
0076                             raw_ostream &OS,
0077                             uint32_t Subsection) const override;
0078   bool useCodeAlign() const override;
0079   StringRef getVirtualSectionKind() const override;
0080 
0081   unsigned getOrAssignWinCFISectionID(unsigned *NextID) const {
0082     if (WinCFISectionID == ~0U)
0083       WinCFISectionID = (*NextID)++;
0084     return WinCFISectionID;
0085   }
0086 
0087   static bool isImplicitlyDiscardable(StringRef Name) {
0088     return Name.starts_with(".debug");
0089   }
0090 
0091   static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
0092 };
0093 
0094 } // end namespace llvm
0095 
0096 #endif // LLVM_MC_MCSECTIONCOFF_H