MCSectionMachO.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef LLVM_MC_MCSECTIONMACHO_H
  14. #define LLVM_MC_MCSECTIONMACHO_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/MC/MCSection.h"
  17. #include "llvm/Support/MachO.h"
  18. namespace llvm {
  19. /// MCSectionMachO - This represents a section on a Mach-O system (used by
  20. /// Mac OS X). On a Mac system, these are also described in
  21. /// /usr/include/mach-o/loader.h.
  22. class MCSectionMachO : public MCSection {
  23. char SegmentName[16]; // Not necessarily null terminated!
  24. char SectionName[16]; // Not necessarily null terminated!
  25. /// TypeAndAttributes - This is the SECTION_TYPE and SECTION_ATTRIBUTES
  26. /// field of a section, drawn from the enums below.
  27. unsigned TypeAndAttributes;
  28. /// Reserved2 - The 'reserved2' field of a section, used to represent the
  29. /// size of stubs, for example.
  30. unsigned Reserved2;
  31. MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
  32. unsigned reserved2, SectionKind K, MCSymbol *Begin);
  33. friend class MCContext;
  34. public:
  35. StringRef getSegmentName() const {
  36. // SegmentName is not necessarily null terminated!
  37. if (SegmentName[15])
  38. return StringRef(SegmentName, 16);
  39. return StringRef(SegmentName);
  40. }
  41. StringRef getSectionName() const {
  42. // SectionName is not necessarily null terminated!
  43. if (SectionName[15])
  44. return StringRef(SectionName, 16);
  45. return StringRef(SectionName);
  46. }
  47. unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
  48. unsigned getStubSize() const { return Reserved2; }
  49. MachO::SectionType getType() const {
  50. return static_cast<MachO::SectionType>(TypeAndAttributes &
  51. MachO::SECTION_TYPE);
  52. }
  53. bool hasAttribute(unsigned Value) const {
  54. return (TypeAndAttributes & Value) != 0;
  55. }
  56. /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
  57. /// This is a string that can appear after a .section directive in a mach-o
  58. /// flavored .s file. If successful, this fills in the specified Out
  59. /// parameters and returns an empty string. When an invalid section
  60. /// specifier is present, this returns a string indicating the problem.
  61. /// If no TAA was parsed, TAA is not altered, and TAAWasSet becomes false.
  62. static std::string ParseSectionSpecifier(StringRef Spec, // In.
  63. StringRef &Segment, // Out.
  64. StringRef &Section, // Out.
  65. unsigned &TAA, // Out.
  66. bool &TAAParsed, // Out.
  67. unsigned &StubSize); // Out.
  68. void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
  69. const MCExpr *Subsection) const override;
  70. bool UseCodeAlign() const override;
  71. bool isVirtualSection() const override;
  72. static bool classof(const MCSection *S) {
  73. return S->getVariant() == SV_MachO;
  74. }
  75. };
  76. } // end namespace llvm
  77. #endif