OSDN Git Service

2007-06-13 Eric Christopher <echristo@apple.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 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 2, 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 COPYING.  If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.  */
21
22 /* Enable Mach-O bits in generic x86 code.  */
23 #undef TARGET_MACHO
24 #define TARGET_MACHO 1
25
26 #define TARGET_VERSION fprintf (stderr, " (i686 Darwin)");
27
28 #undef  TARGET_64BIT
29 #define TARGET_64BIT OPTION_ISA_64BIT
30
31 #ifdef IN_LIBGCC2
32 #undef TARGET_64BIT
33 #ifdef __x86_64__
34 #define TARGET_64BIT 1
35 #else
36 #define TARGET_64BIT 0
37 #endif
38 #endif
39
40 /* Size of the Obj-C jump buffer.  */
41 #define OBJC_JBLEN ((TARGET_64BIT) ? ((9 * 2) + 3 + 16) : (18))
42
43 #undef TARGET_FPMATH_DEFAULT
44 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
45
46 #define TARGET_OS_CPP_BUILTINS()                \
47   do                                            \
48     {                                           \
49       builtin_define ("__LITTLE_ENDIAN__");     \
50       darwin_cpp_builtins (pfile);              \
51     }                                           \
52   while (0)
53
54 #undef PTRDIFF_TYPE
55 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
56
57 #undef WCHAR_TYPE
58 #define WCHAR_TYPE "int"
59
60 #undef WCHAR_TYPE_SIZE
61 #define WCHAR_TYPE_SIZE 32
62
63 #undef MAX_BITS_PER_WORD
64 #define MAX_BITS_PER_WORD 64
65
66 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
67 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
68
69 #undef TARGET_KEEPS_VECTOR_ALIGNED_STACK
70 #define TARGET_KEEPS_VECTOR_ALIGNED_STACK 1
71
72 /* On Darwin, the stack is 128-bit aligned at the point of every call.
73    Failure to ensure this will lead to a crash in the system libraries
74    or dynamic loader.  */
75 #undef STACK_BOUNDARY
76 #define STACK_BOUNDARY 128
77
78 /* Since we'll never want a stack boundary less aligned than 128 bits
79    we need the extra work here otherwise bits of gcc get very grumpy
80    when we ask for lower alignment.  We could just reject values less
81    than 128 bits for Darwin, but it's easier to up the alignment if
82    it's below the minimum.  */
83 #undef PREFERRED_STACK_BOUNDARY
84 #define PREFERRED_STACK_BOUNDARY (ix86_preferred_stack_boundary > 128   \
85                                   ? ix86_preferred_stack_boundary       \
86                                   : 128)
87
88 /* We want -fPIC by default, unless we're using -static to compile for
89    the kernel or some such.  */
90
91 #undef CC1_SPEC
92 #define CC1_SPEC "%{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
93   %{!mmacosx-version-min=*:-mmacosx-version-min=%(darwin_minversion)} \
94   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
95
96 #undef ASM_SPEC
97 #define ASM_SPEC "-arch %(darwin_arch) -force_cpusubtype_ALL"
98
99 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
100 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
101
102 /* Determine a minimum version based on compiler options.  */
103 #define DARWIN_MINVERSION_SPEC                          \
104  "%{!m64|fgnu-runtime:10.4;                             \
105     ,objective-c|,objc-cpp-output:10.5;                 \
106     ,objective-c-header:10.5;                           \
107     ,objective-c++|,objective-c++-cpp-output:10.5;      \
108     ,objective-c++-header|,objc++-cpp-output:10.5;      \
109     :10.4}"
110
111 #undef SUBTARGET_EXTRA_SPECS
112 #define SUBTARGET_EXTRA_SPECS                                   \
113   DARWIN_EXTRA_SPECS                                            \
114   { "darwin_arch", DARWIN_ARCH_SPEC },                          \
115   { "darwin_crt2", "" },                                        \
116   { "darwin_subarch", DARWIN_SUBARCH_SPEC },
117
118 /* Use the following macro for any Darwin/x86-specific command-line option
119    translation.  */
120 #define SUBTARGET_OPTION_TRANSLATE_TABLE \
121   { "", "" }
122
123 /* The Darwin assembler mostly follows AT&T syntax.  */
124 #undef ASSEMBLER_DIALECT
125 #define ASSEMBLER_DIALECT ASM_ATT
126
127 /* Define macro used to output shift-double opcodes when the shift
128    count is in %cl.  Some assemblers require %cl as an argument;
129    some don't.  This macro controls what to do: by default, don't
130    print %cl.  */
131
132 #define SHIFT_DOUBLE_OMITS_COUNT 0
133
134 extern void darwin_x86_file_end (void);
135 #undef TARGET_ASM_FILE_END
136 #define TARGET_ASM_FILE_END darwin_x86_file_end
137
138 /* Define the syntax of pseudo-ops, labels and comments.  */
139
140 /* String containing the assembler's comment-starter.  */
141
142 #define ASM_COMMENT_START "#"
143
144 /* By default, target has a 80387, uses IEEE compatible arithmetic,
145    and returns float values in the 387.  */
146
147 #undef TARGET_SUBTARGET_DEFAULT
148 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
149
150 /* For darwin we want to target specific processor features as a minimum,
151    but these unfortunately don't correspond to a specific processor.  */
152 #undef TARGET_SUBTARGET32_ISA_DEFAULT
153 #define TARGET_SUBTARGET32_ISA_DEFAULT (OPTION_MASK_ISA_MMX             \
154                                         | OPTION_MASK_ISA_SSE           \
155                                         | OPTION_MASK_ISA_SSE2)
156
157 #undef TARGET_SUBTARGET64_ISA_DEFAULT
158 #define TARGET_SUBTARGET64_ISA_DEFAULT (OPTION_MASK_ISA_MMX             \
159                                         | OPTION_MASK_ISA_SSE           \
160                                         | OPTION_MASK_ISA_SSE2          \
161                                         | OPTION_MASK_ISA_SSE3)
162
163 /* For now, disable dynamic-no-pic.  We'll need to go through i386.c
164    with a fine-tooth comb looking for refs to flag_pic!  */
165 #define MASK_MACHO_DYNAMIC_NO_PIC 0
166 #define TARGET_DYNAMIC_NO_PIC     (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
167
168 #undef GOT_SYMBOL_NAME
169 #define GOT_SYMBOL_NAME (machopic_function_base_name ())
170
171 /* Define the syntax of pseudo-ops, labels and comments.  */
172
173 #define LPREFIX "L"
174
175 /* These are used by -fbranch-probabilities */
176 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
177 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
178                               "__TEXT,__unlikely,regular,pure_instructions"
179
180 /* Assembler pseudos to introduce constants of various size.  */
181
182 #define ASM_BYTE_OP "\t.byte\t"
183 #define ASM_SHORT "\t.word\t"
184 #define ASM_LONG "\t.long\t"
185 #define ASM_QUAD "\t.quad\t"
186
187 #define SUBTARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
188
189 #undef ASM_OUTPUT_ALIGN
190 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
191  do { if ((LOG) != 0)                   \
192         {                               \
193           if (in_section == text_section) \
194             fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
195           else                          \
196             fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
197         }                               \
198     } while (0)
199
200 /* This says how to output an assembler line
201    to define a global common symbol.  */
202
203 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)  \
204 ( fputs (".comm ", (FILE)),                     \
205   assemble_name ((FILE), (NAME)),               \
206   fprintf ((FILE), ",%lu\n", (unsigned long)(ROUNDED)))
207
208 /* This says how to output an assembler line
209    to define a local common symbol.  */
210
211 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)  \
212 ( fputs (".lcomm ", (FILE)),                    \
213   assemble_name ((FILE), (NAME)),               \
214   fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
215
216 /* Darwin profiling -- call mcount.  */
217 #undef FUNCTION_PROFILER
218 #define FUNCTION_PROFILER(FILE, LABELNO)                                \
219     do {                                                                \
220       if (MACHOPIC_INDIRECT && !TARGET_64BIT)                           \
221         {                                                               \
222           const char *name = machopic_mcount_stub_name ();              \
223           fprintf (FILE, "\tcall %s\n", name+1);  /*  skip '&'  */      \
224           machopic_validate_stub_or_non_lazy_ptr (name);                \
225         }                                                               \
226       else fprintf (FILE, "\tcall mcount\n");                           \
227     } while (0)
228
229 #define C_COMMON_OVERRIDE_OPTIONS                                       \
230   do {                                                                  \
231     SUBTARGET_C_COMMON_OVERRIDE_OPTIONS;                                \
232   } while (0)
233
234 /* Darwin on x86_64 uses dwarf-2 by default.  Pre-darwin9 32-bit
235    compiles default to stabs+.  darwin9+ defaults to dwarf-2.  */
236 #ifndef DARWIN_PREFER_DWARF
237 #undef PREFERRED_DEBUGGING_TYPE
238 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
239 #endif
240
241 /* Darwin uses the standard DWARF register numbers but the default
242    register numbers for STABS.  Fortunately for 64-bit code the
243    default and the standard are the same.  */
244 #undef DBX_REGISTER_NUMBER
245 #define DBX_REGISTER_NUMBER(n)                                  \
246   (TARGET_64BIT ? dbx64_register_map[n]                         \
247    : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n]   \
248    : dbx_register_map[n])
249
250 /* Unfortunately, the 32-bit EH information also doesn't use the standard
251    DWARF register numbers.  */
252 #define DWARF2_FRAME_REG_OUT(n, for_eh)                                 \
253   (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n)    \
254    : (n) == 5 ? 4                                                       \
255    : (n) == 4 ? 5                                                       \
256    : (n) >= 11 && (n) <= 18 ? (n) + 1                                   \
257    : (n))
258
259 #undef REGISTER_TARGET_PRAGMAS
260 #define REGISTER_TARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
261
262 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
263 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
264
265 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
266    end of the instruction, but without the 4 we'd only have the right
267    address for the start of the instruction.  */
268 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
269 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE)     \
270   if (TARGET_64BIT)                                                             \
271     {                                                                           \
272       if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel)                 \
273         {                                                                       \
274            fputs (ASM_LONG, FILE);                                              \
275            assemble_name (FILE, XSTR (ADDR, 0));                                \
276            fputs ("+4@GOTPCREL", FILE);                                         \
277            goto DONE;                                                           \
278         }                                                                       \
279     }                                                                           \
280   else                                                                          \
281     {                                                                           \
282       if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1))                      \
283         {                                                                       \
284           darwin_non_lazy_pcrel (FILE, ADDR);                                   \
285           goto DONE;                                                            \
286         }                                                                       \
287     }
288
289 /* This needs to move since i386 uses the first flag and other flags are
290    used in Mach-O.  */
291 #undef MACHO_SYMBOL_FLAG_VARIABLE
292 #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)