OSDN Git Service

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