1 /* Definitions of target machine for GNU compiler, for HPs running
2 HPUX using the 64bit runtime model.
3 Copyright (C) 1999-2013 Free Software Foundation, 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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* We can debug dynamically linked executables on hpux11; we also
22 want dereferencing of a NULL pointer to cause a SEGV. Do not move
23 the "+Accept TypeMismatch" switch. We check for it in collect2
24 to determine which init/fini is needed. */
26 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
28 "%{!shared:%{p:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
29 %nwarning: consider linking with '-static' as system libraries with\n\
30 %n profiling support are only provided in archive format}}}\
31 %{!shared:%{pg:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
32 %nwarning: consider linking with '-static' as system libraries with\n\
33 %n profiling support are only provided in archive format}}}\
34 %{!shared:%{!static:%{rdynamic:-E}}}\
35 %{mhp-ld:+Accept TypeMismatch -z} %{mlinker-opt:-O}\
36 %{!shared:-u main %{!nostdlib:%{!nodefaultlibs:-u __cxa_finalize}}}\
37 %{static:-a archive} %{shared:%{mhp-ld:-b}%{!mhp-ld:-shared}}"
40 "%{!shared:%{p:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
41 %nwarning: consider linking with '-static' as system libraries with\n\
42 %n profiling support are only provided in archive format}}}\
43 %{!shared:%{pg:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
44 %nwarning: consider linking with '-static' as system libraries with\n\
45 %n profiling support are only provided in archive format}}}\
46 %{!shared:%{!static:%{rdynamic:-E}}}\
47 %{!mgnu-ld:+Accept TypeMismatch -z} %{mlinker-opt:-O}\
48 %{!shared:-u main %{!nostdlib:%{!nodefaultlibs:-u __cxa_finalize}}}\
49 %{static:-a archive} %{shared:%{mgnu-ld:-shared}%{!mgnu-ld:-b}}"
52 /* Profiling support is only provided in libc.a. However, libprof and
53 libgprof are only available in shared form on HP-UX 11.00. We use
54 the shared form if we are using the GNU linker or an archive form
55 isn't available. We also usually need to link with libdld and it's
56 only available in shared form. */
58 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
61 %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
62 %{mt|pthread:-lpthread} -lc\
63 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
64 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
65 %{p:%{!pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
66 -lprof %{static:-a archive}\
67 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
68 %{mt|pthread:-lpthread} -lc\
69 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
70 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
71 %{pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
72 -lgprof %{static:-a archive}\
73 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
74 %{mt|pthread:-lpthread} -lc\
75 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
76 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
77 %{shared:%{mt|pthread:-lpthread}}"
81 %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
82 %{mt|pthread:-lpthread} -lc\
83 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
84 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
85 %{p:%{!pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
86 -lprof %{static:-a archive}\
87 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
88 %{mt|pthread:-lpthread} -lc\
89 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
90 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
91 %{pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
92 -lgprof %{static:-a archive}\
93 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
94 %{mt|pthread:-lpthread} -lc\
95 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
96 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
97 %{shared:%{mt|pthread:-lpthread}}"
100 /* The libgcc_stub.a and milli.a libraries need to come last. */
101 #undef LINK_GCC_C_SEQUENCE_SPEC
102 #define LINK_GCC_C_SEQUENCE_SPEC "\
103 %G %L %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}\
106 /* Under hpux11, the normal location of the `ld' and `as' programs is the
107 /usr/ccs/bin directory. */
109 #ifndef CROSS_DIRECTORY_STRUCTURE
110 #undef MD_EXEC_PREFIX
111 #define MD_EXEC_PREFIX "/usr/ccs/bin"
114 /* Default prefixes. */
116 #undef STANDARD_STARTFILE_PREFIX_1
117 #define STANDARD_STARTFILE_PREFIX_1 "/lib/pa20_64/"
119 #undef STANDARD_STARTFILE_PREFIX_2
120 #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/pa20_64/"
122 /* Under hpux11 the normal location of the various pa20_64 *crt*.o files
123 is the /usr/ccs/lib/pa20_64 directory. Some files may also be in the
124 /opt/langtools/lib/pa20_64 directory. */
126 #ifndef CROSS_DIRECTORY_STRUCTURE
127 #undef MD_STARTFILE_PREFIX
128 #define MD_STARTFILE_PREFIX "/usr/ccs/lib/pa20_64/"
131 #ifndef CROSS_DIRECTORY_STRUCTURE
132 #undef MD_STARTFILE_PREFIX_1
133 #define MD_STARTFILE_PREFIX_1 "/opt/langtools/lib/pa20_64/"
136 /* This macro specifies the biggest alignment supported by the object
137 file format of this machine.
139 The .align directive in the HP assembler allows alignments up to
140 4096 bytes. However, the maximum alignment of a global common symbol
141 is 16 bytes using HP ld. Unfortunately, this macro doesn't provide
142 a method to check for common symbols. */
143 #undef MAX_OFILE_ALIGNMENT
144 #define MAX_OFILE_ALIGNMENT 32768
146 /* Due to limitations in the target structure, it isn't currently possible
147 to dynamically switch between the GNU and HP assemblers. */
150 /* Configure selects the standard ELFOS defines for use with GAS. */
153 /* We are using GAS. */
156 #undef TARGET_ASM_FILE_START
157 #define TARGET_ASM_FILE_START pa_hpux64_gas_file_start
159 /* This is how we output a null terminated string. */
161 #define STRING_ASM_OP "\t.stringz\t"
163 #define TEXT_SECTION_ASM_OP "\t.text"
164 #define DATA_SECTION_ASM_OP "\t.data"
165 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
167 #define JCR_SECTION_NAME ".jcr"
169 #define HP_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init"
170 #define GNU_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init_array"
171 #define HP_FINI_ARRAY_SECTION_ASM_OP "\t.section\t.fini"
172 #define GNU_FINI_ARRAY_SECTION_ASM_OP "\t.section\t.fini_array"
174 /* We need to override the following two macros defined in elfos.h since
175 the .comm directive has a different syntax and it can't be used for
176 local common symbols. */
177 #undef ASM_OUTPUT_ALIGNED_COMMON
178 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
179 pa_asm_output_aligned_common (FILE, NAME, SIZE, ALIGN)
181 #undef ASM_OUTPUT_ALIGNED_LOCAL
182 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
183 pa_asm_output_aligned_local (FILE, NAME, SIZE, ALIGN)
185 /* The define in pa.h doesn't work with the alias attribute. The
186 default is ok with the following define for GLOBAL_ASM_OP. */
187 #undef TARGET_ASM_GLOBALIZE_LABEL
189 /* This is how we globalize a label. */
190 #define GLOBAL_ASM_OP "\t.globl\t"
192 /* Hacked version from defaults.h that uses assemble_name_raw
193 instead of assemble_name. A symbol in a type directive that
194 isn't otherwise referenced doesn't cause the symbol to be
195 placed in the symbol table of the assembled object. */
196 #undef ASM_OUTPUT_TYPE_DIRECTIVE
197 #define ASM_OUTPUT_TYPE_DIRECTIVE(STREAM, NAME, TYPE) \
199 fputs (TYPE_ASM_OP, STREAM); \
200 assemble_name_raw (STREAM, NAME); \
201 fputs (", ", STREAM); \
202 fprintf (STREAM, TYPE_OPERAND_FMT, TYPE); \
203 putc ('\n', STREAM); \
206 /* Hacked version from elfos.h that doesn't output a label. */
207 #undef ASM_DECLARE_FUNCTION_NAME
208 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
210 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
211 ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \
214 /* The type of external references must be set correctly for the
215 dynamic loader to work correctly. This is equivalent to the
216 HP assembler's .IMPORT directive but relates more directly to
217 ELF object file types. */
218 #undef ASM_OUTPUT_EXTERNAL
219 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
220 pa_hpux_asm_output_external ((FILE), (DECL), (NAME))
221 #define ASM_OUTPUT_EXTERNAL_REAL(FILE, DECL, NAME) \
223 if (FUNCTION_NAME_P (NAME)) \
224 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
226 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
227 default_elf_asm_output_external (FILE, DECL, NAME); \
230 /* We need set the type for external libcalls. Also note that not all
231 libcall names are passed to targetm.encode_section_info (e.g., __main).
232 Thus, we also have to do the section encoding if it hasn't been done
234 #undef ASM_OUTPUT_EXTERNAL_LIBCALL
235 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
237 if (!FUNCTION_NAME_P (XSTR (FUN, 0))) \
238 pa_encode_label (FUN); \
239 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, XSTR (FUN, 0), "function"); \
242 /* We need to use the HP style for internal labels. */
243 #undef ASM_GENERATE_INTERNAL_LABEL
244 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
245 sprintf (LABEL, "*%c$%s%04ld", (PREFIX)[0], (PREFIX) + 1, (long)(NUM))
247 #else /* USING_ELFOS_H */
249 /* We are not using GAS. */
252 /* HPUX 11 has the "new" HP assembler. It's still lousy, but it's a whole
253 lot better than the assembler shipped with older versions of hpux.
254 However, it doesn't support weak symbols and is a bad fit with ELF. */
255 #undef NEW_HP_ASSEMBLER
256 #define NEW_HP_ASSEMBLER 1
258 /* It looks like DWARF2 will be the easiest debug format to handle on this
260 #define DWARF2_DEBUGGING_INFO 1
261 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
263 /* This target uses the ELF object file format. */
264 #define OBJECT_FORMAT_ELF
266 #undef TARGET_ASM_FILE_START
267 #define TARGET_ASM_FILE_START pa_hpux64_hpas_file_start
269 #undef TEXT_SECTION_ASM_OP
270 #define TEXT_SECTION_ASM_OP "\t.SUBSPA $CODE$\n"
271 #undef READONLY_DATA_SECTION_ASM_OP
272 #define READONLY_DATA_SECTION_ASM_OP "\t.SUBSPA $LIT$\n"
273 #undef DATA_SECTION_ASM_OP
274 #define DATA_SECTION_ASM_OP "\t.SUBSPA $DATA$\n"
275 #undef BSS_SECTION_ASM_OP
276 #define BSS_SECTION_ASM_OP "\t.SUBSPA $BSS$\n"
278 /* We provide explicit defines for CTORS_SECTION_ASM_OP and
279 DTORS_SECTION_ASM_OP since we don't yet have support for
280 named sections with the HP assembler. */
281 #undef CTORS_SECTION_ASM_OP
282 #define CTORS_SECTION_ASM_OP "\t.SUBSPA \\.ctors,QUAD=1,ALIGN=8,ACCESS=31"
283 #undef DTORS_SECTION_ASM_OP
284 #define DTORS_SECTION_ASM_OP "\t.SUBSPA \\.dtors,QUAD=1,ALIGN=8,ACCESS=31"
286 #define HP_INIT_ARRAY_SECTION_ASM_OP \
287 "\t.SUBSPA \\.init,QUAD=1,ALIGN=8,ACCESS=31"
288 #define GNU_INIT_ARRAY_SECTION_ASM_OP \
289 "\t.SUBSPA \\.init_array,QUAD=1,ALIGN=8,ACCESS=31"
290 #define HP_FINI_ARRAY_SECTION_ASM_OP \
291 "\t.SUBSPA \\.fini,QUAD=1,ALIGN=8,ACCESS=31"
292 #define GNU_FINI_ARRAY_SECTION_ASM_OP \
293 "\t.SUBSPA \\.fini_array,QUAD=1,ALIGN=8,ACCESS=31"
295 #endif /* USING_ELFOS_H */
297 /* The following defines, used to run constructors and destructors with
298 the SOM linker under HP-UX 11, are not needed. */
299 #undef HAS_INIT_SECTION
300 #undef LD_INIT_SWITCH
301 #undef LD_FINI_SWITCH
303 /* The following STARTFILE_SPEC and ENDFILE_SPEC defines provide the
304 magic needed to run initializers and finalizers. */
305 #undef STARTFILE_SPEC
306 #if TARGET_HPUX_11_31
307 #define STARTFILE_SPEC \
308 "%{!shared: %{!symbolic: crt0%O%s} \
309 %{munix=95:unix95.o%s} %{munix=98:unix98.o%s} \
310 %{!munix=93:%{!munix=95:%{!munix=98:unix2003%O%s}}}} \
311 %{static:crtbeginT%O%s} \
312 %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
313 #elif TARGET_HPUX_11_11
314 #define STARTFILE_SPEC \
315 "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95.o%s} \
316 %{!munix=93:%{!munix=95:unix98%O%s}}} %{static:crtbeginT%O%s} \
317 %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
319 #define STARTFILE_SPEC \
320 "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95%O%s}} \
321 %{static:crtbeginT%O%s} %{!static:%{!shared:crtbegin%O%s} \
322 %{shared:crtbeginS%O%s}}"
325 #define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}"
327 /* Since HP uses the .init and .fini sections for array initializers
328 and finalizers, we need different defines for INIT_SECTION_ASM_OP
329 and FINI_SECTION_ASM_OP. With the implementation adopted below,
330 the sections are not actually used. However, we still must provide
331 defines to select the proper code path. */
332 #undef INIT_SECTION_ASM_OP
333 #define INIT_SECTION_ASM_OP
334 #undef FINI_SECTION_ASM_OP
335 #define FINI_SECTION_ASM_OP
337 /* We are using array initializers and don't want calls in the INIT
338 and FINI sections. */
339 #undef CRT_CALL_STATIC_FUNCTION
340 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)
342 /* The init_priority attribute is not supported with HP ld. This could be
343 supported if collect2 was used with LD_INIT_SWITCH. Unfortunately, this
344 approach doesn't work with GNU ld since HP-UX doesn't support DT_INIT,
345 and therefore the -init and -fini GNU ld switches. */
346 #undef SUPPORTS_INIT_PRIORITY
347 #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0)
349 /* We use DTOR_LIST_BEGIN to carry a bunch of hacks to allow us to use
350 the init and fini array sections with both the HP and GNU linkers.
351 The linkers setup the required dynamic entries in the dynamic segment
352 and the dynamic linker does the calls. This approach avoids using
355 The first hack is to implement __do_global_ctors_aux in crtbegin as
356 it needs to be the first entry in the init array so that it is called
357 last. HP got the order of the init array backwards. The DT_INIT_ARRAY
358 is supposed to be executed in the same order as the addresses appear in
359 the array. DT_FINI_ARRAY is supposed to be executed in the opposite
362 The second hack is a set of plabels to implement the effect of
363 CRT_CALL_STATIC_FUNCTION. HP-UX 11 only supports DI_INIT_ARRAY and
364 DT_FINI_ARRAY and they put the arrays in .init and .fini, rather than
365 in .init_array and .fini_array. The standard defines for .init and
366 .fini have the execute flag set. So, the assembler has to be hacked
367 to munge the standard flags for these sections to make them agree
368 with what the HP linker expects. With the GNU linker, we need to
369 used the .init_array and .fini_array sections. So, we set up for
370 both just in case. Once we have built the table, the linker does
371 the rest of the work.
373 The order is significant. Placing __do_global_ctors_aux first in
374 the list, results in it being called last. User specified initializers,
375 either using the linker +init command or a plabel, run before the
376 initializers specified here. */
378 /* We need to add frame_dummy to the initializer list if EH_FRAME_SECTION_NAME
379 or JCR_SECTION_NAME is defined. */
380 #if defined(EH_FRAME_SECTION_NAME) || defined(JCR_SECTION_NAME)
381 #define PA_INIT_FRAME_DUMMY_ASM_OP ".dword P%frame_dummy"
383 #define PA_INIT_FRAME_DUMMY_ASM_OP ""
386 /* The following hack sets up the .init, .init_array, .fini and
387 .fini_array sections. */
388 #define PA_CRTBEGIN_HACK \
389 asm (TEXT_SECTION_ASM_OP); \
390 static void __attribute__((used)) \
391 __do_global_ctors_aux (void) \
393 func_ptr *p = __CTOR_LIST__; \
396 for (; *p != (func_ptr) -1; p--) \
400 asm (HP_INIT_ARRAY_SECTION_ASM_OP); \
402 asm (".dword P%__do_global_ctors_aux"); \
403 asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
404 asm (GNU_INIT_ARRAY_SECTION_ASM_OP); \
406 asm (".dword P%__do_global_ctors_aux"); \
407 asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
408 asm (HP_FINI_ARRAY_SECTION_ASM_OP); \
410 asm (".dword P%__do_global_dtors_aux"); \
411 asm (GNU_FINI_ARRAY_SECTION_ASM_OP); \
413 asm (".dword P%__do_global_dtors_aux")
415 /* The following two variants of DTOR_LIST_BEGIN are identical to those
416 in crtstuff.c except for the addition of the above crtbegin hack. */
417 #ifdef DTORS_SECTION_ASM_OP
418 #define DTOR_LIST_BEGIN \
419 asm (DTORS_SECTION_ASM_OP); \
420 STATIC func_ptr __DTOR_LIST__[1] \
421 __attribute__ ((aligned(sizeof(func_ptr)))) \
422 = { (func_ptr) (-1) }; \
425 #define DTOR_LIST_BEGIN \
426 STATIC func_ptr __DTOR_LIST__[1] \
427 __attribute__ ((section(".dtors"), aligned(sizeof(func_ptr)))) \
428 = { (func_ptr) (-1) }; \
432 /* If using HP ld do not call pxdb. Use size as a program that does nothing
433 and returns 0. /bin/true cannot be used because it is a script without
435 #define INIT_ENVIRONMENT "LD_PXDB=/usr/ccs/bin/size"
437 /* The HPUX dynamic linker objects to undefined weak symbols, so do
438 not use them in gthr-posix.h. */
439 #define GTHREAD_USE_WEAK 0
441 /* We don't want undefined weak references to __register_frame_info,
442 __deregister_frame_info, _Jv_RegisterClasses and __cxa_finalize
443 introduced by crtbegin.o. The GNU linker only resolves weak
444 references if they appear in a shared library. Thus, it would be
445 impossible to create a static executable if the symbols were weak.
446 So, the best solution seems to be to make the symbols strong and
447 provide an archive library of empty stub functions. */
448 #define TARGET_ATTRIBUTE_WEAK