LLVM 19.0.0git
MCSectionMachO.h
Go to the documentation of this file.
1//===- MCSectionMachO.h - MachO 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 MCSectionMachO class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_MC_MCSECTIONMACHO_H
14#define LLVM_MC_MCSECTIONMACHO_H
15
16#include "llvm/ADT/StringRef.h"
18#include "llvm/MC/MCSection.h"
19
20namespace llvm {
21
22/// This represents a section on a Mach-O system (used by Mac OS X). On a Mac
23/// system, these are also described in /usr/include/mach-o/loader.h.
24class MCSectionMachO final : public MCSection {
25 char SegmentName[16]; // Not necessarily null terminated!
26
27 /// This is the SECTION_TYPE and SECTION_ATTRIBUTES field of a section, drawn
28 /// from the enums below.
29 unsigned TypeAndAttributes;
30
31 /// The 'reserved2' field of a section, used to represent the size of stubs,
32 /// for example.
33 unsigned Reserved2;
34
35 // The defining non-temporary symbol for each fragment.
37
38 MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
39 unsigned reserved2, SectionKind K, MCSymbol *Begin);
40 friend class MCContext;
41public:
42
44 // SegmentName is not necessarily null terminated!
45 if (SegmentName[15])
46 return StringRef(SegmentName, 16);
47 return StringRef(SegmentName);
48 }
49
50 unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
51 unsigned getStubSize() const { return Reserved2; }
52
54 return static_cast<MachO::SectionType>(TypeAndAttributes &
56 }
57 bool hasAttribute(unsigned Value) const {
58 return (TypeAndAttributes & Value) != 0;
59 }
60
61 /// Parse the section specifier indicated by "Spec". This is a string that can
62 /// appear after a .section directive in a mach-o flavored .s file. If
63 /// successful, this fills in the specified Out parameters and returns an
64 /// empty string. When an invalid section specifier is present, this returns
65 /// an Error indicating the problem. If no TAA was parsed, TAA is not altered,
66 /// and TAAWasSet becomes false.
68 StringRef &Segment, // Out.
69 StringRef &Section, // Out.
70 unsigned &TAA, // Out.
71 bool &TAAParsed, // Out.
72 unsigned &StubSize); // Out.
73
74 void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
76 uint32_t Subsection) const override;
77 bool useCodeAlign() const override;
78
79 void allocAtoms();
80 const MCSymbol *getAtom(size_t I) const;
81 void setAtom(size_t I, const MCSymbol *Sym);
82
83 static bool classof(const MCSection *S) {
84 return S->getVariant() == SV_MachO;
85 }
86};
87
88} // end namespace llvm
89
90#endif
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define I(x, y, z)
Definition: MD5.cpp:58
raw_pwrite_stream & OS
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Context object for machine code objects.
Definition: MCContext.h:83
This represents a section on a Mach-O system (used by Mac OS X).
static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
MachO::SectionType getType() const
void setAtom(size_t I, const MCSymbol *Sym)
StringRef getSegmentName() const
const MCSymbol * getAtom(size_t I) const
bool useCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
unsigned getTypeAndAttributes() const
bool hasAttribute(unsigned Value) const
static bool classof(const MCSection *S)
void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, uint32_t Subsection) const override
unsigned getStubSize() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
SectionVariant getVariant() const
Definition: MCSection.h:145
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
SectionType
These are the section type and attributes fields.
Definition: MachO.h:122
@ SECTION_TYPE
Definition: MachO.h:114
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18