MCSectionMachO.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MCSectionMachO.h - MachO Machine Code Sections -----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the MCSectionMachO class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCSECTIONMACHO_H
  18. #define LLVM_MC_MCSECTIONMACHO_H
  19. #include "llvm/ADT/StringRef.h"
  20. #include "llvm/BinaryFormat/MachO.h"
  21. #include "llvm/MC/MCSection.h"
  22. namespace llvm {
  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.
  25. class MCSectionMachO final : public MCSection {
  26. char SegmentName[16]; // Not necessarily null terminated!
  27. /// This is the SECTION_TYPE and SECTION_ATTRIBUTES field of a section, drawn
  28. /// from the enums below.
  29. unsigned TypeAndAttributes;
  30. /// The 'reserved2' field of a section, used to represent the size of stubs,
  31. /// for example.
  32. unsigned Reserved2;
  33. MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA,
  34. unsigned reserved2, SectionKind K, MCSymbol *Begin);
  35. friend class MCContext;
  36. public:
  37. StringRef getSegmentName() const {
  38. // SegmentName is not necessarily null terminated!
  39. if (SegmentName[15])
  40. return StringRef(SegmentName, 16);
  41. return StringRef(SegmentName);
  42. }
  43. unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
  44. unsigned getStubSize() const { return Reserved2; }
  45. MachO::SectionType getType() const {
  46. return static_cast<MachO::SectionType>(TypeAndAttributes &
  47. MachO::SECTION_TYPE);
  48. }
  49. bool hasAttribute(unsigned Value) const {
  50. return (TypeAndAttributes & Value) != 0;
  51. }
  52. /// Parse the section specifier indicated by "Spec". This is a string that can
  53. /// appear after a .section directive in a mach-o flavored .s file. If
  54. /// successful, this fills in the specified Out parameters and returns an
  55. /// empty string. When an invalid section specifier is present, this returns
  56. /// an Error indicating the problem. If no TAA was parsed, TAA is not altered,
  57. /// and TAAWasSet becomes false.
  58. static Error ParseSectionSpecifier(StringRef Spec, // In.
  59. StringRef &Segment, // Out.
  60. StringRef &Section, // Out.
  61. unsigned &TAA, // Out.
  62. bool &TAAParsed, // Out.
  63. unsigned &StubSize); // Out.
  64. void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
  65. raw_ostream &OS,
  66. const MCExpr *Subsection) const override;
  67. bool UseCodeAlign() const override;
  68. bool isVirtualSection() const override;
  69. static bool classof(const MCSection *S) {
  70. return S->getVariant() == SV_MachO;
  71. }
  72. };
  73. } // end namespace llvm
  74. #endif
  75. #ifdef __GNUC__
  76. #pragma GCC diagnostic pop
  77. #endif