LLVM  14.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 
20 namespace 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.
24 class 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  MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
36  unsigned reserved2, SectionKind K, MCSymbol *Begin);
37  friend class MCContext;
38 public:
39 
41  // SegmentName is not necessarily null terminated!
42  if (SegmentName[15])
43  return StringRef(SegmentName, 16);
44  return StringRef(SegmentName);
45  }
46 
47  unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
48  unsigned getStubSize() const { return Reserved2; }
49 
51  return static_cast<MachO::SectionType>(TypeAndAttributes &
53  }
54  bool hasAttribute(unsigned Value) const {
55  return (TypeAndAttributes & Value) != 0;
56  }
57 
58  /// Parse the section specifier indicated by "Spec". This is a string that can
59  /// appear after a .section directive in a mach-o flavored .s file. If
60  /// successful, this fills in the specified Out parameters and returns an
61  /// empty string. When an invalid section specifier is present, this returns
62  /// an Error indicating the problem. If no TAA was parsed, TAA is not altered,
63  /// and TAAWasSet becomes false.
64  static Error ParseSectionSpecifier(StringRef Spec, // In.
65  StringRef &Segment, // Out.
66  StringRef &Section, // Out.
67  unsigned &TAA, // Out.
68  bool &TAAParsed, // Out.
69  unsigned &StubSize); // Out.
70 
71  void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
72  raw_ostream &OS,
73  const MCExpr *Subsection) const override;
74  bool UseCodeAlign() const override;
75  bool isVirtualSection() const override;
76 
77  static bool classof(const MCSection *S) {
78  return S->getVariant() == SV_MachO;
79  }
80 };
81 
82 } // end namespace llvm
83 
84 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MachO::SECTION_TYPE
@ SECTION_TYPE
Definition: MachO.h:112
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
StringRef.h
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::MCSection::SV_MachO
@ SV_MachO
Definition: MCSection.h:47
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::MCSectionMachO::getType
MachO::SectionType getType() const
Definition: MCSectionMachO.h:50
llvm::MCSectionMachO::ParseSectionSpecifier
static Error ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
Parse the section specifier indicated by "Spec".
Definition: MCSectionMachO.cpp:177
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCSectionMachO::getTypeAndAttributes
unsigned getTypeAndAttributes() const
Definition: MCSectionMachO.h:47
llvm::MCSectionMachO::hasAttribute
bool hasAttribute(unsigned Value) const
Definition: MCSectionMachO.h:54
llvm::MCSectionMachO::PrintSwitchToSection
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
Definition: MCSectionMachO.cpp:98
MCSection.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::MCSectionMachO::isVirtualSection
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
Definition: MCSectionMachO.cpp:166
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCSectionMachO::UseCodeAlign
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
Definition: MCSectionMachO.cpp:162
llvm::MCSectionMachO::classof
static bool classof(const MCSection *S)
Definition: MCSectionMachO.h:77
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::MCSectionMachO
This represents a section on a Mach-O system (used by Mac OS X).
Definition: MCSectionMachO.h:24
llvm::MCSectionMachO::getSegmentName
StringRef getSegmentName() const
Definition: MCSectionMachO.h:40
MachO.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::MCSectionMachO::getStubSize
unsigned getStubSize() const
Definition: MCSectionMachO.h:48
llvm::MachO::SectionType
SectionType
These are the section type and attributes fields.
Definition: MachO.h:120