Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
7.7 KiB

  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. namespace llvm {
  18. /// MCSectionMachO - This represents a section on a Mach-O system (used by
  19. /// Mac OS X). On a Mac system, these are also described in
  20. /// /usr/include/mach-o/loader.h.
  21. class MCSectionMachO : public MCSection {
  22. char SegmentName[16]; // Not necessarily null terminated!
  23. char SectionName[16]; // Not necessarily null terminated!
  24. /// TypeAndAttributes - This is the SECTION_TYPE and SECTION_ATTRIBUTES
  25. /// field of a section, drawn from the enums below.
  26. unsigned TypeAndAttributes;
  27. /// Reserved2 - The 'reserved2' field of a section, used to represent the
  28. /// size of stubs, for example.
  29. unsigned Reserved2;
  30. MCSectionMachO(StringRef Segment, StringRef Section,
  31. unsigned TAA, unsigned reserved2, SectionKind K);
  32. friend class MCContext;
  33. public:
  34. /// These are the section type and attributes fields. A MachO section can
  35. /// have only one Type, but can have any of the attributes specified.
  36. enum {
  37. // TypeAndAttributes bitmasks.
  38. SECTION_TYPE = 0x000000FFU,
  39. SECTION_ATTRIBUTES = 0xFFFFFF00U,
  40. // Valid section types.
  41. /// S_REGULAR - Regular section.
  42. S_REGULAR = 0x00U,
  43. /// S_ZEROFILL - Zero fill on demand section.
  44. S_ZEROFILL = 0x01U,
  45. /// S_CSTRING_LITERALS - Section with literal C strings.
  46. S_CSTRING_LITERALS = 0x02U,
  47. /// S_4BYTE_LITERALS - Section with 4 byte literals.
  48. S_4BYTE_LITERALS = 0x03U,
  49. /// S_8BYTE_LITERALS - Section with 8 byte literals.
  50. S_8BYTE_LITERALS = 0x04U,
  51. /// S_LITERAL_POINTERS - Section with pointers to literals.
  52. S_LITERAL_POINTERS = 0x05U,
  53. /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
  54. S_NON_LAZY_SYMBOL_POINTERS = 0x06U,
  55. /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
  56. S_LAZY_SYMBOL_POINTERS = 0x07U,
  57. /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in
  58. /// the Reserved2 field.
  59. S_SYMBOL_STUBS = 0x08U,
  60. /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for
  61. /// initialization.
  62. S_MOD_INIT_FUNC_POINTERS = 0x09U,
  63. /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for
  64. /// termination.
  65. S_MOD_TERM_FUNC_POINTERS = 0x0AU,
  66. /// S_COALESCED - Section contains symbols that are to be coalesced.
  67. S_COALESCED = 0x0BU,
  68. /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
  69. /// gigabytes).
  70. S_GB_ZEROFILL = 0x0CU,
  71. /// S_INTERPOSING - Section with only pairs of function pointers for
  72. /// interposing.
  73. S_INTERPOSING = 0x0DU,
  74. /// S_16BYTE_LITERALS - Section with only 16 byte literals.
  75. S_16BYTE_LITERALS = 0x0EU,
  76. /// S_DTRACE_DOF - Section contains DTrace Object Format.
  77. S_DTRACE_DOF = 0x0FU,
  78. /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to
  79. /// lazy loaded dylibs.
  80. S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10U,
  81. /// S_THREAD_LOCAL_REGULAR - Section with ....
  82. S_THREAD_LOCAL_REGULAR = 0x11U,
  83. /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
  84. S_THREAD_LOCAL_ZEROFILL = 0x12U,
  85. /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure
  86. /// data.
  87. S_THREAD_LOCAL_VARIABLES = 0x13U,
  88. /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with ....
  89. S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14U,
  90. /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local
  91. /// variable initialization pointers to functions.
  92. S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15U,
  93. LAST_KNOWN_SECTION_TYPE = S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
  94. // Valid section attributes.
  95. /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
  96. /// instructions.
  97. S_ATTR_PURE_INSTRUCTIONS = 1U << 31,
  98. /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be
  99. /// in a ranlib table of contents.
  100. S_ATTR_NO_TOC = 1U << 30,
  101. /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section
  102. /// in files with the MY_DYLDLINK flag.
  103. S_ATTR_STRIP_STATIC_SYMS = 1U << 29,
  104. /// S_ATTR_NO_DEAD_STRIP - No dead stripping.
  105. S_ATTR_NO_DEAD_STRIP = 1U << 28,
  106. /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
  107. S_ATTR_LIVE_SUPPORT = 1U << 27,
  108. /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by
  109. /// dyld.
  110. S_ATTR_SELF_MODIFYING_CODE = 1U << 26,
  111. /// S_ATTR_DEBUG - A debug section.
  112. S_ATTR_DEBUG = 1U << 25,
  113. /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
  114. S_ATTR_SOME_INSTRUCTIONS = 1U << 10,
  115. /// S_ATTR_EXT_RELOC - Section has external relocation entries.
  116. S_ATTR_EXT_RELOC = 1U << 9,
  117. /// S_ATTR_LOC_RELOC - Section has local relocation entries.
  118. S_ATTR_LOC_RELOC = 1U << 8
  119. };
  120. StringRef getSegmentName() const {
  121. // SegmentName is not necessarily null terminated!
  122. if (SegmentName[15])
  123. return StringRef(SegmentName, 16);
  124. return StringRef(SegmentName);
  125. }
  126. StringRef getSectionName() const {
  127. // SectionName is not necessarily null terminated!
  128. if (SectionName[15])
  129. return StringRef(SectionName, 16);
  130. return StringRef(SectionName);
  131. }
  132. virtual std::string getLabelBeginName() const {
  133. return StringRef(getSegmentName().str() + getSectionName().str() + "_begin");
  134. }
  135. virtual std::string getLabelEndName() const {
  136. return StringRef(getSegmentName().str() + getSectionName().str() + "_end");
  137. }
  138. unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
  139. unsigned getStubSize() const { return Reserved2; }
  140. unsigned getType() const { return TypeAndAttributes & SECTION_TYPE; }
  141. bool hasAttribute(unsigned Value) const {
  142. return (TypeAndAttributes & Value) != 0;
  143. }
  144. /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
  145. /// This is a string that can appear after a .section directive in a mach-o
  146. /// flavored .s file. If successful, this fills in the specified Out
  147. /// parameters and returns an empty string. When an invalid section
  148. /// specifier is present, this returns a string indicating the problem.
  149. /// If no TAA was parsed, TAA is not altered, and TAAWasSet becomes false.
  150. static std::string ParseSectionSpecifier(StringRef Spec, // In.
  151. StringRef &Segment, // Out.
  152. StringRef &Section, // Out.
  153. unsigned &TAA, // Out.
  154. bool &TAAParsed, // Out.
  155. unsigned &StubSize); // Out.
  156. virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
  157. raw_ostream &OS,
  158. const MCExpr *Subsection) const;
  159. virtual bool UseCodeAlign() const;
  160. virtual bool isVirtualSection() const;
  161. static bool classof(const MCSection *S) {
  162. return S->getVariant() == SV_MachO;
  163. }
  164. };
  165. } // end namespace llvm
  166. #endif