Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- MCSectionELF.h - ELF 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 MCSectionELF class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCSECTIONELF_H
0014 #define LLVM_MC_MCSECTIONELF_H
0015 
0016 #include "llvm/ADT/PointerIntPair.h"
0017 #include "llvm/ADT/StringRef.h"
0018 #include "llvm/BinaryFormat/ELF.h"
0019 #include "llvm/MC/MCSection.h"
0020 #include "llvm/MC/MCSymbolELF.h"
0021 #include "llvm/MC/SectionKind.h"
0022 
0023 namespace llvm {
0024 
0025 /// This represents a section on linux, lots of unix variants and some bare
0026 /// metal systems.
0027 class MCSectionELF final : public MCSection {
0028   /// This is the sh_type field of a section, drawn from the enums below.
0029   unsigned Type;
0030 
0031   /// This is the sh_flags field of a section, drawn from the enums below.
0032   unsigned Flags;
0033 
0034   unsigned UniqueID;
0035 
0036   /// The size of each entry in this section. This size only makes sense for
0037   /// sections that contain fixed-sized entries. If a section does not contain
0038   /// fixed-sized entries 'EntrySize' will be 0.
0039   unsigned EntrySize;
0040 
0041   /// The section group signature symbol (if not null) and a bool indicating
0042   /// whether this is a GRP_COMDAT group.
0043   const PointerIntPair<const MCSymbolELF *, 1, bool> Group;
0044 
0045   /// Used by SHF_LINK_ORDER. If non-null, the sh_link field will be set to the
0046   /// section header index of the section where LinkedToSym is defined.
0047   const MCSymbol *LinkedToSym;
0048 
0049   /// Start/end offset in file, used by ELFWriter.
0050   uint64_t StartOffset;
0051   uint64_t EndOffset;
0052 
0053 private:
0054   friend class MCContext;
0055 
0056   // The storage of Name is owned by MCContext's ELFUniquingMap.
0057   MCSectionELF(StringRef Name, unsigned type, unsigned flags,
0058                unsigned entrySize, const MCSymbolELF *group, bool IsComdat,
0059                unsigned UniqueID, MCSymbol *Begin,
0060                const MCSymbolELF *LinkedToSym)
0061       : MCSection(SV_ELF, Name, flags & ELF::SHF_EXECINSTR,
0062                   type == ELF::SHT_NOBITS, Begin),
0063         Type(type), Flags(flags), UniqueID(UniqueID), EntrySize(entrySize),
0064         Group(group, IsComdat), LinkedToSym(LinkedToSym) {
0065     assert((!(Flags & ELF::SHF_GROUP) || Group.getPointer()) &&
0066            "Group section without signature!");
0067     if (Group.getPointer())
0068       Group.getPointer()->setIsSignature();
0069   }
0070 
0071   // TODO Delete after we stop supporting generation of GNU-style .zdebug_*
0072   // sections.
0073   void setSectionName(StringRef Name) { this->Name = Name; }
0074 
0075 public:
0076   /// Decides whether a '.section' directive should be printed before the
0077   /// section name
0078   bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
0079 
0080   unsigned getType() const { return Type; }
0081   unsigned getFlags() const { return Flags; }
0082   unsigned getEntrySize() const { return EntrySize; }
0083   void setFlags(unsigned F) { Flags = F; }
0084   const MCSymbolELF *getGroup() const { return Group.getPointer(); }
0085   bool isComdat() const { return Group.getInt(); }
0086 
0087   void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
0088                             raw_ostream &OS,
0089                             uint32_t Subsection) const override;
0090   bool useCodeAlign() const override;
0091   StringRef getVirtualSectionKind() const override;
0092 
0093   bool isUnique() const { return UniqueID != NonUniqueID; }
0094   unsigned getUniqueID() const { return UniqueID; }
0095 
0096   const MCSection *getLinkedToSection() const {
0097     return &LinkedToSym->getSection();
0098   }
0099   const MCSymbol *getLinkedToSymbol() const { return LinkedToSym; }
0100 
0101   void setOffsets(uint64_t Start, uint64_t End) {
0102     StartOffset = Start;
0103     EndOffset = End;
0104   }
0105   std::pair<uint64_t, uint64_t> getOffsets() const {
0106     return std::make_pair(StartOffset, EndOffset);
0107   }
0108 
0109   static bool classof(const MCSection *S) {
0110     return S->getVariant() == SV_ELF;
0111   }
0112 };
0113 
0114 } // end namespace llvm
0115 
0116 #endif // LLVM_MC_MCSECTIONELF_H