PageRenderTime 24ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/gcc/gcc/config/i386/darwin.h

https://github.com/haiku/buildtools
C Header | 357 lines | 216 code | 62 blank | 79 comment | 36 complexity | 746464bd1413bdc2ccdd62a67866f0b9 MD5 | raw file
  1. /* Target definitions for x86 running Darwin.
  2. Copyright (C) 2001-2021 Free Software Foundation, Inc.
  3. Contributed by Apple Computer Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. /* Enable Mach-O bits in generic x86 code. */
  17. #undef TARGET_MACHO
  18. #define TARGET_MACHO 1
  19. #undef DARWIN_X86
  20. #define DARWIN_X86 1
  21. #undef TARGET_64BIT
  22. #define TARGET_64BIT TARGET_ISA_64BIT
  23. #undef TARGET_64BIT_P
  24. #define TARGET_64BIT_P(x) TARGET_ISA_64BIT_P(x)
  25. #ifdef IN_LIBGCC2
  26. #undef TARGET_64BIT
  27. #ifdef __x86_64__
  28. #define TARGET_64BIT 1
  29. #else
  30. #define TARGET_64BIT 0
  31. #endif
  32. #endif
  33. /* WORKAROUND pr80556:
  34. For x86_64 Darwin10 and later, the unwinder is in libunwind (redirected
  35. from libSystem). This doesn't use the keymgr (see keymgr.c) and therefore
  36. the calls that libgcc makes to obtain the KEYMGR_GCC3_DW2_OBJ_LIST are not
  37. updated to include new images, and might not even be valid for a single
  38. image.
  39. Therefore, for 64b exes at least, we must use the libunwind implementation,
  40. even when static-libgcc is specified. We put libSystem first so that
  41. unwinder symbols are satisfied from there.
  42. We default to 64b for single-arch builds, so apply this unconditionally. */
  43. #undef REAL_LIBGCC_SPEC
  44. #define REAL_LIBGCC_SPEC \
  45. "%{static-libgcc|static: \
  46. %:version-compare(>= 10.6 mmacosx-version-min= -lSystem) \
  47. -lgcc_eh -lgcc; \
  48. shared-libgcc|fexceptions|fgnu-runtime: \
  49. %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_s.10.4) \
  50. %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5) \
  51. %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_ext.10.4) \
  52. %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_ext.10.5) \
  53. -lgcc ; \
  54. :%:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \
  55. %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5) \
  56. %:version-compare(!> 10.5 mmacosx-version-min= -lgcc_ext.10.4) \
  57. %:version-compare(>= 10.5 mmacosx-version-min= -lgcc_ext.10.5) \
  58. -lgcc }"
  59. /* Size of the Obj-C jump buffer. */
  60. #define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
  61. #undef TARGET_FPMATH_DEFAULT
  62. #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
  63. #undef TARGET_FPMATH_DEFAULT_P
  64. #define TARGET_FPMATH_DEFAULT_P(x) \
  65. (TARGET_SSE_P(x) ? FPMATH_SSE : FPMATH_387)
  66. #define TARGET_OS_CPP_BUILTINS() \
  67. do { \
  68. builtin_define ("__LITTLE_ENDIAN__"); \
  69. darwin_cpp_builtins (pfile); \
  70. } while (0)
  71. #undef PTRDIFF_TYPE
  72. #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
  73. #undef WCHAR_TYPE
  74. #define WCHAR_TYPE "int"
  75. #undef WCHAR_TYPE_SIZE
  76. #define WCHAR_TYPE_SIZE 32
  77. /* Generate pic symbol indirection stubs if this is true. */
  78. #undef TARGET_MACHO_SYMBOL_STUBS
  79. #define TARGET_MACHO_SYMBOL_STUBS (darwin_symbol_stubs)
  80. /* For compatibility with OSX system tools, use the new style of pic stub
  81. if this is set (default). */
  82. #undef MACHOPIC_ATT_STUB
  83. #define MACHOPIC_ATT_STUB (darwin_macho_att_stub)
  84. #undef MAX_BITS_PER_WORD
  85. #define MAX_BITS_PER_WORD 64
  86. #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
  87. #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
  88. #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
  89. #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
  90. /* On Darwin, the stack is 128-bit aligned at the point of every call.
  91. Failure to ensure this will lead to a crash in the system libraries
  92. or dynamic loader. */
  93. #undef MAIN_STACK_BOUNDARY
  94. #define MAIN_STACK_BOUNDARY 128
  95. /* Since we'll never want a stack boundary less aligned than 128 bits
  96. we need the extra work here otherwise bits of gcc get very grumpy
  97. when we ask for lower alignment. We could just reject values less
  98. than 128 bits for Darwin, but it's easier to up the alignment if
  99. it's below the minimum. */
  100. #undef PREFERRED_STACK_BOUNDARY
  101. #define PREFERRED_STACK_BOUNDARY \
  102. MAX (128, ix86_preferred_stack_boundary)
  103. /* We want -fPIC by default, unless we're using -static to compile for
  104. the kernel or some such. */
  105. #undef CC1_SPEC
  106. #define CC1_SPEC "%(cc1_cpu) \
  107. %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
  108. %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
  109. %{mx32:%eDarwin is not an mx32 platform} \
  110. %{mfentry*:%eDarwin does not support -mfentry or associated options}" \
  111. DARWIN_CC1_SPEC
  112. #undef ASM_SPEC
  113. #define ASM_SPEC "-arch %(darwin_arch) \
  114. " ASM_OPTIONS " -force_cpusubtype_ALL \
  115. %{static}" ASM_MMACOSX_VERSION_MIN_SPEC
  116. #undef ENDFILE_SPEC
  117. #define ENDFILE_SPEC \
  118. "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
  119. %{mpc32:crtprec32.o%s} \
  120. %{mpc64:crtprec64.o%s} \
  121. %{mpc80:crtprec80.o%s}" TM_DESTRUCTOR
  122. /* We default to x86_64 for single-arch builds, bi-arch overrides. */
  123. #define DARWIN_ARCH_SPEC "x86_64"
  124. #undef SUBTARGET_EXTRA_SPECS
  125. #define SUBTARGET_EXTRA_SPECS \
  126. DARWIN_EXTRA_SPECS \
  127. { "darwin_arch", DARWIN_ARCH_SPEC }, \
  128. { "darwin_crt2", "" }, \
  129. { "darwin_subarch", DARWIN_ARCH_SPEC },
  130. /* The Darwin assembler mostly follows AT&T syntax. */
  131. #undef ASSEMBLER_DIALECT
  132. #define ASSEMBLER_DIALECT ASM_ATT
  133. /* Define macro used to output shift-double opcodes when the shift
  134. count is in %cl. Some assemblers require %cl as an argument;
  135. some don't. This macro controls what to do: by default, don't
  136. print %cl. */
  137. #define SHIFT_DOUBLE_OMITS_COUNT 0
  138. #undef TARGET_ASM_FILE_END
  139. #define TARGET_ASM_FILE_END darwin_file_end
  140. /* Define the syntax of pseudo-ops, labels and comments. */
  141. /* String containing the assembler's comment-starter. */
  142. #define ASM_COMMENT_START "#"
  143. /* By default, target has a 80387, uses IEEE compatible arithmetic,
  144. and returns float values in the 387. */
  145. #undef TARGET_SUBTARGET_DEFAULT
  146. #define TARGET_SUBTARGET_DEFAULT \
  147. (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
  148. /* For darwin we want to target specific processor features as a minimum,
  149. but these unfortunately don't correspond to a specific processor. */
  150. #undef TARGET_SUBTARGET32_ISA_DEFAULT
  151. #define TARGET_SUBTARGET32_ISA_DEFAULT \
  152. (OPTION_MASK_ISA_MMX | OPTION_MASK_ISA_SSE \
  153. | OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE3)
  154. #undef TARGET_SUBTARGET64_ISA_DEFAULT
  155. #define TARGET_SUBTARGET64_ISA_DEFAULT TARGET_SUBTARGET32_ISA_DEFAULT
  156. #undef GOT_SYMBOL_NAME
  157. #define GOT_SYMBOL_NAME MACHOPIC_FUNCTION_BASE_NAME
  158. /* Define the syntax of pseudo-ops, labels and comments. */
  159. #define LPREFIX "L"
  160. /* Assembler pseudos to introduce constants of various size. */
  161. #define ASM_BYTE "\t.byte\t"
  162. #define ASM_SHORT "\t.word\t"
  163. #define ASM_LONG "\t.long\t"
  164. #define ASM_QUAD "\t.quad\t"
  165. #define SUBTARGET_ENCODE_SECTION_INFO darwin_encode_section_info
  166. #undef ASM_OUTPUT_ALIGN
  167. #define ASM_OUTPUT_ALIGN(FILE,LOG) \
  168. do { \
  169. if ((LOG) != 0) \
  170. { \
  171. if (in_section == text_section) \
  172. fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
  173. else \
  174. fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
  175. } \
  176. } while (0)
  177. #ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
  178. #define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE,LOG,MAX_SKIP) \
  179. do { \
  180. if ((LOG) != 0) { \
  181. if ((MAX_SKIP) == 0 || (MAX_SKIP) >= (1 << (LOG)) - 1) \
  182. fprintf ((FILE), "\t.p2align %d\n", (LOG)); \
  183. else \
  184. fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP)); \
  185. } \
  186. } while (0)
  187. #endif
  188. /* Darwin x86 assemblers support the .ident directive. */
  189. #undef TARGET_ASM_OUTPUT_IDENT
  190. #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
  191. /* We always want jump tables in the text section:
  192. * for PIC code, we need the subtracted symbol to be defined at
  193. assembly-time.
  194. * for mdynamic-no-pic, we cannot support jump tables in the .const
  195. section for weak functions, this looks to ld64 like direct access
  196. to the weak symbol from an anonymous atom. */
  197. #undef JUMP_TABLES_IN_TEXT_SECTION
  198. #define JUMP_TABLES_IN_TEXT_SECTION 1
  199. /* Darwin profiling -- call mcount.
  200. If we need a stub, then we unconditionally mark it as used. */
  201. #undef FUNCTION_PROFILER
  202. #define FUNCTION_PROFILER(FILE, LABELNO) \
  203. do { \
  204. if (TARGET_MACHO_SYMBOL_STUBS \
  205. && MACHOPIC_INDIRECT && !TARGET_64BIT) \
  206. { \
  207. const char *name = machopic_mcount_stub_name (); \
  208. fprintf (FILE, "\tcall %s\n", name+1); /* skip '&' */ \
  209. } \
  210. else fprintf (FILE, "\tcall mcount\n"); \
  211. } while (0)
  212. #define C_COMMON_OVERRIDE_OPTIONS \
  213. do { \
  214. SUBTARGET_C_COMMON_OVERRIDE_OPTIONS; \
  215. } while (0)
  216. #undef SUBTARGET_OVERRIDE_OPTIONS
  217. #define SUBTARGET_OVERRIDE_OPTIONS \
  218. do { \
  219. if (TARGET_64BIT && MACHO_DYNAMIC_NO_PIC_P) \
  220. target_flags &= ~MASK_MACHO_DYNAMIC_NO_PIC; \
  221. } while (0)
  222. /* Darwin on x86_64 uses dwarf-2 by default. Pre-darwin9 32-bit
  223. compiles default to stabs+. darwin9+ defaults to dwarf-2. */
  224. #ifndef DARWIN_PREFER_DWARF
  225. #undef PREFERRED_DEBUGGING_TYPE
  226. #ifdef HAVE_AS_STABS_DIRECTIVE
  227. #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
  228. #else
  229. #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
  230. #endif
  231. #endif
  232. /* Darwin uses the standard DWARF register numbers but the default
  233. register numbers for STABS. Fortunately for 64-bit code the
  234. default and the standard are the same. */
  235. #undef DBX_REGISTER_NUMBER
  236. #define DBX_REGISTER_NUMBER(n) \
  237. (TARGET_64BIT ? dbx64_register_map[n] \
  238. : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n] \
  239. : dbx_register_map[n])
  240. /* Unfortunately, the 32-bit EH information also doesn't use the standard
  241. DWARF register numbers. */
  242. #define DWARF2_FRAME_REG_OUT(n, for_eh) \
  243. (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n) \
  244. : (n) == 5 ? 4 \
  245. : (n) == 4 ? 5 \
  246. : (n) >= 11 && (n) <= 18 ? (n) + 1 \
  247. : (n))
  248. #undef REGISTER_SUBTARGET_PRAGMAS
  249. #define REGISTER_SUBTARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
  250. #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
  251. #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
  252. /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
  253. end of the instruction, but without the 4 we'd only have the right
  254. address for the start of the instruction. */
  255. #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
  256. #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE) \
  257. if (TARGET_64BIT) \
  258. { \
  259. if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel) \
  260. { \
  261. fputs (ASM_LONG, FILE); \
  262. assemble_name (FILE, XSTR (ADDR, 0)); \
  263. fputs ("+4@GOTPCREL", FILE); \
  264. goto DONE; \
  265. } \
  266. } \
  267. else \
  268. { \
  269. if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) \
  270. { \
  271. darwin_non_lazy_pcrel (FILE, ADDR); \
  272. goto DONE; \
  273. } \
  274. }
  275. /* First available SYMBOL flag bit for use by subtargets. */
  276. #define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP << 5)
  277. #undef MACHOPIC_NL_SYMBOL_PTR_SECTION
  278. #define MACHOPIC_NL_SYMBOL_PTR_SECTION \
  279. ".section __IMPORT,__pointers,non_lazy_symbol_pointers"
  280. #define SUBTARGET32_DEFAULT_CPU "i686"
  281. #undef SUBTARGET_INIT_BUILTINS
  282. #define SUBTARGET_INIT_BUILTINS \
  283. do { \
  284. ix86_builtins[(int) IX86_BUILTIN_CFSTRING] \
  285. = darwin_init_cfstring_builtins ((unsigned) (IX86_BUILTIN_CFSTRING)); \
  286. darwin_rename_builtins (); \
  287. } while(0)
  288. /* Define the shadow offset for asan. */
  289. #undef SUBTARGET_SHADOW_OFFSET
  290. #define SUBTARGET_SHADOW_OFFSET \
  291. (TARGET_LP64 ? HOST_WIDE_INT_1 << 44 : HOST_WIDE_INT_1 << 29)