LLVM 24.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"
20
21namespace llvm {
22
23/// This represents a section on a Mach-O system (used by Mac OS X). On a Mac
24/// system, these are also described in /usr/include/mach-o/loader.h.
25class LLVM_ABI MCSectionMachO final : public MCSection {
26 friend class MCContext;
27 char SegmentName[16]; // Not necessarily null terminated!
28
29 /// This is the SECTION_TYPE and SECTION_ATTRIBUTES field of a section, drawn
30 /// from the enums below.
31 unsigned TypeAndAttributes;
32
33 /// The 'reserved2' field of a section, used to represent the size of stubs,
34 /// for example.
35 unsigned Reserved2;
36
37 // The index of this section in MachObjectWriter::SectionOrder, which is
38 // different from MCSection::Ordinal.
39 unsigned LayoutOrder = 0;
40
41 // The defining non-temporary symbol for each fragment.
43
44 MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
45 unsigned reserved2, SectionKind K, MCSymbol *Begin);
46public:
47
49 // SegmentName is not necessarily null terminated!
50 if (SegmentName[15])
51 return StringRef(SegmentName, 16);
52 return StringRef(SegmentName);
53 }
54
55 unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
56 unsigned getStubSize() const { return Reserved2; }
57
59 return static_cast<MachO::SectionType>(TypeAndAttributes &
61 }
62 bool hasAttribute(unsigned Value) const {
63 return (TypeAndAttributes & Value) != 0;
64 }
65
66 /// Parse the section specifier indicated by "Spec". This is a string that can
67 /// appear after a .section directive in a mach-o flavored .s file. If
68 /// successful, this fills in the specified Out parameters and returns an
69 /// empty string. When an invalid section specifier is present, this returns
70 /// an Error indicating the problem. If no TAA was parsed, TAA is not altered,
71 /// and TAAWasSet becomes false.
72 static Error ParseSectionSpecifier(StringRef Spec, // In.
73 StringRef &Segment, // Out.
74 StringRef &Section, // Out.
75 unsigned &TAA, // Out.
76 bool &TAAParsed, // Out.
77 unsigned &StubSize); // Out.
78
79 void allocAtoms();
80 const MCSymbol *getAtom(size_t I) const;
81 void setAtom(size_t I, const MCSymbol *Sym);
82
83 unsigned getLayoutOrder() const { return LayoutOrder; }
84 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
85};
86
87} // end namespace llvm
88
89#endif
#define LLVM_ABI
Definition Compiler.h:211
#define I(x, y, z)
Definition MD5.cpp:57
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
MachO::SectionType getType() const
StringRef getSegmentName() const
unsigned getLayoutOrder() const
void setLayoutOrder(unsigned Value)
unsigned getTypeAndAttributes() const
bool hasAttribute(unsigned Value) const
unsigned getStubSize() const
MCSection(StringRef Name, bool IsText, bool IsBss, MCSymbol *Begin)
Definition MCSection.cpp:21
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
@ SECTION_TYPE
Definition MachO.h:114
SectionType
These are the section type and attributes fields.
Definition MachO.h:122
This is an optimization pass for GlobalISel generic memory operations.