1 /* Target definitions for x86 running Darwin.
2 Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
3 Contributed by Apple Computer Inc.
5 This file is part of GCC.
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)
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.
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. */
22 /* Enable Mach-O bits in generic x86 code. */
24 #define TARGET_MACHO 1
26 #define TARGET_VERSION fprintf (stderr, " (i686 Darwin)");
29 #define TARGET_64BIT (target_flags & MASK_64BIT)
34 #define TARGET_64BIT 1
36 #define TARGET_64BIT 0
40 #undef TARGET_FPMATH_DEFAULT
41 #define TARGET_FPMATH_DEFAULT (TARGET_SSE ? FPMATH_SSE : FPMATH_387)
43 #define TARGET_OS_CPP_BUILTINS() \
46 builtin_define ("__LITTLE_ENDIAN__"); \
47 darwin_cpp_builtins (pfile); \
52 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
55 #define WCHAR_TYPE "int"
57 #undef WCHAR_TYPE_SIZE
58 #define WCHAR_TYPE_SIZE 32
60 #undef MAX_BITS_PER_WORD
61 #define MAX_BITS_PER_WORD 64
63 #undef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
64 #define FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN (0)
66 /* We want -fPIC by default, unless we're using -static to compile for
67 the kernel or some such. */
70 #define CC1_SPEC "%{!static:-fPIC}\
71 %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
74 #define ASM_SPEC "-arch %(darwin_arch) -force_cpusubtype_ALL"
76 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
77 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
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 },
85 /* Use the following macro for any Darwin/x86-specific command-line option
87 #define SUBTARGET_OPTION_TRANSLATE_TABLE \
90 /* The Darwin assembler mostly follows AT&T syntax. */
91 #undef ASSEMBLER_DIALECT
92 #define ASSEMBLER_DIALECT ASM_ATT
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
99 #define SHIFT_DOUBLE_OMITS_COUNT 0
101 extern void darwin_x86_file_end (void);
102 #undef TARGET_ASM_FILE_END
103 #define TARGET_ASM_FILE_END darwin_x86_file_end
105 /* Define the syntax of pseudo-ops, labels and comments. */
107 /* String containing the assembler's comment-starter. */
109 #define ASM_COMMENT_START "#"
111 /* By default, target has a 80387, uses IEEE compatible arithmetic,
112 and returns float values in the 387. */
114 #define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_128BIT_LONG_DOUBLE)
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)
121 #undef GOT_SYMBOL_NAME
122 #define GOT_SYMBOL_NAME (machopic_function_base_name ())
124 /* Define the syntax of pseudo-ops, labels and comments. */
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"
133 /* Assembler pseudos to introduce constants of various size. */
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"
140 #define SUBTARGET_ENCODE_SECTION_INFO darwin_encode_section_info
142 #undef ASM_OUTPUT_ALIGN
143 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
144 do { if ((LOG) != 0) \
146 if (in_section == text_section) \
147 fprintf (FILE, "\t%s %d,0x90\n", ALIGN_ASM_OP, (LOG)); \
149 fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)); \
153 /* This says how to output an assembler line
154 to define a global common symbol. */
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)))
161 /* This says how to output an assembler line
162 to define a local common symbol. */
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)))
169 /* Darwin profiling -- call mcount. */
170 #undef FUNCTION_PROFILER
171 #define FUNCTION_PROFILER(FILE, LABELNO) \
173 if (MACHOPIC_INDIRECT && !TARGET_64BIT) \
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); \
179 else fprintf (FILE, "\tcall mcount\n"); \
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)
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])
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) \
201 : (n) >= 11 && (n) <= 18 ? (n) + 1 \
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).
208 There is no way to query the execute permission of the stack, so
209 we always issue the mprotect() call.
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().
214 Also note that no errors should be emitted by this code; it is
215 considered dangerous for library calls to send messages to
218 #define ENABLE_EXECUTE_STACK \
219 extern void __enable_execute_stack (void *); \
221 __enable_execute_stack (void *addr) \
223 extern int mprotect (void *, size_t, int); \
224 extern int __sysctl (int *, unsigned int, void *, size_t *, \
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); \
244 page = (char *) (((long) addr) & mask); \
245 end = (char *) ((((long) (addr + TRAMPOLINE_SIZE)) & mask) + size); \
247 /* 7 == PROT_READ | PROT_WRITE | PROT_EXEC */ \
248 (void) mprotect (page, end - page, 7); \
251 #undef REGISTER_TARGET_PRAGMAS
252 #define REGISTER_TARGET_PRAGMAS() DARWIN_REGISTER_TARGET_PRAGMAS()
254 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
255 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES darwin_set_default_type_attributes
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) \
264 if ((SIZE) == 4 && ((ENCODING) & 0x70) == DW_EH_PE_pcrel) \
266 fputs (ASM_LONG, FILE); \
267 assemble_name (FILE, XSTR (ADDR, 0)); \
268 fputs ("+4@GOTPCREL", FILE); \
274 if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) \
276 darwin_non_lazy_pcrel (FILE, ADDR); \
281 /* This needs to move since i386 uses the first flag and other flags are
283 #undef MACHO_SYMBOL_FLAG_VARIABLE
284 #define MACHO_SYMBOL_FLAG_VARIABLE ((SYMBOL_FLAG_MACH_DEP) << 3)