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