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