OSDN Git Service

2006-09-08 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 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 (target_flags & MASK_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 #undef TARGET_FPMATH_DEFAULT
41 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
42
43 #define TARGET_OS_CPP_BUILTINS()                \
44   do                                            \
45     {                                           \
46       builtin_define ("__LITTLE_ENDIAN__");     \
47       darwin_cpp_builtins (pfile);              \
48     }                                           \
49   while (0)
50
51 #undef PTRDIFF_TYPE
52 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
53
54 #undef WCHAR_TYPE
55 #define WCHAR_TYPE "int"
56
57 #undef WCHAR_TYPE_SIZE
58 #define WCHAR_TYPE_SIZE 32
59
60 #undef MAX_BITS_PER_WORD
61 #define MAX_BITS_PER_WORD 64
62
63 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
64 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
65
66 /* We want -fPIC by default, unless we're using -static to compile for
67    the kernel or some such.  */
68
69 #undef CC1_SPEC
70 #define CC1_SPEC "%{!static:-fPIC}\
71   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
72
73 #undef ASM_SPEC
74 #define ASM_SPEC "-arch %(darwin_arch) -force_cpusubtype_ALL"
75
76 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
77 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
78
79 #undef SUBTARGET_EXTRA_SPECS
80 #define SUBTARGET_EXTRA_SPECS                                   \
81   { "darwin_arch", DARWIN_ARCH_SPEC },                          \
82   { "darwin_crt2", "" },                                        \
83   { "darwin_subarch", DARWIN_SUBARCH_SPEC },
84
85 /* Use the following macro for any Darwin/x86-specific command-line option
86    translation.  */
87 #define SUBTARGET_OPTION_TRANSLATE_TABLE \
88   { "", "" }
89
90 /* The Darwin assembler mostly follows AT&T syntax.  */
91 #undef ASSEMBLER_DIALECT
92 #define ASSEMBLER_DIALECT ASM_ATT
93
94 /* Define macro used to output shift-double opcodes when the shift
95    count is in %cl.  Some assemblers require %cl as an argument;
96    some don't.  This macro controls what to do: by default, don't
97    print %cl.  */
98
99 #define SHIFT_DOUBLE_OMITS_COUNT 0
100
101 extern void darwin_x86_file_end (void);
102 #undef TARGET_ASM_FILE_END
103 #define TARGET_ASM_FILE_END darwin_x86_file_end
104
105 /* Define the syntax of pseudo-ops, labels and comments.  */
106
107 /* String containing the assembler's comment-starter.  */
108
109 #define ASM_COMMENT_START "#"
110
111 /* By default, target has a 80387, uses IEEE compatible arithmetic,
112    and returns float values in the 387.  */
113
114 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
115
116 /* For now, disable dynamic-no-pic.  We'll need to go through i386.c
117    with a fine-tooth comb looking for refs to flag_pic!  */
118 #define MASK_MACHO_DYNAMIC_NO_PIC 0
119 #define TARGET_DYNAMIC_NO_PIC     (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
120
121 #undef GOT_SYMBOL_NAME
122 #define GOT_SYMBOL_NAME (machopic_function_base_name ())
123
124 /* Define the syntax of pseudo-ops, labels and comments.  */
125
126 #define LPREFIX "L"
127
128 /* These are used by -fbranch-probabilities */
129 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
130 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
131                               "__TEXT,__unlikely,regular,pure_instructions"
132
133 /* Assembler pseudos to introduce constants of various size.  */
134
135 #define ASM_BYTE_OP "\t.byte\t"
136 #define ASM_SHORT "\t.word\t"
137 #define ASM_LONG "\t.long\t"
138 #define ASM_QUAD "\t.quad\t"
139
140 #define SUBTARGET_ENCODE_SECTION_INFO  darwin_encode_section_info
141
142 #undef ASM_OUTPUT_ALIGN
143 #define ASM_OUTPUT_ALIGN(FILE,LOG)      \
144  do { if ((LOG) != 0)                   \
145         {                               \
146           if (in_section == text_section) \
147             fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
148           else                          \
149             fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
150         }                               \
151     } while (0)
152
153 /* This says how to output an assembler line
154    to define a global common symbol.  */
155
156 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)  \
157 ( fputs (".comm ", (FILE)),                     \
158   assemble_name ((FILE), (NAME)),               \
159   fprintf ((FILE), ",%lu\n", (unsigned long)(ROUNDED)))
160
161 /* This says how to output an assembler line
162    to define a local common symbol.  */
163
164 #define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED)  \
165 ( fputs (".lcomm ", (FILE)),                    \
166   assemble_name ((FILE), (NAME)),               \
167   fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", (ROUNDED)))
168
169 /* Darwin profiling -- call mcount.  */
170 #undef FUNCTION_PROFILER
171 #define FUNCTION_PROFILER(FILE, LABELNO)                                \
172     do {                                                                \
173       if (MACHOPIC_INDIRECT && !TARGET_64BIT)                           \
174         {                                                               \
175           const char *name = machopic_mcount_stub_name ();              \
176           fprintf (FILE, "\tcall %s\n", name+1);  /*  skip '&'  */      \
177           machopic_validate_stub_or_non_lazy_ptr (name);                \
178         }                                                               \
179       else fprintf (FILE, "\tcall mcount\n");                           \
180     } while (0)
181
182 /* Darwin on x86_64 uses dwarf-2 by default.  */
183 #undef PREFERRED_DEBUGGING_TYPE
184 #define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
185
186 /* Darwin uses the standard DWARF register numbers but the default
187    register numbers for STABS.  Fortunately for 64-bit code the
188    default and the standard are the same.  */
189 #undef DBX_REGISTER_NUMBER
190 #define DBX_REGISTER_NUMBER(n)                                  \
191   (TARGET_64BIT ? dbx64_register_map[n]                         \
192    : write_symbols == DWARF2_DEBUG ? svr4_dbx_register_map[n]   \
193    : dbx_register_map[n])
194
195 /* Unfortunately, the 32-bit EH information also doesn't use the standard
196    DWARF register numbers.  */
197 #define DWARF2_FRAME_REG_OUT(n, for_eh)                                 \
198   (! (for_eh) || write_symbols != DWARF2_DEBUG || TARGET_64BIT ? (n)    \
199    : (n) == 5 ? 4                                                       \
200    : (n) == 4 ? 5                                                       \
201    : (n) >= 11 && (n) <= 18 ? (n) + 1                                   \
202    : (n))
203
204 /* Attempt to turn on execute permission for the stack.  This may be
205     used by INITIALIZE_TRAMPOLINE of the target needs it (that is,
206     if the target machine can change execute permissions on a page).
207
208     There is no way to query the execute permission of the stack, so
209     we always issue the mprotect() call.
210
211     Note that we go out of our way to use namespace-non-invasive calls
212     here.  Unfortunately, there is no libc-internal name for mprotect().
213
214     Also note that no errors should be emitted by this code; it is
215     considered dangerous for library calls to send messages to
216     stdout/stderr.  */
217
218 #define ENABLE_EXECUTE_STACK                                            \
219 extern void __enable_execute_stack (void *);                            \
220 void                                                                    \
221 __enable_execute_stack (void *addr)                                     \
222 {                                                                       \
223    extern int mprotect (void *, size_t, int);                           \
224    extern int __sysctl (int *, unsigned int, void *, size_t *,          \
225                        void *, size_t);                                 \
226                                                                         \
227    static int size;                                                     \
228    static long mask;                                                    \
229                                                                         \
230    char *page, *end;                                                    \
231                                                                         \
232    if (size == 0)                                                       \
233      {                                                                  \
234        int mib[2];                                                      \
235        size_t len;                                                      \
236                                                                         \
237        mib[0] = 6; /* CTL_HW */                                         \
238        mib[1] = 7; /* HW_PAGESIZE */                                    \
239        len = sizeof (size);                                             \
240        (void) __sysctl (mib, 2, &size, &len, NULL, 0);                  \
241        mask = ~((long) size - 1);                                       \
242      }                                                                  \
243                                                                         \
244    page = (char *) (((long) addr) & mask);                              \
245    end  = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
246                                                                         \
247    /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */                        \
248    (void) mprotect (page, end - page, 7);                               \
249 }
250
251 #undef REGISTER_TARGET_PRAGMAS
252 #define REGISTER_TARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
253
254 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
255 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
256
257 /* For 64-bit, we need to add 4 because @GOTPCREL is relative to the
258    end of the instruction, but without the 4 we'd only have the right
259    address for the start of the instruction.  */
260 #undef ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX
261 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(FILE, ENCODING, SIZE, ADDR, DONE)     \
262   if (TARGET_64BIT)                                                             \
263     {                                                                           \
264       if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel)                 \
265         {                                                                       \
266            fputs (ASM_LONG, FILE);                                              \
267            assemble_name (FILE, XSTR (ADDR, 0));                                \
268            fputs ("+4@GOTPCREL", FILE);                                         \
269            goto DONE;                                                           \
270         }                                                                       \
271     }                                                                           \
272   else                                                                          \
273     {                                                                           \
274       if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1))                      \
275         {                                                                       \
276           darwin_non_lazy_pcrel (FILE, ADDR);                                   \
277           goto DONE;                                                            \
278         }                                                                       \
279     }
280
281 /* This needs to move since i386 uses the first flag and other flags are
282    used in Mach-O.  */
283 #undef MACHO_SYMBOL_FLAG_VARIABLE
284 #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)