]> gcc.gnu.org Git - gcc.git/blob - gcc/config/darwin.h
Config,Darwin: Allow for configuring Darwin to use embedded runpath.
[gcc.git] / gcc / config / darwin.h
1 /* Target definitions for Darwin (macOS) systems.
2 Copyright (C) 1989-2023 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 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
25
26 #ifndef CONFIG_DARWIN_H
27 #define CONFIG_DARWIN_H
28
29 /* The definitions in this file are common to all processor types
30 running Darwin, which is the kernel for macOS. Darwin is
31 basically a BSD user layer laid over a Mach kernel, then evolved
32 for many years (at NeXT) in parallel with other Unix systems. So
33 while the runtime is a somewhat idiosyncratic Mach-based thing,
34 other definitions look like they would for a BSD variant. */
35
36 /* Although NeXT ran on many different architectures, as of Jan 2001
37 the only supported Darwin targets are PowerPC and x86. */
38
39 /* One of Darwin's NeXT legacies is the Mach-O format, which is partly
40 like a.out and partly like COFF, with additional features like
41 multi-architecture binary support. */
42
43 #define DARWIN_X86 0
44 #define DARWIN_PPC 0
45
46 #define OBJECT_FORMAT_MACHO 1
47
48 /* Suppress g++ attempt to link in the math library automatically. */
49 #define MATH_LIBRARY ""
50
51 /* We have atexit. */
52
53 #define HAVE_ATEXIT
54
55 /* Define an empty body for the function do_global_dtors() in libgcc2.c. */
56
57 #define DO_GLOBAL_DTORS_BODY
58
59 /* Register static destructors to run from __cxa_atexit instead of putting
60 them into a .mod_term_funcs section. */
61
62 #define TARGET_DTORS_FROM_CXA_ATEXIT true
63
64 /* The string value for __SIZE_TYPE__. */
65
66 #ifndef SIZE_TYPE
67 #define SIZE_TYPE "long unsigned int"
68 #endif
69
70 /* Type used for ptrdiff_t, as a string used in a declaration. */
71
72 #undef PTRDIFF_TYPE
73 #define PTRDIFF_TYPE "int"
74
75 /* wchar_t is int. */
76
77 #undef WCHAR_TYPE
78 #define WCHAR_TYPE "int"
79 #undef WCHAR_TYPE_SIZE
80 #define WCHAR_TYPE_SIZE 32
81
82 #define INT8_TYPE "signed char"
83 #define INT16_TYPE "short int"
84 #define INT32_TYPE "int"
85 #define INT64_TYPE "long long int"
86 #define UINT8_TYPE "unsigned char"
87 #define UINT16_TYPE "short unsigned int"
88 #define UINT32_TYPE "unsigned int"
89 #define UINT64_TYPE "long long unsigned int"
90
91 #define INT_LEAST8_TYPE "signed char"
92 #define INT_LEAST16_TYPE "short int"
93 #define INT_LEAST32_TYPE "int"
94 #define INT_LEAST64_TYPE "long long int"
95 #define UINT_LEAST8_TYPE "unsigned char"
96 #define UINT_LEAST16_TYPE "short unsigned int"
97 #define UINT_LEAST32_TYPE "unsigned int"
98 #define UINT_LEAST64_TYPE "long long unsigned int"
99
100 #define INT_FAST8_TYPE "signed char"
101 #define INT_FAST16_TYPE "short int"
102 #define INT_FAST32_TYPE "int"
103 #define INT_FAST64_TYPE "long long int"
104 #define UINT_FAST8_TYPE "unsigned char"
105 #define UINT_FAST16_TYPE "short unsigned int"
106 #define UINT_FAST32_TYPE "unsigned int"
107 #define UINT_FAST64_TYPE "long long unsigned int"
108
109 #define INTPTR_TYPE "long int"
110 #define UINTPTR_TYPE "long unsigned int"
111
112 #define SIG_ATOMIC_TYPE "int"
113
114 /* Default to using the NeXT-style runtime, since that's what is
115 pre-installed on Darwin systems. */
116
117 #define NEXT_OBJC_RUNTIME 100508
118
119 /* Don't default to pcc-struct-return, because gcc is the only compiler, and
120 we want to retain compatibility with older gcc versions. */
121
122 #undef DEFAULT_PCC_STRUCT_RETURN
123 #define DEFAULT_PCC_STRUCT_RETURN 0
124
125 /* True if pragma ms_struct is in effect. */
126 extern GTY(()) int darwin_ms_struct;
127
128 /* Darwin has a user convenience feature where some linker options are exposed
129 at the driver level (so one can type "-all_load" instead of "-Wl,-all_load"
130 or "-Xlinker -all_load"). We retain this, but now these options are all
131 marked as 'Driver' and we process them as early as possible so that they
132 get allocated to the right toolchain command. There are a couple of special
133 cases where these driver opts are used multiple times, or to control
134 operations on more than one command (e.g. dynamiclib). These are handled
135 specially and we then add %<xxxx specs for the commands that _don't_ need
136 them.
137 We keep a couple of cases where a negative option originally appeared after
138 the positive alternate, potentially overriding it.
139 When we report an error with %e, it seems necessary to strip the option
140 before doing so, otherwise it survives to the cc1 command line (%e doesn't
141 appear to abort the program before this).
142 Right now there's no mechanism to split up the "variable portion" (%*) of
143 the matched spec string, so where we have some driver specs that take 2
144 or 3 arguments, these cannot be processed here, but are deferred until the
145 LINK_SPEC, where they are copied verbatim. */
146
147 #undef SUBTARGET_DRIVER_SELF_SPECS
148 #define SUBTARGET_DRIVER_SELF_SPECS \
149 "%{static|fapple-kext|mkernel:%{shared|dynamic|dynamiclib: \
150 %econflicting code generation switches}}",\
151 "%{shared|dynamiclib:-Xlinker -dylib \
152 %{allowable_client*:-Xlinker -allowable_client -Xlinker %*} \
153 %<allowable_client* \
154 %{bundle_loader*: %<bundle_loader* \
155 %e-bundle_loader not allowed with -dynamiclib} \
156 %{client_name*: %<client_name* \
157 %e-client_name not allowed with -dynamiclib} \
158 %{compatibility_version*:\
159 -Xlinker -dylib_compatibility_version -Xlinker %*} \
160 %<compatibility_version* \
161 %{current_version*:-Xlinker -dylib_current_version -Xlinker %*} \
162 %<current_version* \
163 %{install_name*:-Xlinker -dylib_install_name -Xlinker %* } \
164 %<install_name* \
165 %{keep_private_externs: %<keep_private_externs \
166 %e-keep_private_externs not allowed with -dynamiclib} \
167 %{private_bundle: %<private_bundle \
168 %e-private_bundle not allowed with -dynamiclib} \
169 }", \
170 "%{!dynamiclib:%{!shared: \
171 %{bundle_loader*:-Xlinker -bundle_loader -Xlinker %*} \
172 %<bundle_loader* \
173 %{client_name*:-Xlinker -client_name -Xlinker %*} \
174 %<client_name* \
175 %{compatibility_version*: %<compatibility_version* \
176 %e-compatibility_version only allowed with -dynamiclib} \
177 %{current_version*: %<current_version* \
178 %e-current_version only allowed with -dynamiclib} \
179 %{install_name*: %<install_name* \
180 %e-install_name only allowed with -dynamiclib} \
181 %{keep_private_externs:-Xlinker -keep_private_externs} \
182 %<keep_private_externs \
183 %{private_bundle:-Xlinker -private_bundle} \
184 %<private_bundle \
185 }}", \
186 "%{all_load:-Xlinker -all_load} %<all_load", \
187 "%{arch_errors_fatal:-Xlinker -arch_errors_fatal} \
188 %<arch_errors_fatal", \
189 "%{bind_at_load:-Xlinker -bind_at_load} %<bind_at_load", \
190 "%{bundle:%{!dynamiclib:%{!shared: -Xlinker -bundle; \
191 :%e-bundle not allowed with -shared}; \
192 :%e-bundle not allowed with -dynamiclib}}", \
193 "%{dead_strip:-Xlinker -dead_strip} %<dead_strip", \
194 "%{dylib_file*:-Xlinker -dylib_file -Xlinker %*} %<dylib_file*", \
195 "%{dylinker:-Xlinker -dylinker} %<dylinker", \
196 "%{dylinker_install_name*:-Xlinker -dylinker_install_name -Xlinker %*}\
197 %<dylinker_install_name*", \
198 "%{exported_symbols_list*:-Xlinker -exported_symbols_list -Xlinker %*}\
199 %<exported_symbols_list", \
200 "%{findirect-virtual-calls: -fapple-kext} %<findirect-virtual-calls", \
201 "%{fterminated-vtables: -fapple-kext} %<fterminated-vtables", \
202 "%{fapple-kext|mkernel:-static}", \
203 "%{filelist*:-Xlinker -filelist -Xlinker %*} %<filelist*", \
204 "%{flat_namespace:-Xlinker -flat_namespace} %<flat_namespace", \
205 "%{force_cpusubtype_ALL:-Xassembler -force_cpusubtype_ALL} ", \
206 "%{force_flat_namespace: \
207 %{!dynamiclib:-Xlinker -force_flat_namespace; \
208 :%e-force_flat_namespace not allowed with -dynamiclib}} \
209 %<force_flat_namespace", \
210 "%{framework*:-Xlinker -framework -Xlinker %*} %<framework*", \
211 "%{gfull:-g -fno-eliminate-unused-debug-symbols} %<gfull", \
212 "%{gused:-g -feliminate-unused-debug-symbols} %<gused", \
213 "%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform} \
214 %<gsplit-dwarf", \
215 "%{headerpad_max_install_names:-Xlinker -headerpad_max_install_names}\
216 %<headerpad_max_install_names", \
217 "%{image_base*:-Xlinker -image_base -Xlinker %*} %<image_base*", \
218 "%{init*:-Xlinker -init -Xlinker %*} %<init*", \
219 "%{multi_module:-Xlinker -multi_module} %<multi_module", \
220 "%{multiply_defined*:-Xlinker -multiply_defined -Xlinker %*} ", \
221 "%{multiplydefinedunused*:\
222 -Xlinker -multiply_defined_unused -Xlinker %*} \
223 %<multiplydefinedunused* ", \
224 "%{no_dead_strip_inits_and_terms:\
225 -Xlinker -no_dead_strip_inits_and_terms} \
226 %<no_dead_strip_inits_and_terms", \
227 "%{nofixprebinding:-Xlinker -nofixprebinding} %<nofixprebinding", \
228 "%{nomultidefs:-Xlinker -nomultidefs} %<nomultidefs", \
229 "%{pagezero_size*:-Xlinker -pagezero_size -Xlinker %*} \
230 %<pagezero_size", \
231 "%{prebind:-Xlinker -prebind} %<prebind", \
232 "%{noprebind:-Xlinker -noprebind} %<noprebind", \
233 "%{prebind_all_twolevel_modules:\
234 -Xlinker -prebind_all_twolevel_modules} \
235 %<prebind_all_twolevel_modules", \
236 "%{preload:-Xlinker -preload} %<preload", \
237 "%{read_only_relocs*:-Xlinker -read_only_relocs -Xlinker %*} \
238 %<read_only_relocs*", \
239 "%{rpath*: -Xlinker -rpath -Xlinker %*}", \
240 "%{seg_addr_table_filename*: \
241 -Xlinker -seg_addr_table_filename -Xlinker %*} \
242 %<seg_addr_table_filename*", \
243 "%{seg_addr_table*:-Xlinker -seg_addr_table -Xlinker %*} \
244 %<seg_addr_table*", \
245 "%{seg1addr*:-Xlinker -image_base -Xlinker %*} %<seg1addr*", \
246 "%{seglinkedit:-Xlinker -seglinkedit} %<seglinkedit", \
247 "%{noseglinkedit:-Xlinker -noseglinkedit} %<noseglinkedit", \
248 "%{segs_read_only_addr*:-Xlinker -segs_read_only_addr -Xlinker %*} \
249 %<segs_read_only_addr*", \
250 "%{segs_read_write_addr*:-Xlinker -segs_read_write_addr -Xlinker %*} \
251 %<segs_read_write_addr*", \
252 "%{single_module:-Xlinker -single_module} %<single_module", \
253 "%{sub_library*:-Xlinker -sub_library -Xlinker %*} %<sub_library*", \
254 "%{sub_umbrella*:-Xlinker -sub_umbrella -Xlinker %*} %<sub_umbrella*",\
255 "%{twolevel_namespace:-Xlinker -twolevel_namespace} \
256 %<twolevel_namespace", \
257 "%{twolevel_namespace_hints:-Xlinker -twolevel_namespace_hints} \
258 %<twolevel_namespace_hints", \
259 "%{umbrella*:-Xlinker -umbrella -Xlinker %*} %<umbrella*", \
260 "%{undefined*:-Xlinker -undefined -Xlinker %*} %<undefined*", \
261 "%{unexported_symbols_list*:\
262 -Xlinker -unexported_symbols_list -Xlinker %*} \
263 %<unexported_symbols_list*", \
264 "%{weak_reference_mismatches*:\
265 -Xlinker -weak_reference_mismatches -Xlinker %*} \
266 %<weak_reference_mismatches*", \
267 "%{whyload:-Xlinker -whyload} %<whyload", \
268 "%{whatsloaded:-Xlinker -whatsloaded} %<whatsloaded", \
269 "%{w:-Xlinker -w}", \
270 "%<y*", \
271 "%<Mach "
272
273 #if LD64_HAS_DEMANGLE
274 #define DARWIN_LD_DEMANGLE " -demangle "
275 #else
276 #define DARWIN_LD_DEMANGLE ""
277 #endif
278
279 #if LD64_HAS_EXPORT_DYNAMIC
280 #define DARWIN_RDYNAMIC "%{rdynamic:-export_dynamic}"
281 #else
282 #define DARWIN_RDYNAMIC "%{rdynamic:%nrdynamic is not supported}"
283 #endif
284
285 #if LD64_HAS_PLATFORM_VERSION
286 #define DARWIN_PLATFORM_ID \
287 "%{mmacosx-version-min=*: -platform_version macos %* 0.0} "
288 #else
289 #define DARWIN_PLATFORM_ID \
290 "%{mmacosx-version-min=*:-macosx_version_min %*} "
291 #endif
292
293 /* Code built with mdynamic-no-pic does not support PIE/PIC, so we disallow
294 these combinations; we also ensure that the no_pie option is passed to
295 ld64 on system versions that default to PIE when mdynamic-no-pic is given.
296 FIXME: we should check that the linker supports the -pie and -no_pie.
297 options. */
298 #define DARWIN_PIE_SPEC \
299 "%{pie|fpie|fPIE:\
300 %{mdynamic-no-pic: \
301 %n'-mdynamic-no-pic' overrides '-pie', '-fpie' or '-fPIE'; \
302 :%:version-compare(>= 10.5 mmacosx-version-min= -pie) }; \
303 mdynamic-no-pic:%:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } "
304
305 #define DARWIN_NOPIE_SPEC \
306 "%{no-pie|fno-pie|fno-PIE: \
307 %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) }"
308
309 #define DARWIN_CC1_SPEC \
310 "%<dynamic %<force_cpusubtype_ALL %<multiply_defined* %<dynamiclib"
311
312 /* When we are using embedded runpaths DARWIN_AT_RPATH is set. */
313 #if DARWIN_AT_RPATH
314 # define DARWIN_RPATH_LINK \
315 "%{!r:%{!nostdlib:%{!nodefaultrpaths:%(darwin_rpaths)}}}"
316 # define DARWIN_SHARED_LIBGCC "-lgcc_s.1.1"
317 #else
318 # define DARWIN_RPATH_LINK ""
319 # define DARWIN_SHARED_LIBGCC \
320 "%:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \
321 %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) "
322 #endif
323
324 #define SUBSUBTARGET_OVERRIDE_OPTIONS \
325 do { \
326 darwin_override_options (); \
327 } while (0)
328
329 #define SUBTARGET_C_COMMON_OVERRIDE_OPTIONS do { \
330 if (flag_mkernel || flag_apple_kext) \
331 { \
332 if (flag_use_cxa_atexit == 2) \
333 flag_use_cxa_atexit = 0; \
334 /* kexts should always be built without the coalesced sections \
335 because the kernel loader doesn't grok such sections. */ \
336 flag_weak = 0; \
337 /* No RTTI in kexts. */ \
338 flag_rtti = 0; \
339 } \
340 } while (0)
341
342 /* Machine dependent cpp options. Don't add more options here, add
343 them to darwin_cpp_builtins in darwin-c.cc. */
344
345 #undef CPP_SPEC
346 #define CPP_SPEC "%{static:%{!dynamic:-D__STATIC__}}%{!static:-D__DYNAMIC__}" \
347 " %{pthread:-D_REENTRANT} "
348
349 /* This is a fix for PR41260 by passing -no_compact_unwind on darwin10 and
350 later until the assembler, linker and libunwind are able to deal with the
351 output from GCC.
352
353 FIXME: we should check that the linker supports the option.
354 */
355
356 #define DARWIN_NOCOMPACT_UNWIND \
357 " %:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) "
358
359 /* In Darwin linker specs we can put -lcrt0.o and ld will search the library
360 path for crt0.o or -lcrtx.a and it will search for libcrtx.a. As for
361 other ports, we can also put xxx.{o,a}%s and get the appropriate complete
362 startfile absolute directory. This latter point is important when we want
363 to override ld's rule of .dylib being found ahead of .a and the user wants
364 the convenience library to be linked. */
365
366 /* The LINK_COMMAND spec is mostly a clone of the standard LINK_COMMAND_SPEC,
367 plus precomp, libtool, and fat build additions.
368
369 In general, random Darwin linker flags should go into LINK_SPEC
370 instead of LINK_COMMAND_SPEC. The command spec is better for
371 specifying the handling of options understood by generic Unix
372 linkers, and for positional arguments like libraries. */
373
374 #define LINK_COMMAND_SPEC_A \
375 "%{!c:%{!E:%{!S:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*: \
376 %(linker)" \
377 DARWIN_LD_DEMANGLE \
378 LINK_PLUGIN_SPEC \
379 "%{flto*:%<fcompare-debug*} \
380 %{flto} %{fno-lto} %{flto=*} \
381 %l " \
382 DARWIN_PLATFORM_ID \
383 LINK_COMPRESS_DEBUG_SPEC \
384 "%X %{s} %{t} %{Z} %{u*} \
385 %{e*} %{r} \
386 %{o*}%{!o:-o a.out} \
387 %{!r:%{!nostdlib:%{!nostartfiles:%S}}} \
388 %{L*} %(link_libgcc) %o \
389 %{!r:%{!nostdlib:%{!nodefaultlibs:\
390 %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
391 %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \
392 %{static|static-libgcc|static-libstdc++|static-libgfortran: \
393 libgomp.a%s; : -lgomp }} \
394 %{fgnu-tm: \
395 %{static|static-libgcc|static-libstdc++|static-libgfortran: \
396 libitm.a%s; : -litm }} \
397 %{%:sanitize(address): -lasan } \
398 %{%:sanitize(undefined): -lubsan } \
399 %(link_ssp) \
400 %:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef) \
401 %(link_gcc_c_sequence) \
402 %{!nodefaultexport:%{dylib|dynamiclib|bundle: \
403 %:version-compare(>= 10.11 asm_macosx_version_min= -U) \
404 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \
405 %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \
406 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \
407 %:version-compare(>= 10.11 asm_macosx_version_min= -U) \
408 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \
409 %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \
410 %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \
411 }} \
412 }}}\
413 %{!r:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} "\
414 DARWIN_PIE_SPEC \
415 DARWIN_NOPIE_SPEC \
416 DARWIN_RDYNAMIC \
417 DARWIN_NOCOMPACT_UNWIND \
418 DARWIN_RPATH_LINK \
419 "}}}}}}} %<pie %<no-pie %<rdynamic %<X %<rpath %<nodefaultrpaths "
420
421 /* Spec that controls whether the debug linker is run automatically for
422 a link step. This needs to be done if there is a source file on the
423 command line which will result in a temporary object (and debug is
424 enabled). */
425
426 #define DSYMUTIL_SPEC \
427 "%{!c:%{!E:%{!S:%{!r:%{!M:%{!MM:%{!fsyntax-only:%{!fdump=*:\
428 %{g*:%{!gctf:%{!gbtf:%{%:debug-level-gt(0): -idsym \
429 %{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm|.s|.f|.f90|\
430 .f95|.f03|.f77|.for|.F|.F90|.F95|.F03|.d: -dsym }\
431 }}}}\
432 }}}}}}}}"
433
434 #define LINK_COMMAND_SPEC LINK_COMMAND_SPEC_A DSYMUTIL_SPEC
435
436 /* Tell collect2 to run dsymutil for us as necessary. */
437 #define COLLECT_RUN_DSYMUTIL 1
438
439 /* We only want one instance of %G, since libSystem (Darwin's -lc) does not
440 depend on libgcc. */
441 #undef LINK_GCC_C_SEQUENCE_SPEC
442 #define LINK_GCC_C_SEQUENCE_SPEC \
443 "%G %{!nolibc:%L} "
444
445 /* ld64 supports a sysroot, it just has a different name and there's no easy
446 way to check for it at config time. */
447 #undef HAVE_LD_SYSROOT
448 #define HAVE_LD_SYSROOT 1
449 /* It seems the only (working) way to get a space after %R is to append a
450 dangling '/'. */
451 #define SYSROOT_SPEC "%{!isysroot*:-syslibroot %R/ } "
452
453 /* Do the same as clang, for now, and insert the sysroot for ld when an
454 isysroot is specified. */
455 #define LINK_SYSROOT_SPEC "%{isysroot*:-syslibroot %*} "
456
457 /* Suppress the addition of extra prefix paths when a sysroot is in use. */
458 #define STANDARD_STARTFILE_PREFIX_1 ""
459 #define STANDARD_STARTFILE_PREFIX_2 ""
460
461
462 /* Please keep the random linker options in alphabetical order.
463 Note that options taking arguments may appear multiple times on a command
464 line with different arguments each time, so put a * after their names so
465 all of them get passed. */
466 #define LINK_SPEC \
467 "%{static}%{!static:%{!dynamic:-dynamic}} \
468 %:remove-outfile(-ldl) \
469 %:remove-outfile(-lm) \
470 %:remove-outfile(-lpthread) \
471 %{fgnu-runtime: %{static|static-libgcc: \
472 %:replace-outfile(-lobjc libobjc-gnu.a%s); \
473 :%:replace-outfile(-lobjc -lobjc-gnu )}}\
474 %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\
475 %{static|static-libgcc|static-libquadmath:%:replace-outfile(-lquadmath libquadmath.a%s)}\
476 %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\
477 %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\
478 %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\
479 %{static|static-libgm2:%:replace-outfile(-lm2pim libm2pim.a%s)}\
480 %{static|static-libgm2:%:replace-outfile(-lm2iso libm2iso.a%s)}\
481 %{static|static-libgm2:%:replace-outfile(-lm2min libm2min.a%s)}\
482 %{static|static-libgm2:%:replace-outfile(-lm2log libm2log.a%s)}\
483 %{static|static-libgm2:%:replace-outfile(-lm2cor libm2cor.a%s)}\
484 %{force_cpusubtype_ALL:-arch %(darwin_arch)} \
485 %{!force_cpusubtype_ALL:-arch %(darwin_subarch)} "\
486 LINK_SYSROOT_SPEC \
487 "%{!multiply_defined*:%{shared-libgcc: \
488 %:version-compare(< 10.5 mmacosx-version-min= -multiply_defined) \
489 %:version-compare(< 10.5 mmacosx-version-min= suppress) }} \
490 %{sectalign*} %{sectcreate*} %{sectobjectsymbols*} %{sectorder*} \
491 %{segaddr*} %{segcreate*} %{segprot*} "
492
493 /* Machine dependent libraries. */
494
495 #define LIB_SPEC "%{!static:-lSystem}"
496
497 /* Note that by default, -lgcc_eh (which provides a statically-linked unwinder)
498 is not used. This is because, in general, we need to unwind through system
499 libraries that are linked with the shared unwinder in libunwind (or libgcc_s
500 for OSX 10.4/5 [darwin8/9]).
501
502 When -static-libgcc is forced: < 10.6, use the unwinder in libgcc_eh (and
503 find the emultls impl. there too).
504
505 For -static-libgcc: >= 10.6, the unwinder *still* comes from libSystem and
506 we find the emutls impl from lemutls_w. In either case, the builtins etc.
507 are linked from -lgcc. The eh library is still available so that it could
508 be specified explicitly if there is some reason to do so.
509
510 When we have specified shared-libgcc or any case that might require
511 exceptions, we pull the libgcc content (including emulated tls) from
512 -lgcc_s.1.1 in GCC and the unwinder from /usr/lib/libgcc_s.1 for < 10.6 and
513 libSystem for >= 10.6 respectively.
514 Otherwise, we just link the emutls/builtins from convenience libs.
515
516 We have to work around that DYLD_XXXX are disabled in macOS 10.11+ which
517 means that any bootstrap trying to use a shared libgcc with a bumped SO-
518 name will fail. This means that we do not accept shared libgcc for these
519 versions (the primary reason for forcing a shared libgcc was that it
520 contained the unwinder on Darwin8 and 9).
521
522 When using the shared version of gcc_s.1.1 the unwinder is provided by:
523 * Prior to 10.3.9, then we have to link the static eh lib, since there
524 is no shared unwinder version on the system.
525 * from 10.3.9 to 10.5, from /usr/lib/libgcc_s.1.dylib
526 * from 10.6 onwards, from libSystem.dylib
527 */
528 #undef REAL_LIBGCC_SPEC
529 #define REAL_LIBGCC_SPEC \
530 "%{static-libgcc|static: \
531 %:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh) \
532 %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w); \
533 shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \
534 " DARWIN_SHARED_LIBGCC " \
535 %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \
536 %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \
537 %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5); \
538 : -lemutls_w \
539 } -lgcc "
540
541 /* We specify crt0.o as -lcrt0.o so that ld will search the library path. */
542
543 #undef STARTFILE_SPEC
544 #define STARTFILE_SPEC \
545 "%{dynamiclib|shared: %(darwin_dylib1) %{fgnu-tm: -lcrttms.o}} \
546 %{!dynamiclib:%{!shared:%{bundle:%(darwin_bundle1)} \
547 %{!bundle:%{pg:%{static:-lgcrt0.o} \
548 %{!static:%{object:-lgcrt0.o} \
549 %{!object:%{preload:-lgcrt0.o} \
550 %{!preload:-lgcrt1.o \
551 %:version-compare(>= 10.8 mmacosx-version-min= -no_new_main) \
552 %(darwin_crt2)}}}} \
553 %{!pg:%{static:-lcrt0.o} \
554 %{!static:%{object:-lcrt0.o} \
555 %{!object:%{preload:-lcrt0.o} \
556 %{!preload: %(darwin_crt1) \
557 %(darwin_crt2)}}}}}}} \
558 %(darwin_crt3) "
559
560 /* We want a destructor last in the list. */
561 #define TM_DESTRUCTOR "%{fgnu-tm: -lcrttme.o}"
562 #define ENDFILE_SPEC TM_DESTRUCTOR
563
564 #define DARWIN_EXTRA_SPECS \
565 { "darwin_crt1", DARWIN_CRT1_SPEC }, \
566 { "darwin_crt2", DARWIN_CRT2_SPEC }, \
567 { "darwin_crt3", DARWIN_CRT3_SPEC }, \
568 { "darwin_dylib1", DARWIN_DYLIB1_SPEC }, \
569 { "darwin_bundle1", DARWIN_BUNDLE1_SPEC }, \
570 { "darwin_rpaths", DARWIN_RPATH_SPEC },
571
572 #define DARWIN_CRT1_SPEC \
573 "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o) \
574 %:version-compare(>< 10.5 10.6 mmacosx-version-min= -lcrt1.10.5.o) \
575 %:version-compare(>< 10.6 10.8 mmacosx-version-min= -lcrt1.10.6.o) \
576 %{fgnu-tm: -lcrttms.o}"
577
578 #define DARWIN_CRT2_SPEC ""
579
580 /* crt3.o provides __cxa_atexit on systems that don't have it (and a fix
581 up for faulty versions on 10.4). Since it's only used with C++, which
582 requires passing -shared-libgcc, key off that to avoid unnecessarily
583 adding a destructor to every program built for 10.4 or earlier. */
584
585 #define DARWIN_CRT3_SPEC \
586 "%{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}"
587
588 #define DARWIN_DYLIB1_SPEC \
589 "%:version-compare(!> 10.5 mmacosx-version-min= -ldylib1.o) \
590 %:version-compare(>< 10.5 10.6 mmacosx-version-min= -ldylib1.10.5.o)"
591
592 #define DARWIN_BUNDLE1_SPEC \
593 "%{!static:%:version-compare(< 10.6 mmacosx-version-min= -lbundle1.o) \
594 %{fgnu-tm: -lcrttms.o}}"
595
596 #if DARWIN_AT_RPATH
597 /* A default rpath, that picks up dependent libraries installed in the same
598 director as one being loaded. */
599 #define DARWIN_RPATH_SPEC \
600 "%:version-compare(>= 10.5 mmacosx-version-min= -rpath) \
601 %:version-compare(>= 10.5 mmacosx-version-min= @loader_path) \
602 %P "
603 #else
604 #define DARWIN_RPATH_SPEC ""
605 #endif
606
607 #ifdef HAVE_AS_MMACOSX_VERSION_MIN_OPTION
608 /* Emit macosx version (but only major). */
609 #define ASM_MMACOSX_VERSION_MIN_SPEC \
610 "%{asm_macosx_version_min=*: -mmacosx-version-min=%* } \
611 %<asm_macosx_version_min=* "
612 #else
613 #define ASM_MMACOSX_VERSION_MIN_SPEC " %<asm_macosx_version_min=* "
614 #endif
615
616 #if HAVE_GNU_AS
617 /* The options are added in gcc.cc for this case. */
618 #define ASM_OPTIONS ""
619 #else
620 /* When we detect that we're cctools or llvm as, we need to insert the right
621 additional options. Actually, currently these are the same as GAS. */
622 #define ASM_OPTIONS "%{v} %{w:-W} %{I*}"
623 #endif
624
625 /* Default Darwin ASM_SPEC, very simple. */
626 #define ASM_SPEC \
627 "%{static} -arch %(darwin_arch) " \
628 ASM_OPTIONS ASM_MMACOSX_VERSION_MIN_SPEC
629
630 #define ASM_DEBUG_SPEC ""
631 #undef ASM_DEBUG_OPTION_SPEC
632 #define ASM_DEBUG_OPTION_SPEC ""
633
634 #define ASM_FINAL_SPEC \
635 "%{gsplit-dwarf:%ngsplit-dwarf is not supported on this platform} \
636 %<gsplit-dwarf"
637
638 /* We now require C++11 to bootstrap and newer tools than those based on
639 stabs, so require DWARF-2, even if stabs is supported by the assembler. */
640
641 #define DWARF2_DEBUGGING_INFO 1
642 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
643
644 #define DEBUG_FRAME_SECTION "__DWARF,__debug_frame,regular,debug"
645 #define DEBUG_INFO_SECTION "__DWARF,__debug_info,regular,debug"
646 #define DEBUG_ABBREV_SECTION "__DWARF,__debug_abbrev,regular,debug"
647 #define DEBUG_ARANGES_SECTION "__DWARF,__debug_aranges,regular,debug"
648 #define DEBUG_MACINFO_SECTION "__DWARF,__debug_macinfo,regular,debug"
649 #define DEBUG_LINE_SECTION "__DWARF,__debug_line,regular,debug"
650 #define DEBUG_LOC_SECTION "__DWARF,__debug_loc,regular,debug"
651 #define DEBUG_LOCLISTS_SECTION "__DWARF,__debug_loclists,regular,debug"
652
653 #define DEBUG_STR_SECTION "__DWARF,__debug_str,regular,debug"
654 #define DEBUG_STR_OFFSETS_SECTION "__DWARF,__debug_str_offs,regular,debug"
655 #define DEBUG_RANGES_SECTION "__DWARF,__debug_ranges,regular,debug"
656 #define DEBUG_RNGLISTS_SECTION "__DWARF,__debug_rnglists,regular,debug"
657 #define DEBUG_MACRO_SECTION "__DWARF,__debug_macro,regular,debug"
658
659 #define DEBUG_LTO_INFO_SECTION "__GNU_DWARF_LTO,__debug_info,regular,debug"
660 #define DEBUG_LTO_ABBREV_SECTION "__GNU_DWARF_LTO,__debug_abbrev,regular,debug"
661 #define DEBUG_LTO_MACINFO_SECTION "__GNU_DWARF_LTO,__debug_macinfo,regular,debug"
662 #define DEBUG_LTO_LINE_SECTION "__GNU_DWARF_LTO,__debug_line,regular,debug"
663 #define DEBUG_LTO_STR_SECTION "__GNU_DWARF_LTO,__debug_str,regular,debug"
664 #define DEBUG_LTO_MACRO_SECTION "__GNU_DWARF_LTO,__debug_macro,regular,debug"
665
666 #define TARGET_WANT_DEBUG_PUB_SECTIONS true
667 #define DEBUG_PUBNAMES_SECTION ((debug_generate_pub_sections == 2) \
668 ? "__DWARF,__debug_gnu_pubn,regular,debug" \
669 : "__DWARF,__debug_pubnames,regular,debug")
670
671 #define DEBUG_PUBTYPES_SECTION ((debug_generate_pub_sections == 2) \
672 ? "__DWARF,__debug_gnu_pubt,regular,debug" \
673 : "__DWARF,__debug_pubtypes,regular,debug")
674
675 /* GCC's definition of 'one_only' is the same as its definition of 'weak'. */
676 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
677
678 /* Mach-O supports 'weak imports', and 'weak definitions' in coalesced
679 sections. machopic_select_section ensures that weak variables go in
680 coalesced sections. Weak aliases (or any other kind of aliases) are
681 not supported. Weak symbols that aren't visible outside the .s file
682 are not supported. */
683 #define ASM_WEAKEN_DECL(FILE, DECL, NAME, ALIAS) \
684 do { \
685 if (ALIAS) \
686 { \
687 warning (0, "alias definitions not supported in Mach-O; ignored"); \
688 break; \
689 } \
690 \
691 if (! DECL_EXTERNAL (DECL) && TREE_PUBLIC (DECL)) \
692 targetm.asm_out.globalize_label (FILE, NAME); \
693 if (DECL_EXTERNAL (DECL)) \
694 fputs ("\t.weak_reference ", FILE); \
695 else if (lookup_attribute ("weak_import", DECL_ATTRIBUTES (DECL))) \
696 break; \
697 else if (TREE_PUBLIC (DECL)) \
698 fputs ("\t.weak_definition ", FILE); \
699 else \
700 break; \
701 assemble_name (FILE, NAME); \
702 fputc ('\n', FILE); \
703 } while (0)
704
705 /* Darwin has the pthread routines in libSystem, which every program
706 links to, so there's no need for weak-ness for that. */
707 #define GTHREAD_USE_WEAK 0
708
709 /* On Darwin, we don't (at the time of writing) have linkonce sections
710 with names, so it's safe to make the class data not comdat. */
711 #define TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT hook_bool_void_false
712
713 /* For efficiency, on Darwin the RTTI information that is always
714 emitted in the standard C++ library should not be COMDAT. */
715 #define TARGET_CXX_LIBRARY_RTTI_COMDAT hook_bool_void_false
716
717 /* We make exception information linkonce. */
718 #undef TARGET_USES_WEAK_UNWIND_INFO
719 #define TARGET_USES_WEAK_UNWIND_INFO 1
720
721 /* We need to use a nonlocal label for the start of an EH frame: the
722 Darwin linker requires that a coalesced section start with a label.
723 Unfortunately, it also requires that 'debug' sections don't contain
724 labels. */
725 #undef FRAME_BEGIN_LABEL
726 #define FRAME_BEGIN_LABEL (for_eh ? "EH_frame" : "Lframe")
727
728 /* Emit a label for the FDE corresponding to DECL. EMPTY means
729 emit a label for an empty FDE. */
730 #define TARGET_ASM_EMIT_UNWIND_LABEL darwin_emit_unwind_label
731
732 /* Emit a label to separate the exception table. */
733 #define TARGET_ASM_EMIT_EXCEPT_TABLE_LABEL darwin_emit_except_table_label
734
735 /* Make an EH (personality or LDSA) symbol indirect as needed. */
736 #define TARGET_ASM_MAKE_EH_SYMBOL_INDIRECT darwin_make_eh_symbol_indirect
737
738 /* Some of Darwin's unwinders need current frame address state to be reset
739 after a DW_CFA_restore_state recovers the register values. */
740 #undef TARGET_ASM_SHOULD_RESTORE_CFA_STATE
741 #define TARGET_ASM_SHOULD_RESTORE_CFA_STATE darwin_should_restore_cfa_state
742
743 /* Our profiling scheme doesn't LP labels and counter words. */
744
745 #define NO_PROFILE_COUNTERS 1
746
747 #undef INIT_SECTION_ASM_OP
748 #define INIT_SECTION_ASM_OP ""
749
750 #undef INVOKE__main
751
752 #define TARGET_ASM_CONSTRUCTOR machopic_asm_out_constructor
753 #define TARGET_ASM_DESTRUCTOR machopic_asm_out_destructor
754
755 /* Always prefix with an underscore. */
756
757 #define USER_LABEL_PREFIX "_"
758
759 /* A dummy symbol that will be replaced with the function base name. */
760 #define MACHOPIC_FUNCTION_BASE_NAME "<pic base>"
761
762 /* Don't output a .file directive. That is only used by the assembler for
763 error reporting. */
764 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
765 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE false
766
767 #undef TARGET_ASM_FILE_END
768 #define TARGET_ASM_FILE_END darwin_file_end
769
770 /* Because Mach-O relocations have a counter from 1 to 255 for the
771 section number they apply to, it is necessary to output all
772 normal sections before the LTO sections, to make sure that the
773 sections that may have relocations always have a section number
774 smaller than 255. */
775 #undef TARGET_ASM_LTO_START
776 #define TARGET_ASM_LTO_START darwin_asm_lto_start
777 #undef TARGET_ASM_LTO_END
778 #define TARGET_ASM_LTO_END darwin_asm_lto_end
779
780 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
781 fprintf (FILE, "\t.space " HOST_WIDE_INT_PRINT_UNSIGNED"\n", SIZE)
782
783 /* Give ObjC methods pretty symbol names. */
784
785 #undef OBJC_GEN_METHOD_LABEL
786 #define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \
787 do { if (CAT_NAME) \
788 sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+', \
789 (CLASS_NAME), (CAT_NAME), (SEL_NAME)); \
790 else \
791 sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+', \
792 (CLASS_NAME), (SEL_NAME)); \
793 } while (0)
794
795 #undef ASM_DECLARE_OBJECT_NAME
796 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
797 darwin_asm_declare_object_name ((FILE), (NAME), (DECL))
798
799 /* The RTTI data (e.g., __ti4name) is common and public (and static),
800 but it does need to be referenced via indirect PIC data pointers.
801 The machopic_define_symbol calls are telling the machopic subsystem
802 that the name *is* defined in this module, so it doesn't need to
803 make them indirect. */
804
805 #undef ASM_DECLARE_FUNCTION_NAME
806 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
807 do { \
808 const char *xname = NAME; \
809 if (GET_CODE (XEXP (DECL_RTL (DECL), 0)) != SYMBOL_REF) \
810 xname = IDENTIFIER_POINTER (DECL_NAME (DECL)); \
811 if (! DECL_WEAK (DECL) \
812 && ((TREE_STATIC (DECL) \
813 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
814 || DECL_INITIAL (DECL))) \
815 machopic_define_symbol (DECL_RTL (DECL)); \
816 if ((TREE_STATIC (DECL) \
817 && (!DECL_COMMON (DECL) || !TREE_PUBLIC (DECL))) \
818 || DECL_INITIAL (DECL)) \
819 (* targetm.encode_section_info) (DECL, DECL_RTL (DECL), false); \
820 ASM_OUTPUT_FUNCTION_LABEL (FILE, xname, DECL); \
821 } while (0)
822
823 #undef TARGET_ASM_DECLARE_CONSTANT_NAME
824 #define TARGET_ASM_DECLARE_CONSTANT_NAME darwin_asm_declare_constant_name
825
826 /* Wrap new method names in quotes so the assembler doesn't gag.
827 Make Objective-C internal symbols local and in doing this, we need
828 to accommodate the name mangling done by c++ on file scope locals. */
829
830 int darwin_label_is_anonymous_local_objc_name (const char *name);
831
832 #undef ASM_OUTPUT_LABELREF
833 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
834 do { \
835 const char *xname = (NAME); \
836 if (! strcmp (xname, MACHOPIC_FUNCTION_BASE_NAME)) \
837 machopic_output_function_base_name(FILE); \
838 else if (xname[0] == '&' || xname[0] == '*') \
839 { \
840 int len = strlen (xname); \
841 if (len > 6 && !strcmp ("$stub", xname + len - 5)) \
842 machopic_validate_stub_or_non_lazy_ptr (xname); \
843 else if (len > 7 && !strcmp ("$stub\"", xname + len - 6)) \
844 machopic_validate_stub_or_non_lazy_ptr (xname); \
845 else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
846 machopic_validate_stub_or_non_lazy_ptr (xname); \
847 else if (len > 15 && !strcmp ("$non_lazy_ptr\"", xname + len - 14)) \
848 machopic_validate_stub_or_non_lazy_ptr (xname); \
849 if (xname[1] != '"' && name_needs_quotes (&xname[1])) \
850 fprintf (FILE, "\"%s\"", &xname[1]); \
851 else \
852 fputs (&xname[1], FILE); \
853 } \
854 else if (xname[0] == '+' || xname[0] == '-') \
855 fprintf (FILE, "\"%s\"", xname); \
856 else if (darwin_label_is_anonymous_local_objc_name (xname)) \
857 fprintf (FILE, "L%s", xname); \
858 else if (xname[0] != '"' && name_needs_quotes (xname)) \
859 asm_fprintf (FILE, "\"%U%s\"", xname); \
860 else \
861 asm_fprintf (FILE, "%U%s", xname); \
862 } while (0)
863
864 /* Output before executable code. */
865 #undef TEXT_SECTION_ASM_OP
866 #define TEXT_SECTION_ASM_OP "\t.text"
867
868 /* Output before writable data. */
869
870 #undef DATA_SECTION_ASM_OP
871 #define DATA_SECTION_ASM_OP "\t.data"
872
873 #undef ALIGN_ASM_OP
874 #define ALIGN_ASM_OP ".align"
875
876 #undef ASM_OUTPUT_ALIGN
877 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
878 if ((LOG) != 0) \
879 fprintf (FILE, "\t%s\t%d\n", ALIGN_ASM_OP, (LOG))
880
881 /* The maximum alignment which the object file format can support in bits
882 which depends on the OS version and whether the object is a common
883 variable. */
884
885 #undef MAX_OFILE_ALIGNMENT
886 #define MAX_OFILE_ALIGNMENT ((1U << L2_MAX_OFILE_ALIGNMENT) * 8U)
887
888 /* These are the three variants that emit referenced blank space. */
889 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
890 darwin_output_aligned_bss ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
891
892 #undef ASM_OUTPUT_ALIGNED_DECL_LOCAL
893 #define ASM_OUTPUT_ALIGNED_DECL_LOCAL(FILE, DECL, NAME, SIZE, ALIGN) \
894 darwin_asm_output_aligned_decl_local \
895 ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
896
897 #undef ASM_OUTPUT_ALIGNED_DECL_COMMON
898 #define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \
899 darwin_asm_output_aligned_decl_common \
900 ((FILE), (DECL), (NAME), (SIZE), (ALIGN))
901
902 /* The generic version, archs should over-ride where required. */
903 #define MACHOPIC_NL_SYMBOL_PTR_SECTION ".non_lazy_symbol_pointer"
904
905 /* Declare the section variables. */
906 #ifndef USED_FOR_TARGET
907 enum darwin_section_enum {
908 #define DEF_SECTION(NAME, FLAGS, DIRECTIVE, OBJC) NAME,
909 #include "darwin-sections.def"
910 #undef DEF_SECTION
911 NUM_DARWIN_SECTIONS
912 };
913 extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
914 #endif
915
916 #undef TARGET_ASM_SELECT_SECTION
917 #define TARGET_ASM_SELECT_SECTION machopic_select_section
918
919 #undef TARGET_ASM_FUNCTION_SECTION
920 #define TARGET_ASM_FUNCTION_SECTION darwin_function_section
921
922 #undef TARGET_ASM_SELECT_RTX_SECTION
923 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
924 #undef TARGET_ASM_UNIQUE_SECTION
925 #define TARGET_ASM_UNIQUE_SECTION darwin_unique_section
926 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
927 #define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
928
929 #undef TARGET_ASM_TM_CLONE_TABLE_SECTION
930 #define TARGET_ASM_TM_CLONE_TABLE_SECTION darwin_tm_clone_table_section
931
932 #undef TARGET_ASM_RELOC_RW_MASK
933 #define TARGET_ASM_RELOC_RW_MASK machopic_reloc_rw_mask
934
935 /* Globalizing directive for a label. */
936 #define GLOBAL_ASM_OP "\t.globl "
937 #define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
938
939 /* Emit an assembler directive to set visibility for a symbol. Used
940 to support visibility attribute and Darwin's private extern
941 feature. */
942 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
943 #define TARGET_ASM_ASSEMBLE_VISIBILITY darwin_assemble_visibility
944
945 /* Extra attributes for Darwin. */
946 #define SUBTARGET_ATTRIBUTE_TABLE \
947 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, \
948 affects_type_identity, handler, exclude } */ \
949 { "apple_kext_compatibility", 0, 0, false, true, false, false, \
950 darwin_handle_kext_attribute, NULL }, \
951 { "weak_import", 0, 0, true, false, false, false, \
952 darwin_handle_weak_import_attribute, NULL }
953
954 /* Make local constant labels linker-visible, so that if one follows a
955 weak_global constant, ld64 will be able to separate the atoms. */
956 #undef ASM_GENERATE_INTERNAL_LABEL
957 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
958 do { \
959 if (strcmp ("LC", PREFIX) == 0) \
960 sprintf (LABEL, "*%s%ld", "lC", (long)(NUM)); \
961 else if (strcmp ("Lubsan_data", PREFIX) == 0) \
962 sprintf (LABEL, "*%s%ld", "lubsan_data", (long)(NUM));\
963 else if (strcmp ("Lubsan_type", PREFIX) == 0) \
964 sprintf (LABEL, "*%s%ld", "lubsan_type", (long)(NUM));\
965 else if (strcmp ("LASAN", PREFIX) == 0) \
966 sprintf (LABEL, "*%s%ld", "lASAN", (long)(NUM));\
967 else if (strcmp ("LTRAMP", PREFIX) == 0) \
968 sprintf (LABEL, "*%s%ld", "lTRAMP", (long)(NUM));\
969 else \
970 sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM)); \
971 } while (0)
972
973 #undef TARGET_ASM_MARK_DECL_PRESERVED
974 #define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
975
976 /* Any port using this header needs to define the first available
977 subtarget symbol bit: SYMBOL_FLAG_SUBT_DEP. */
978
979 /* Is a variable. */
980 #define MACHO_SYMBOL_FLAG_VARIABLE (SYMBOL_FLAG_SUBT_DEP)
981 #define MACHO_SYMBOL_VARIABLE_P(RTX) \
982 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_VARIABLE) != 0)
983
984 /* Set on a symbol that must be indirected, even when there is a
985 definition in the TU. The ABI mandates that common symbols are so
986 indirected, as are weak. If 'fix-and-continue' is operational then
987 data symbols might also be. */
988
989 #define MACHO_SYMBOL_FLAG_MUST_INDIRECT ((SYMBOL_FLAG_SUBT_DEP) << 1)
990 #define MACHO_SYMBOL_MUST_INDIRECT_P(RTX) \
991 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_MUST_INDIRECT) != 0)
992
993 /* Set on a symbol with SYMBOL_FLAG_FUNCTION or MACHO_SYMBOL_FLAG_VARIABLE
994 to indicate that the function or variable is considered defined in this
995 translation unit. */
996
997 #define MACHO_SYMBOL_FLAG_DEFINED ((SYMBOL_FLAG_SUBT_DEP) << 2)
998 #define MACHO_SYMBOL_DEFINED_P(RTX) \
999 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_DEFINED) != 0)
1000
1001 /* Set on a symbol that has specified non-default visibility. */
1002
1003 #define MACHO_SYMBOL_FLAG_HIDDEN_VIS ((SYMBOL_FLAG_SUBT_DEP) << 3)
1004 #define MACHO_SYMBOL_HIDDEN_VIS_P(RTX) \
1005 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_HIDDEN_VIS) != 0)
1006
1007 /* Set on a symbol that should be made visible to the linker (overriding
1008 'L' symbol prefixes). */
1009
1010 #define MACHO_SYMBOL_FLAG_LINKER_VIS ((SYMBOL_FLAG_SUBT_DEP) << 4)
1011 #define MACHO_SYMBOL_LINKER_VIS_P(RTX) \
1012 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_LINKER_VIS) != 0)
1013
1014 /* Set on a symbol that is a pic stub or symbol indirection (i.e. the
1015 L_xxxxx${stub,non_lazy_ptr,lazy_ptr}. */
1016
1017 #define MACHO_SYMBOL_FLAG_INDIRECTION ((SYMBOL_FLAG_SUBT_DEP) << 5)
1018 #define MACHO_SYMBOL_INDIRECTION_P(RTX) \
1019 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_INDIRECTION) != 0)
1020
1021 /* Set on a symbol to indicate when fix-and-continue style code
1022 generation is being used and the symbol refers to a static symbol
1023 that should be rebound from new instances of a translation unit to
1024 the original instance of the data. */
1025
1026 #define MACHO_SYMBOL_FLAG_STATIC ((SYMBOL_FLAG_SUBT_DEP) << 6)
1027 #define MACHO_SYMBOL_STATIC_P(RTX) \
1028 ((SYMBOL_REF_FLAGS (RTX) & MACHO_SYMBOL_FLAG_STATIC) != 0)
1029
1030 /* Symbolic names for various things we might know about a symbol. */
1031
1032 enum machopic_addr_class {
1033 MACHOPIC_UNDEFINED,
1034 MACHOPIC_DEFINED_DATA,
1035 MACHOPIC_UNDEFINED_DATA,
1036 MACHOPIC_DEFINED_FUNCTION,
1037 MACHOPIC_UNDEFINED_FUNCTION
1038 };
1039
1040 /* Macros defining the various PIC cases. */
1041
1042 #undef MACHO_DYNAMIC_NO_PIC_P
1043 #define MACHO_DYNAMIC_NO_PIC_P (TARGET_MACHO_DYNAMIC_NO_PIC)
1044 #undef MACHOPIC_INDIRECT
1045 #define MACHOPIC_INDIRECT (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
1046 #define MACHOPIC_JUST_INDIRECT (MACHO_DYNAMIC_NO_PIC_P)
1047 #undef MACHOPIC_PURE
1048 #define MACHOPIC_PURE (flag_pic && ! MACHO_DYNAMIC_NO_PIC_P)
1049
1050 #undef TARGET_ENCODE_SECTION_INFO
1051 #define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info
1052 #undef TARGET_STRIP_NAME_ENCODING
1053 #define TARGET_STRIP_NAME_ENCODING default_strip_name_encoding
1054
1055 #define GEN_BINDER_NAME_FOR_STUB(BUF,STUB,STUB_LENGTH) \
1056 do { \
1057 const char *const stub_ = (STUB); \
1058 char *buffer_ = (BUF); \
1059 strcpy (buffer_, stub_); \
1060 if (stub_[0] == '"') \
1061 { \
1062 strcpy (buffer_ + (STUB_LENGTH) - 1, "_binder\""); \
1063 } \
1064 else \
1065 { \
1066 strcpy (buffer_ + (STUB_LENGTH), "_binder"); \
1067 } \
1068 } while (0)
1069
1070 #define GEN_SYMBOL_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
1071 do { \
1072 const char *const symbol_ = (SYMBOL); \
1073 char *buffer_ = (BUF); \
1074 if (name_needs_quotes (symbol_) && symbol_[0] != '"') \
1075 { \
1076 sprintf (buffer_, "\"%s\"", symbol_); \
1077 } \
1078 else \
1079 { \
1080 strcpy (buffer_, symbol_); \
1081 } \
1082 } while (0)
1083
1084 /* Given a symbol name string, create the lazy pointer version
1085 of the symbol name. */
1086
1087 #define GEN_LAZY_PTR_NAME_FOR_SYMBOL(BUF,SYMBOL,SYMBOL_LENGTH) \
1088 do { \
1089 const char *symbol_ = (SYMBOL); \
1090 char *buffer_ = (BUF); \
1091 if (symbol_[0] == '"') \
1092 { \
1093 strcpy (buffer_, "\"L"); \
1094 strcpy (buffer_ + 2, symbol_ + 1); \
1095 strcpy (buffer_ + (SYMBOL_LENGTH), "$lazy_ptr\""); \
1096 } \
1097 else if (name_needs_quotes (symbol_)) \
1098 { \
1099 strcpy (buffer_, "\"L"); \
1100 strcpy (buffer_ + 2, symbol_); \
1101 strcpy (buffer_ + (SYMBOL_LENGTH) + 2, "$lazy_ptr\""); \
1102 } \
1103 else \
1104 { \
1105 strcpy (buffer_, "L"); \
1106 strcpy (buffer_ + 1, symbol_); \
1107 strcpy (buffer_ + (SYMBOL_LENGTH) + 1, "$lazy_ptr"); \
1108 } \
1109 } while (0)
1110
1111 #define EH_FRAME_SECTION_NAME "__TEXT"
1112 #define EH_FRAME_SECTION_ATTR ",coalesced,no_toc+strip_static_syms+live_support"
1113
1114 #undef ASM_PREFERRED_EH_DATA_FORMAT
1115 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \
1116 (((CODE) == 2 && (GLOBAL) == 1) || ((CODE) == 0 && (GLOBAL) == 1) \
1117 ? (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4) : \
1118 ((CODE) == 1 || (GLOBAL) == 0) ? DW_EH_PE_pcrel : DW_EH_PE_absptr)
1119
1120 #define ASM_OUTPUT_DWARF_DELTA(FILE,SIZE,LABEL1,LABEL2) \
1121 darwin_asm_output_dwarf_delta (FILE, SIZE, LABEL1, LABEL2, 0)
1122
1123 #define ASM_OUTPUT_DWARF_OFFSET(FILE,SIZE,LABEL,OFFSET,BASE) \
1124 darwin_asm_output_dwarf_offset (FILE, SIZE, LABEL, OFFSET, BASE)
1125
1126 #define ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX(ASM_OUT_FILE, ENCODING, SIZE, ADDR, DONE) \
1127 if (ENCODING == ASM_PREFERRED_EH_DATA_FORMAT (2, 1)) { \
1128 darwin_non_lazy_pcrel (ASM_OUT_FILE, ADDR); \
1129 goto DONE; \
1130 }
1131
1132 /* Experimentally, putting jump tables in text is faster on SPEC.
1133 Also this is needed for correctness for coalesced functions. */
1134
1135 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1136 #define JUMP_TABLES_IN_TEXT_SECTION 1
1137 #endif
1138
1139 #define TARGET_TERMINATE_DW2_EH_FRAME_INFO false
1140
1141 #define TARGET_ASM_INIT_SECTIONS darwin_init_sections
1142 #undef TARGET_ASM_NAMED_SECTION
1143 #define TARGET_ASM_NAMED_SECTION darwin_asm_named_section
1144
1145 #define DARWIN_REGISTER_TARGET_PRAGMAS() \
1146 do { \
1147 if (!flag_preprocess_only) \
1148 cpp_register_pragma (parse_in, NULL, "mark", \
1149 darwin_pragma_ignore, false); \
1150 c_register_pragma (0, "options", darwin_pragma_options); \
1151 c_register_pragma (0, "segment", darwin_pragma_ignore); \
1152 c_register_pragma (0, "unused", darwin_pragma_unused); \
1153 c_register_pragma (0, "ms_struct", darwin_pragma_ms_struct); \
1154 } while (0)
1155
1156 #undef ASM_APP_ON
1157 #define ASM_APP_ON ""
1158 #undef ASM_APP_OFF
1159 #define ASM_APP_OFF ""
1160
1161 void darwin_register_frameworks (const char *, const char *, int);
1162 void darwin_register_objc_includes (const char *, const char *, int);
1163 #define TARGET_EXTRA_PRE_INCLUDES darwin_register_objc_includes
1164 #define TARGET_EXTRA_INCLUDES darwin_register_frameworks
1165
1166 void add_framework_path (char *);
1167 #define TARGET_OPTF add_framework_path
1168
1169 #define TARGET_POSIX_IO
1170
1171 #define WINT_TYPE "int"
1172
1173 /* Every program on darwin links against libSystem which contains the pthread
1174 routines, so there's no need to explicitly call out when doing threaded
1175 work. */
1176
1177 #undef GOMP_SELF_SPECS
1178 #define GOMP_SELF_SPECS ""
1179 #undef GTM_SELF_SPECS
1180 #define GTM_SELF_SPECS ""
1181
1182 /* Darwin disables section anchors by default.
1183 They should be enabled per arch where support exists in that arch. */
1184 #define TARGET_ASM_OUTPUT_ANCHOR NULL
1185 #define DARWIN_SECTION_ANCHORS 0
1186
1187 #define HAVE_ENABLE_EXECUTE_STACK
1188
1189 /* For Apple KEXTs, we make the constructors return this to match gcc
1190 2.95. */
1191 #define TARGET_CXX_CDTOR_RETURNS_THIS (darwin_kextabi_p)
1192 #define TARGET_KEXTABI flag_apple_kext
1193
1194 /* We have target-specific builtins. */
1195 #define SUBTARGET_FOLD_BUILTIN darwin_fold_builtin
1196
1197 #define TARGET_N_FORMAT_TYPES 1
1198 #define TARGET_FORMAT_TYPES darwin_additional_format_types
1199
1200 #ifndef USED_FOR_TARGET
1201 extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **);
1202 #define GCC_DRIVER_HOST_INITIALIZATION \
1203 darwin_driver_init (&decoded_options_count, &decoded_options)
1204 #endif
1205
1206 /* The Apple assembler and linker do not support constructor priorities. */
1207 #undef SUPPORTS_INIT_PRIORITY
1208 #define SUPPORTS_INIT_PRIORITY 0
1209
1210 #undef STACK_CHECK_STATIC_BUILTIN
1211 #define STACK_CHECK_STATIC_BUILTIN 1
1212
1213 /* When building cross-compilers (and native crosses) we shall default to
1214 providing an osx-version-min of this unless overridden by the User.
1215 10.5 is the only version that fully supports all our archs so that's the
1216 fall-back default. */
1217 #ifndef DEF_MIN_OSX_VERSION
1218 #define DEF_MIN_OSX_VERSION "10.5"
1219 #endif
1220
1221 /* Later versions of ld64 support coalescing weak code/data without requiring
1222 that they be placed in specially identified sections. This is the earliest
1223 _tested_ version known to support this so far. */
1224 #define MIN_LD64_NO_COAL_SECTS "236.3"
1225
1226 /* From at least version 62.1, ld64 can build symbol indirection stubs as
1227 needed, and there is no need for the compiler to emit them. */
1228 #define MIN_LD64_OMIT_STUBS "62.1"
1229
1230 /* Emit start labels for init and term sections from this version. */
1231 #define MIN_LD64_INIT_TERM_START_LABELS "136.0"
1232
1233 /* If we have no definition for the linker version, pick the minimum version
1234 that will bootstrap the compiler. */
1235 #ifndef LD64_VERSION
1236 # ifndef DEF_LD64
1237 # define LD64_VERSION "85.2.1"
1238 # else
1239 # define LD64_VERSION DEF_LD64
1240 # endif
1241 #endif
1242
1243 /* CTF and BTF support. */
1244 #undef CTF_INFO_SECTION_NAME
1245 #define CTF_INFO_SECTION_NAME "__CTF_BTF,__ctf,regular,debug"
1246 #undef BTF_INFO_SECTION_NAME
1247 #define BTF_INFO_SECTION_NAME "__CTF_BTF,__btf,regular,debug"
1248
1249 #endif /* CONFIG_DARWIN_H */
This page took 0.092687 seconds and 5 git commands to generate.