Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- MCSectionMachO.h - MachO 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 MCSectionMachO class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCSECTIONMACHO_H
0014 #define LLVM_MC_MCSECTIONMACHO_H
0015 
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/BinaryFormat/MachO.h"
0018 #include "llvm/MC/MCSection.h"
0019 
0020 namespace llvm {
0021 
0022 /// This represents a section on a Mach-O system (used by Mac OS X).  On a Mac
0023 /// system, these are also described in /usr/include/mach-o/loader.h.
0024 class MCSectionMachO final : public MCSection {
0025   char SegmentName[16];  // Not necessarily null terminated!
0026 
0027   /// This is the SECTION_TYPE and SECTION_ATTRIBUTES field of a section, drawn
0028   /// from the enums below.
0029   unsigned TypeAndAttributes;
0030 
0031   /// The 'reserved2' field of a section, used to represent the size of stubs,
0032   /// for example.
0033   unsigned Reserved2;
0034 
0035   // The index of this section in MachObjectWriter::SectionOrder, which is
0036   // different from MCSection::Ordinal.
0037   unsigned LayoutOrder = 0;
0038 
0039   // The defining non-temporary symbol for each fragment.
0040   SmallVector<const MCSymbol *, 0> Atoms;
0041 
0042   MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
0043                  unsigned reserved2, SectionKind K, MCSymbol *Begin);
0044   friend class MCContext;
0045 public:
0046 
0047   StringRef getSegmentName() const {
0048     // SegmentName is not necessarily null terminated!
0049     if (SegmentName[15])
0050       return StringRef(SegmentName, 16);
0051     return StringRef(SegmentName);
0052   }
0053 
0054   unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
0055   unsigned getStubSize() const { return Reserved2; }
0056 
0057   MachO::SectionType getType() const {
0058     return static_cast<MachO::SectionType>(TypeAndAttributes &
0059                                            MachO::SECTION_TYPE);
0060   }
0061   bool hasAttribute(unsigned Value) const {
0062     return (TypeAndAttributes & Value) != 0;
0063   }
0064 
0065   /// Parse the section specifier indicated by "Spec". This is a string that can
0066   /// appear after a .section directive in a mach-o flavored .s file.  If
0067   /// successful, this fills in the specified Out parameters and returns an
0068   /// empty string.  When an invalid section specifier is present, this returns
0069   /// an Error indicating the problem. If no TAA was parsed, TAA is not altered,
0070   /// and TAAWasSet becomes false.
0071   static Error ParseSectionSpecifier(StringRef Spec,      // In.
0072                                      StringRef &Segment,  // Out.
0073                                      StringRef &Section,  // Out.
0074                                      unsigned &TAA,       // Out.
0075                                      bool &TAAParsed,     // Out.
0076                                      unsigned &StubSize); // Out.
0077 
0078   void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
0079                             raw_ostream &OS,
0080                             uint32_t Subsection) const override;
0081   bool useCodeAlign() const override;
0082 
0083   void allocAtoms();
0084   const MCSymbol *getAtom(size_t I) const;
0085   void setAtom(size_t I, const MCSymbol *Sym);
0086 
0087   unsigned getLayoutOrder() const { return LayoutOrder; }
0088   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
0089 
0090   static bool classof(const MCSection *S) {
0091     return S->getVariant() == SV_MachO;
0092   }
0093 };
0094 
0095 } // end namespace llvm
0096 
0097 #endif