LLVM  3.7.0
MCSectionMachO.h
Go to the documentation of this file.
1 //===- MCSectionMachO.h - MachO Machine Code Sections -----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the MCSectionMachO class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MC_MCSECTIONMACHO_H
15 #define LLVM_MC_MCSECTIONMACHO_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/MC/MCSection.h"
19 #include "llvm/Support/MachO.h"
20 
21 namespace llvm {
22 
23 /// MCSectionMachO - This represents a section on a Mach-O system (used by
24 /// Mac OS X). On a Mac system, these are also described in
25 /// /usr/include/mach-o/loader.h.
26 class MCSectionMachO : public MCSection {
27  char SegmentName[16]; // Not necessarily null terminated!
28  char SectionName[16]; // Not necessarily null terminated!
29 
30  /// TypeAndAttributes - This is the SECTION_TYPE and SECTION_ATTRIBUTES
31  /// field of a section, drawn from the enums below.
32  unsigned TypeAndAttributes;
33 
34  /// Reserved2 - The 'reserved2' field of a section, used to represent the
35  /// size of stubs, for example.
36  unsigned Reserved2;
37 
38  MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
39  unsigned reserved2, SectionKind K, MCSymbol *Begin);
40  friend class MCContext;
41 public:
42 
44  // SegmentName is not necessarily null terminated!
45  if (SegmentName[15])
46  return StringRef(SegmentName, 16);
47  return StringRef(SegmentName);
48  }
50  // SectionName is not necessarily null terminated!
51  if (SectionName[15])
52  return StringRef(SectionName, 16);
53  return StringRef(SectionName);
54  }
55 
56  unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
57  unsigned getStubSize() const { return Reserved2; }
58 
60  return static_cast<MachO::SectionType>(TypeAndAttributes &
62  }
63  bool hasAttribute(unsigned Value) const {
64  return (TypeAndAttributes & Value) != 0;
65  }
66 
67  /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
68  /// This is a string that can appear after a .section directive in a mach-o
69  /// flavored .s file. If successful, this fills in the specified Out
70  /// parameters and returns an empty string. When an invalid section
71  /// specifier is present, this returns a string indicating the problem.
72  /// If no TAA was parsed, TAA is not altered, and TAAWasSet becomes false.
73  static std::string ParseSectionSpecifier(StringRef Spec, // In.
74  StringRef &Segment, // Out.
75  StringRef &Section, // Out.
76  unsigned &TAA, // Out.
77  bool &TAAParsed, // Out.
78  unsigned &StubSize); // Out.
79 
80  void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
81  const MCExpr *Subsection) const override;
82  bool UseCodeAlign() const override;
83  bool isVirtualSection() const override;
84 
85  static bool classof(const MCSection *S) {
86  return S->getVariant() == SV_MachO;
87  }
88 };
89 
90 } // end namespace llvm
91 
92 #endif
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
MCSectionMachO - This represents a section on a Mach-O system (used by Mac OS X). ...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
SectionVariant getVariant() const
Definition: MCSection.h:111
static bool classof(const MCSection *S)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Context object for machine code objects.
Definition: MCContext.h:48
StringRef getSectionName() const
unsigned getStubSize() const
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
static std::string ParseSectionSpecifier(StringRef Spec, StringRef &Segment, StringRef &Section, unsigned &TAA, bool &TAAParsed, unsigned &StubSize)
ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
bool hasAttribute(unsigned Value) const
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
MachO::SectionType getType() const
StringRef getSegmentName() const
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
unsigned getTypeAndAttributes() const
LLVM Value Representation.
Definition: Value.h:69
void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const override
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
SectionType
These are the section type and attributes fields.