Home | History | Annotate | Line # | Download | only in MC
      1 //===- MCSectionELF.h - ELF 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 MCSectionELF class.
     10 //
     11 //===----------------------------------------------------------------------===//
     12 
     13 #ifndef LLVM_MC_MCSECTIONELF_H
     14 #define LLVM_MC_MCSECTIONELF_H
     15 
     16 #include "llvm/ADT/PointerIntPair.h"
     17 #include "llvm/ADT/StringRef.h"
     18 #include "llvm/MC/MCSection.h"
     19 #include "llvm/MC/MCSymbolELF.h"
     20 #include "llvm/MC/SectionKind.h"
     21 
     22 namespace llvm {
     23 
     24 class MCSymbol;
     25 
     26 /// This represents a section on linux, lots of unix variants and some bare
     27 /// metal systems.
     28 class MCSectionELF final : public MCSection {
     29   /// This is the sh_type field of a section, drawn from the enums below.
     30   unsigned Type;
     31 
     32   /// This is the sh_flags field of a section, drawn from the enums below.
     33   unsigned Flags;
     34 
     35   unsigned UniqueID;
     36 
     37   /// The size of each entry in this section. This size only makes sense for
     38   /// sections that contain fixed-sized entries. If a section does not contain
     39   /// fixed-sized entries 'EntrySize' will be 0.
     40   unsigned EntrySize;
     41 
     42   /// The section group signature symbol (if not null) and a bool indicating
     43   /// whether this is a GRP_COMDAT group.
     44   const PointerIntPair<const MCSymbolELF *, 1, bool> Group;
     45 
     46   /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
     47   /// section header index of the section where LinkedToSym is defined.
     48   const MCSymbol *LinkedToSym;
     49 
     50 private:
     51   friend class MCContext;
     52 
     53   // The storage of Name is owned by MCContext's ELFUniquingMap.
     54   MCSectionELF(StringRef Name, unsigned type, unsigned flags, SectionKind K,
     55                unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
     56                unsigned UniqueID, MCSymbol *Begin,
     57                const MCSymbolELF *LinkedToSym)
     58       : MCSection(SV_ELF, Name, K, Begin), Type(type), Flags(flags),
     59         UniqueID(UniqueID), EntrySize(entrySize), Group(group, IsComdat),
     60         LinkedToSym(LinkedToSym) {
     61     if (Group.getPointer())
     62       Group.getPointer()->setIsSignature();
     63   }
     64 
     65   // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
     66   // sections.
     67   void setSectionName(StringRef Name) { this->Name = Name; }
     68 
     69 public:
     70   /// Decides whether a '.section' directive should be printed before the
     71   /// section name
     72   bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
     73 
     74   unsigned getType() const { return Type; }
     75   unsigned getFlags() const { return Flags; }
     76   unsigned getEntrySize() const { return EntrySize; }
     77   void setFlags(unsigned F) { Flags = F; }
     78   const MCSymbolELF *getGroup() const { return Group.getPointer(); }
     79   bool isComdat() const { return Group.getInt(); }
     80 
     81   void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
     82                             raw_ostream &OS,
     83                             const MCExpr *Subsection) const override;
     84   bool UseCodeAlign() const override;
     85   bool isVirtualSection() const override;
     86   StringRef getVirtualSectionKind() const override;
     87 
     88   bool isUnique() const { return UniqueID != NonUniqueID; }
     89   unsigned getUniqueID() const { return UniqueID; }
     90 
     91   const MCSection *getLinkedToSection() const {
     92     return &LinkedToSym->getSection();
     93   }
     94   const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
     95 
     96   static bool classof(const MCSection *S) {
     97     return S->getVariant() == SV_ELF;
     98   }
     99 };
    100 
    101 } // end namespace llvm
    102 
    103 #endif // LLVM_MC_MCSECTIONELF_H
    104