2011-03-21 Daniel Jacobowitz <dan@codesourcery.com>
[official-gcc.git] / gcc / config / pa / pa64-hpux.h
blobcc9724a6e7ebbb5b22ba31d78306fe6f52531a84
1 /* Definitions of target machine for GNU compiler, for HPs running
2 HPUX using the 64bit runtime model.
3 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* We can debug dynamically linked executables on hpux11; we also
23 want dereferencing of a NULL pointer to cause a SEGV. Do not move
24 the "+Accept TypeMismatch" switch. We check for it in collect2
25 to determine which init/fini is needed. */
26 #undef LINK_SPEC
27 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
28 #define LINK_SPEC \
29 "%{!shared:%{p:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
30 %nwarning: consider linking with '-static' as system libraries with\n\
31 %n profiling support are only provided in archive format}}}\
32 %{!shared:%{pg:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
33 %nwarning: consider linking with '-static' as system libraries with\n\
34 %n profiling support are only provided in archive format}}}\
35 %{!shared:%{!static:%{rdynamic:-E}}}\
36 %{mhp-ld:+Accept TypeMismatch -z} %{mlinker-opt:-O}\
37 %{!shared:-u main %{!nostdlib:%{!nodefaultlibs:-u __cxa_finalize}}}\
38 %{static:-a archive} %{shared:%{mhp-ld:-b}%{!mhp-ld:-shared}}"
39 #else
40 #define LINK_SPEC \
41 "%{!shared:%{p:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
42 %nwarning: consider linking with '-static' as system libraries with\n\
43 %n profiling support are only provided in archive format}}}\
44 %{!shared:%{pg:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
45 %nwarning: consider linking with '-static' as system libraries with\n\
46 %n profiling support are only provided in archive format}}}\
47 %{!shared:%{!static:%{rdynamic:-E}}}\
48 %{!mgnu-ld:+Accept TypeMismatch -z} %{mlinker-opt:-O}\
49 %{!shared:-u main %{!nostdlib:%{!nodefaultlibs:-u __cxa_finalize}}}\
50 %{static:-a archive} %{shared:%{mgnu-ld:-shared}%{!mgnu-ld:-b}}"
51 #endif
53 /* Profiling support is only provided in libc.a. However, libprof and
54 libgprof are only available in shared form on HP-UX 11.00. We use
55 the shared form if we are using the GNU linker or an archive form
56 isn't available. We also usually need to link with libdld and it's
57 only available in shared form. */
58 #undef LIB_SPEC
59 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
60 #define LIB_SPEC \
61 "%{!shared:\
62 %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
63 %{mt|pthread:-lpthread} -lc\
64 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
65 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
66 %{p:%{!pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
67 -lprof %{static:-a archive}\
68 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
69 %{mt|pthread:-lpthread} -lc\
70 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
71 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
72 %{pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
73 -lgprof %{static:-a archive}\
74 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
75 %{mt|pthread:-lpthread} -lc\
76 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
77 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
78 %{shared:%{mt|pthread:-lpthread}}"
79 #else
80 #define LIB_SPEC \
81 "%{!shared:\
82 %{!p:%{!pg:%{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
83 %{mt|pthread:-lpthread} -lc\
84 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
85 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
86 %{p:%{!pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
87 -lprof %{static:-a archive}\
88 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
89 %{mt|pthread:-lpthread} -lc\
90 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
91 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
92 %{pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
93 -lgprof %{static:-a archive}\
94 %{fopenmp:%{static:-a shared} -lrt %{static:-a archive}}\
95 %{mt|pthread:-lpthread} -lc\
96 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
97 %{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
98 %{shared:%{mt|pthread:-lpthread}}"
99 #endif
101 /* The libgcc_stub.a and milli.a libraries need to come last. */
102 #undef LINK_GCC_C_SEQUENCE_SPEC
103 #define LINK_GCC_C_SEQUENCE_SPEC "\
104 %G %L %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}\
105 milli.a%s}}"
107 /* Under hpux11, the normal location of the `ld' and `as' programs is the
108 /usr/ccs/bin directory. */
110 #ifndef CROSS_DIRECTORY_STRUCTURE
111 #undef MD_EXEC_PREFIX
112 #define MD_EXEC_PREFIX "/usr/ccs/bin"
113 #endif
115 /* Default prefixes. */
117 #undef STANDARD_STARTFILE_PREFIX_1
118 #define STANDARD_STARTFILE_PREFIX_1 "/lib/pa20_64/"
120 #undef STANDARD_STARTFILE_PREFIX_2
121 #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/pa20_64/"
123 /* Under hpux11 the normal location of the various pa20_64 *crt*.o files
124 is the /usr/ccs/lib/pa20_64 directory. Some files may also be in the
125 /opt/langtools/lib/pa20_64 directory. */
127 #ifndef CROSS_DIRECTORY_STRUCTURE
128 #undef MD_STARTFILE_PREFIX
129 #define MD_STARTFILE_PREFIX "/usr/ccs/lib/pa20_64/"
130 #endif
132 #ifndef CROSS_DIRECTORY_STRUCTURE
133 #undef MD_STARTFILE_PREFIX_1
134 #define MD_STARTFILE_PREFIX_1 "/opt/langtools/lib/pa20_64/"
135 #endif
137 /* This macro specifies the biggest alignment supported by the object
138 file format of this machine.
140 The .align directive in the HP assembler allows alignments up to
141 4096 bytes. However, the maximum alignment of a global common symbol
142 is 16 bytes using HP ld. Unfortunately, this macro doesn't provide
143 a method to check for common symbols. */
144 #undef MAX_OFILE_ALIGNMENT
145 #define MAX_OFILE_ALIGNMENT 32768
147 /* Due to limitations in the target structure, it isn't currently possible
148 to dynamically switch between the GNU and HP assemblers. */
149 #undef TARGET_GAS
151 /* Configure selects the standard ELFOS defines for use with GAS. */
152 #ifdef USING_ELFOS_H
154 /* We are using GAS. */
155 #define TARGET_GAS 1
157 #undef TARGET_ASM_FILE_START
158 #define TARGET_ASM_FILE_START pa_hpux64_gas_file_start
160 /* This is how we output a null terminated string. */
161 #undef STRING_ASM_OP
162 #define STRING_ASM_OP "\t.stringz\t"
164 #define TEXT_SECTION_ASM_OP "\t.text"
165 #define DATA_SECTION_ASM_OP "\t.data"
166 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
168 #define JCR_SECTION_NAME ".jcr"
170 #define HP_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init"
171 #define GNU_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init_array"
172 #define HP_FINI_ARRAY_SECTION_ASM_OP "\t.section\t.fini"
173 #define GNU_FINI_ARRAY_SECTION_ASM_OP "\t.section\t.fini_array"
175 /* We need to override the following two macros defined in elfos.h since
176 the .comm directive has a different syntax and it can't be used for
177 local common symbols. */
178 #undef ASM_OUTPUT_ALIGNED_COMMON
179 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
180 pa_asm_output_aligned_common (FILE, NAME, SIZE, ALIGN)
182 #undef ASM_OUTPUT_ALIGNED_LOCAL
183 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
184 pa_asm_output_aligned_local (FILE, NAME, SIZE, ALIGN)
186 /* The define in pa.h doesn't work with the alias attribute. The
187 default is ok with the following define for GLOBAL_ASM_OP. */
188 #undef TARGET_ASM_GLOBALIZE_LABEL
190 /* This is how we globalize a label. */
191 #define GLOBAL_ASM_OP "\t.globl\t"
193 /* Hacked version from defaults.h that uses assemble_name_raw
194 instead of assemble_name. A symbol in a type directive that
195 isn't otherwise referenced doesn't cause the symbol to be
196 placed in the symbol table of the assembled object. */
197 #undef ASM_OUTPUT_TYPE_DIRECTIVE
198 #define ASM_OUTPUT_TYPE_DIRECTIVE(STREAM, NAME, TYPE) \
199 do { \
200 fputs (TYPE_ASM_OP, STREAM); \
201 assemble_name_raw (STREAM, NAME); \
202 fputs (", ", STREAM); \
203 fprintf (STREAM, TYPE_OPERAND_FMT, TYPE); \
204 putc ('\n', STREAM); \
205 } while (0)
207 /* Hacked version from elfos.h that doesn't output a label. */
208 #undef ASM_DECLARE_FUNCTION_NAME
209 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
210 do { \
211 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
212 ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \
213 } while (0)
215 /* The type of external references must be set correctly for the
216 dynamic loader to work correctly. This is equivalent to the
217 HP assembler's .IMPORT directive but relates more directly to
218 ELF object file types. */
219 #undef ASM_OUTPUT_EXTERNAL
220 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
221 pa_hpux_asm_output_external ((FILE), (DECL), (NAME))
222 #define ASM_OUTPUT_EXTERNAL_REAL(FILE, DECL, NAME) \
223 do { \
224 if (FUNCTION_NAME_P (NAME)) \
225 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
226 else \
227 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
228 default_elf_asm_output_external (FILE, DECL, NAME); \
229 } while (0)
231 /* We need set the type for external libcalls. Also note that not all
232 libcall names are passed to targetm.encode_section_info (e.g., __main).
233 Thus, we also have to do the section encoding if it hasn't been done
234 already. */
235 #undef ASM_OUTPUT_EXTERNAL_LIBCALL
236 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
237 do { \
238 if (!FUNCTION_NAME_P (XSTR (FUN, 0))) \
239 hppa_encode_label (FUN); \
240 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, XSTR (FUN, 0), "function"); \
241 } while (0)
243 /* We need to use the HP style for internal labels. */
244 #undef ASM_GENERATE_INTERNAL_LABEL
245 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
246 sprintf (LABEL, "*%c$%s%04ld", (PREFIX)[0], (PREFIX) + 1, (long)(NUM))
248 #else /* USING_ELFOS_H */
250 /* We are not using GAS. */
251 #define TARGET_GAS 0
253 /* HPUX 11 has the "new" HP assembler. It's still lousy, but it's a whole
254 lot better than the assembler shipped with older versions of hpux.
255 However, it doesn't support weak symbols and is a bad fit with ELF. */
256 #undef NEW_HP_ASSEMBLER
257 #define NEW_HP_ASSEMBLER 1
259 /* It looks like DWARF2 will be the easiest debug format to handle on this
260 platform. */
261 #define DWARF2_DEBUGGING_INFO 1
262 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
264 /* This target uses the ELF object file format. */
265 #define OBJECT_FORMAT_ELF
267 #undef TARGET_ASM_FILE_START
268 #define TARGET_ASM_FILE_START pa_hpux64_hpas_file_start
270 #undef TEXT_SECTION_ASM_OP
271 #define TEXT_SECTION_ASM_OP "\t.SUBSPA $CODE$\n"
272 #undef READONLY_DATA_SECTION_ASM_OP
273 #define READONLY_DATA_SECTION_ASM_OP "\t.SUBSPA $LIT$\n"
274 #undef DATA_SECTION_ASM_OP
275 #define DATA_SECTION_ASM_OP "\t.SUBSPA $DATA$\n"
276 #undef BSS_SECTION_ASM_OP
277 #define BSS_SECTION_ASM_OP "\t.SUBSPA $BSS$\n"
279 /* We provide explicit defines for CTORS_SECTION_ASM_OP and
280 DTORS_SECTION_ASM_OP since we don't yet have support for
281 named sections with the HP assembler. */
282 #undef CTORS_SECTION_ASM_OP
283 #define CTORS_SECTION_ASM_OP "\t.SUBSPA \\.ctors,QUAD=1,ALIGN=8,ACCESS=31"
284 #undef DTORS_SECTION_ASM_OP
285 #define DTORS_SECTION_ASM_OP "\t.SUBSPA \\.dtors,QUAD=1,ALIGN=8,ACCESS=31"
287 #define HP_INIT_ARRAY_SECTION_ASM_OP \
288 "\t.SUBSPA \\.init,QUAD=1,ALIGN=8,ACCESS=31"
289 #define GNU_INIT_ARRAY_SECTION_ASM_OP \
290 "\t.SUBSPA \\.init_array,QUAD=1,ALIGN=8,ACCESS=31"
291 #define HP_FINI_ARRAY_SECTION_ASM_OP \
292 "\t.SUBSPA \\.fini,QUAD=1,ALIGN=8,ACCESS=31"
293 #define GNU_FINI_ARRAY_SECTION_ASM_OP \
294 "\t.SUBSPA \\.fini_array,QUAD=1,ALIGN=8,ACCESS=31"
296 #endif /* USING_ELFOS_H */
298 /* The following defines, used to run constructors and destructors with
299 the SOM linker under HP-UX 11, are not needed. */
300 #undef HAS_INIT_SECTION
301 #undef LD_INIT_SWITCH
302 #undef LD_FINI_SWITCH
304 /* The following STARTFILE_SPEC and ENDFILE_SPEC defines provide the
305 magic needed to run initializers and finalizers. */
306 #undef STARTFILE_SPEC
307 #if TARGET_HPUX_11_11
308 #define STARTFILE_SPEC \
309 "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95.o%s} \
310 %{!munix=93:%{!munix=95:unix98%O%s}}} %{static:crtbeginT%O%s} \
311 %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
312 #else
313 #define STARTFILE_SPEC \
314 "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95%O%s}} \
315 %{static:crtbeginT%O%s} %{!static:%{!shared:crtbegin%O%s} \
316 %{shared:crtbeginS%O%s}}"
317 #endif
318 #undef ENDFILE_SPEC
319 #define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}"
321 /* Since HP uses the .init and .fini sections for array initializers
322 and finalizers, we need different defines for INIT_SECTION_ASM_OP
323 and FINI_SECTION_ASM_OP. With the implementation adopted below,
324 the sections are not actually used. However, we still must provide
325 defines to select the proper code path. */
326 #undef INIT_SECTION_ASM_OP
327 #define INIT_SECTION_ASM_OP
328 #undef FINI_SECTION_ASM_OP
329 #define FINI_SECTION_ASM_OP
331 /* We are using array initializers and don't want calls in the INIT
332 and FINI sections. */
333 #undef CRT_CALL_STATIC_FUNCTION
334 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)
336 /* The init_priority attribute is not supported with HP ld. This could be
337 supported if collect2 was used with LD_INIT_SWITCH. Unfortunately, this
338 approach doesn't work with GNU ld since HP-UX doesn't support DT_INIT,
339 and therefore the -init and -fini GNU ld switches. */
340 #undef SUPPORTS_INIT_PRIORITY
341 #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0)
343 /* We use DTOR_LIST_BEGIN to carry a bunch of hacks to allow us to use
344 the init and fini array sections with both the HP and GNU linkers.
345 The linkers setup the required dynamic entries in the dynamic segment
346 and the dynamic linker does the calls. This approach avoids using
347 collect2.
349 The first hack is to implement __do_global_ctors_aux in crtbegin as
350 it needs to be the first entry in the init array so that it is called
351 last. HP got the order of the init array backwards. The DT_INIT_ARRAY
352 is supposed to be executed in the same order as the addresses appear in
353 the array. DT_FINI_ARRAY is supposed to be executed in the opposite
354 order.
356 The second hack is a set of plabels to implement the effect of
357 CRT_CALL_STATIC_FUNCTION. HP-UX 11 only supports DI_INIT_ARRAY and
358 DT_FINI_ARRAY and they put the arrays in .init and .fini, rather than
359 in .init_array and .fini_array. The standard defines for .init and
360 .fini have the execute flag set. So, the assembler has to be hacked
361 to munge the standard flags for these sections to make them agree
362 with what the HP linker expects. With the GNU linker, we need to
363 used the .init_array and .fini_array sections. So, we set up for
364 both just in case. Once we have built the table, the linker does
365 the rest of the work.
367 The order is significant. Placing __do_global_ctors_aux first in
368 the list, results in it being called last. User specified initializers,
369 either using the linker +init command or a plabel, run before the
370 initializers specified here. */
372 /* We need to add frame_dummy to the initializer list if EH_FRAME_SECTION_NAME
373 or JCR_SECTION_NAME is defined. */
374 #if defined(EH_FRAME_SECTION_NAME) || defined(JCR_SECTION_NAME)
375 #define PA_INIT_FRAME_DUMMY_ASM_OP ".dword P%frame_dummy"
376 #else
377 #define PA_INIT_FRAME_DUMMY_ASM_OP ""
378 #endif
380 /* The following hack sets up the .init, .init_array, .fini and
381 .fini_array sections. */
382 #define PA_CRTBEGIN_HACK \
383 asm (TEXT_SECTION_ASM_OP); \
384 static void __attribute__((used)) \
385 __do_global_ctors_aux (void) \
387 func_ptr *p = __CTOR_LIST__; \
388 while (*(p + 1)) \
389 p++; \
390 for (; *p != (func_ptr) -1; p--) \
391 (*p) (); \
394 asm (HP_INIT_ARRAY_SECTION_ASM_OP); \
395 asm (".align 8"); \
396 asm (".dword P%__do_global_ctors_aux"); \
397 asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
398 asm (GNU_INIT_ARRAY_SECTION_ASM_OP); \
399 asm (".align 8"); \
400 asm (".dword P%__do_global_ctors_aux"); \
401 asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
402 asm (HP_FINI_ARRAY_SECTION_ASM_OP); \
403 asm (".align 8"); \
404 asm (".dword P%__do_global_dtors_aux"); \
405 asm (GNU_FINI_ARRAY_SECTION_ASM_OP); \
406 asm (".align 8"); \
407 asm (".dword P%__do_global_dtors_aux")
409 /* The following two variants of DTOR_LIST_BEGIN are identical to those
410 in crtstuff.c except for the addition of the above crtbegin hack. */
411 #ifdef DTORS_SECTION_ASM_OP
412 #define DTOR_LIST_BEGIN \
413 asm (DTORS_SECTION_ASM_OP); \
414 STATIC func_ptr __DTOR_LIST__[1] \
415 __attribute__ ((aligned(sizeof(func_ptr)))) \
416 = { (func_ptr) (-1) }; \
417 PA_CRTBEGIN_HACK
418 #else
419 #define DTOR_LIST_BEGIN \
420 STATIC func_ptr __DTOR_LIST__[1] \
421 __attribute__ ((section(".dtors"), aligned(sizeof(func_ptr)))) \
422 = { (func_ptr) (-1) }; \
423 PA_CRTBEGIN_HACK
424 #endif
426 /* If using HP ld do not call pxdb. Use size as a program that does nothing
427 and returns 0. /bin/true cannot be used because it is a script without
428 an interpreter. */
429 #define INIT_ENVIRONMENT "LD_PXDB=/usr/ccs/bin/size"
431 /* The HPUX dynamic linker objects to undefined weak symbols, so do
432 not use them in gthr-posix.h. */
433 #define GTHREAD_USE_WEAK 0
435 /* We don't want undefined weak references to __register_frame_info,
436 __deregister_frame_info, _Jv_RegisterClasses and __cxa_finalize
437 introduced by crtbegin.o. The GNU linker only resolves weak
438 references if they appear in a shared library. Thus, it would be
439 impossible to create a static executable if the symbols were weak.
440 So, the best solution seems to be to make the symbols strong and
441 provide an archive library of empty stub functions. */
442 #define TARGET_ATTRIBUTE_WEAK