Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / config / pa / pa64-hpux.h
blobef1122d6b3baffef3052ab3a8d783fdf3fcfa568
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 Free Software Foundation,
4 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 %{mhp-ld:+Accept TypeMismatch -z} -E %{mlinker-opt:-O}\
36 %{!shared:-u main %{!nostdlib:%{!nodefaultlibs:-u __cxa_finalize}}}\
37 %{static:-a archive} %{shared:%{mhp-ld:-b}%{!mhp-ld:-shared}}"
38 #else
39 #define LINK_SPEC \
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 %{!mgnu-ld:+Accept TypeMismatch -z} -E %{mlinker-opt:-O}\
47 %{!shared:-u main %{!nostdlib:%{!nodefaultlibs:-u __cxa_finalize}}}\
48 %{static:-a archive} %{shared:%{mgnu-ld:-shared}%{!mgnu-ld:-b}}"
49 #endif
51 /* Profiling support is only provided in libc.a. However, libprof and
52 libgprof are only available in shared form on HP-UX 11.00. We use
53 the shared form if we are using the GNU linker or an archive form
54 isn't available. We also usually need to link with libdld and it's
55 only available in shared form. */
56 #undef LIB_SPEC
57 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
58 #define LIB_SPEC \
59 "%{!shared:\
60 %{!p:%{!pg: %{static|mt|pthread:-lpthread} -lc\
61 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
62 %{p:%{!pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
63 -lprof %{static:-a archive} %{static|mt|pthread:-lpthread} -lc\
64 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
65 %{pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
66 -lgprof %{static:-a archive} %{static|mt|pthread:-lpthread} -lc\
67 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
68 %{shared:%{mt|pthread:-lpthread}}"
69 #else
70 #define LIB_SPEC \
71 "%{!shared:\
72 %{!p:%{!pg: %{static|mt|pthread:-lpthread} -lc\
73 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
74 %{p:%{!pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
75 -lprof %{static:-a archive} %{static|mt|pthread:-lpthread} -lc\
76 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
77 %{pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
78 -lgprof %{static:-a archive} %{static|mt|pthread:-lpthread} -lc\
79 %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
80 %{shared:%{mt|pthread:-lpthread}}"
81 #endif
83 /* The libgcc_stub.a and milli.a libraries need to come last. */
84 #undef LINK_GCC_C_SEQUENCE_SPEC
85 #define LINK_GCC_C_SEQUENCE_SPEC "\
86 %G %L %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}\
87 /usr/lib/pa20_64/milli.a}}"
89 /* Under hpux11, the normal location of the `ld' and `as' programs is the
90 /usr/ccs/bin directory. */
92 #ifndef CROSS_DIRECTORY_STRUCTURE
93 #undef MD_EXEC_PREFIX
94 #define MD_EXEC_PREFIX "/usr/ccs/bin"
95 #endif
97 /* Default prefixes. */
99 #undef STANDARD_STARTFILE_PREFIX_1
100 #define STANDARD_STARTFILE_PREFIX_1 "/lib/pa20_64/"
102 #undef STANDARD_STARTFILE_PREFIX_2
103 #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/pa20_64/"
105 /* Under hpux11 the normal location of the various pa20_64 *crt*.o files
106 is the /usr/ccs/lib/pa20_64 directory. Some files may also be in the
107 /opt/langtools/lib/pa20_64 directory. */
109 #ifndef CROSS_DIRECTORY_STRUCTURE
110 #undef MD_STARTFILE_PREFIX
111 #define MD_STARTFILE_PREFIX "/usr/ccs/lib/pa20_64/"
112 #endif
114 #ifndef CROSS_DIRECTORY_STRUCTURE
115 #undef MD_STARTFILE_PREFIX_1
116 #define MD_STARTFILE_PREFIX_1 "/opt/langtools/lib/pa20_64/"
117 #endif
119 /* This macro specifies the biggest alignment supported by the object
120 file format of this machine.
122 The .align directive in the HP assembler allows alignments up to
123 4096 bytes. However, the maximum alignment of a global common symbol
124 is 16 bytes using HP ld. Unfortunately, this macro doesn't provide
125 a method to check for common symbols. */
126 #undef MAX_OFILE_ALIGNMENT
127 #define MAX_OFILE_ALIGNMENT 32768
129 /* Due to limitations in the target structure, it isn't currently possible
130 to dynamically switch between the GNU and HP assemblers. */
131 #undef TARGET_GAS
133 /* Configure selects the standard ELFOS defines for use with GAS. */
134 #ifdef USING_ELFOS_H
136 /* We are using GAS. */
137 #define TARGET_GAS 1
139 #undef TARGET_ASM_FILE_START
140 #define TARGET_ASM_FILE_START pa_hpux64_gas_file_start
142 /* This is how we output a null terminated string. */
143 #undef STRING_ASM_OP
144 #define STRING_ASM_OP "\t.stringz\t"
146 #define TEXT_SECTION_ASM_OP "\t.text"
147 #define DATA_SECTION_ASM_OP "\t.data"
148 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
150 #define JCR_SECTION_NAME ".jcr"
152 #define HP_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init"
153 #define GNU_INIT_ARRAY_SECTION_ASM_OP "\t.section\t.init_array"
154 #define HP_FINI_ARRAY_SECTION_ASM_OP "\t.section\t.fini"
155 #define GNU_FINI_ARRAY_SECTION_ASM_OP "\t.section\t.fini_array"
157 /* We need to override the following two macros defined in elfos.h since
158 the .comm directive has a different syntax and it can't be used for
159 local common symbols. */
160 #undef ASM_OUTPUT_ALIGNED_COMMON
161 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
162 pa_asm_output_aligned_common (FILE, NAME, SIZE, ALIGN)
164 #undef ASM_OUTPUT_ALIGNED_LOCAL
165 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
166 pa_asm_output_aligned_local (FILE, NAME, SIZE, ALIGN)
168 /* The define in pa.h doesn't work with the alias attribute. The
169 default is ok with the following define for GLOBAL_ASM_OP. */
170 #undef TARGET_ASM_GLOBALIZE_LABEL
172 /* This is how we globalize a label. */
173 #define GLOBAL_ASM_OP "\t.globl\t"
175 /* Hacked version from defaults.h that uses assemble_name_raw
176 instead of assemble_name. A symbol in a type directive that
177 isn't otherwise referenced doesn't cause the symbol to be
178 placed in the symbol table of the assembled object. */
179 #undef ASM_OUTPUT_TYPE_DIRECTIVE
180 #define ASM_OUTPUT_TYPE_DIRECTIVE(STREAM, NAME, TYPE) \
181 do { \
182 fputs (TYPE_ASM_OP, STREAM); \
183 assemble_name_raw (STREAM, NAME); \
184 fputs (", ", STREAM); \
185 fprintf (STREAM, TYPE_OPERAND_FMT, TYPE); \
186 putc ('\n', STREAM); \
187 } while (0)
189 /* Hacked version from elfos.h that doesn't output a label. */
190 #undef ASM_DECLARE_FUNCTION_NAME
191 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
192 do { \
193 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
194 ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \
195 } while (0)
197 /* The type of external references must be set correctly for the
198 dynamic loader to work correctly. This is equivalent to the
199 HP assembler's .IMPORT directive but relates more directly to
200 ELF object file types. */
201 #undef ASM_OUTPUT_EXTERNAL
202 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
203 pa_hpux_asm_output_external ((FILE), (DECL), (NAME))
204 #define ASM_OUTPUT_EXTERNAL_REAL(FILE, DECL, NAME) \
205 do { \
206 if (FUNCTION_NAME_P (NAME)) \
207 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
208 else \
209 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
210 } while (0)
212 /* We need set the type for external libcalls. Also note that not all
213 libcall names are passed to targetm.encode_section_info (e.g., __main).
214 Thus, we also have to do the section encoding if it hasn't been done
215 already. */
216 #undef ASM_OUTPUT_EXTERNAL_LIBCALL
217 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
218 do { \
219 if (!FUNCTION_NAME_P (XSTR (FUN, 0))) \
220 hppa_encode_label (FUN); \
221 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, XSTR (FUN, 0), "function"); \
222 } while (0)
224 /* We need to use the HP style for internal labels. */
225 #undef ASM_GENERATE_INTERNAL_LABEL
226 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
227 sprintf (LABEL, "*%c$%s%04ld", (PREFIX)[0], (PREFIX) + 1, (long)(NUM))
229 #else /* USING_ELFOS_H */
231 /* We are not using GAS. */
232 #define TARGET_GAS 0
234 /* HPUX 11 has the "new" HP assembler. It's still lousy, but it's a whole
235 lot better than the assembler shipped with older versions of hpux.
236 However, it doesn't support weak symbols and is a bad fit with ELF. */
237 #undef NEW_HP_ASSEMBLER
238 #define NEW_HP_ASSEMBLER 1
240 /* It looks like DWARF2 will be the easiest debug format to handle on this
241 platform. */
242 #define DWARF2_DEBUGGING_INFO 1
243 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
245 /* This target uses the ELF object file format. */
246 #define OBJECT_FORMAT_ELF
248 #undef TARGET_ASM_FILE_START
249 #define TARGET_ASM_FILE_START pa_hpux64_hpas_file_start
251 #undef TEXT_SECTION_ASM_OP
252 #define TEXT_SECTION_ASM_OP "\t.SUBSPA $CODE$\n"
253 #undef READONLY_DATA_SECTION_ASM_OP
254 #define READONLY_DATA_SECTION_ASM_OP "\t.SUBSPA $LIT$\n"
255 #undef DATA_SECTION_ASM_OP
256 #define DATA_SECTION_ASM_OP "\t.SUBSPA $DATA$\n"
257 #undef BSS_SECTION_ASM_OP
258 #define BSS_SECTION_ASM_OP "\t.SUBSPA $BSS$\n"
260 /* We provide explicit defines for CTORS_SECTION_ASM_OP and
261 DTORS_SECTION_ASM_OP since we don't yet have support for
262 named sections with the HP assembler. */
263 #undef CTORS_SECTION_ASM_OP
264 #define CTORS_SECTION_ASM_OP "\t.SUBSPA \\.ctors,QUAD=1,ALIGN=8,ACCESS=31"
265 #undef DTORS_SECTION_ASM_OP
266 #define DTORS_SECTION_ASM_OP "\t.SUBSPA \\.dtors,QUAD=1,ALIGN=8,ACCESS=31"
268 #define HP_INIT_ARRAY_SECTION_ASM_OP \
269 "\t.SUBSPA \\.init,QUAD=1,ALIGN=8,ACCESS=31"
270 #define GNU_INIT_ARRAY_SECTION_ASM_OP \
271 "\t.SUBSPA \\.init_array,QUAD=1,ALIGN=8,ACCESS=31"
272 #define HP_FINI_ARRAY_SECTION_ASM_OP \
273 "\t.SUBSPA \\.fini,QUAD=1,ALIGN=8,ACCESS=31"
274 #define GNU_FINI_ARRAY_SECTION_ASM_OP \
275 "\t.SUBSPA \\.fini_array,QUAD=1,ALIGN=8,ACCESS=31"
277 #endif /* USING_ELFOS_H */
279 /* The following defines, used to run constructors and destructors with
280 the SOM linker under HP-UX 11, are not needed. */
281 #undef HAS_INIT_SECTION
282 #undef LD_INIT_SWITCH
283 #undef LD_FINI_SWITCH
285 /* The following STARTFILE_SPEC and ENDFILE_SPEC defines provide the
286 magic needed to run initializers and finalizers. */
287 #undef STARTFILE_SPEC
288 #if TARGET_HPUX_11_11
289 #define STARTFILE_SPEC \
290 "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95.o%s} \
291 %{!munix=93:%{!munix=95:unix98%O%s}}} %{static:crtbeginT%O%s} \
292 %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
293 #else
294 #define STARTFILE_SPEC \
295 "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95%O%s}} \
296 %{static:crtbeginT%O%s} %{!static:%{!shared:crtbegin%O%s} \
297 %{shared:crtbeginS%O%s}}"
298 #endif
299 #undef ENDFILE_SPEC
300 #define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}"
302 /* Since HP uses the .init and .fini sections for array initializers
303 and finalizers, we need different defines for INIT_SECTION_ASM_OP
304 and FINI_SECTION_ASM_OP. With the implementation adopted below,
305 the sections are not actually used. However, we still must provide
306 defines to select the proper code path. */
307 #undef INIT_SECTION_ASM_OP
308 #define INIT_SECTION_ASM_OP
309 #undef FINI_SECTION_ASM_OP
310 #define FINI_SECTION_ASM_OP
312 /* We are using array initializers and don't want calls in the INIT
313 and FINI sections. */
314 #undef CRT_CALL_STATIC_FUNCTION
315 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)
317 /* The init_priority attribute is not supported with HP ld. This could be
318 supported if collect2 was used with LD_INIT_SWITCH. Unfortunately, this
319 approach doesn't work with GNU ld since HP-UX doesn't support DT_INIT,
320 and therefore the -init and -fini GNU ld switches. */
321 #undef SUPPORTS_INIT_PRIORITY
322 #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0)
324 /* We use DTOR_LIST_BEGIN to carry a bunch of hacks to allow us to use
325 the init and fini array sections with both the HP and GNU linkers.
326 The linkers setup the required dynamic entries in the dynamic segment
327 and the dynamic linker does the calls. This approach avoids using
328 collect2.
330 The first hack is to implement __do_global_ctors_aux in crtbegin as
331 it needs to be the first entry in the init array so that it is called
332 last. HP got the order of the init array backwards. The DT_INIT_ARRAY
333 is supposed to be executed in the same order as the addresses appear in
334 the array. DT_FINI_ARRAY is supposed to be executed in the opposite
335 order.
337 The second hack is a set of plabels to implement the effect of
338 CRT_CALL_STATIC_FUNCTION. HP-UX 11 only supports DI_INIT_ARRAY and
339 DT_FINI_ARRAY and they put the arrays in .init and .fini, rather than
340 in .init_array and .fini_array. The standard defines for .init and
341 .fini have the execute flag set. So, the assembler has to be hacked
342 to munge the standard flags for these sections to make them agree
343 with what the HP linker expects. With the GNU linker, we need to
344 used the .init_array and .fini_array sections. So, we set up for
345 both just in case. Once we have built the table, the linker does
346 the rest of the work.
348 The order is significant. Placing __do_global_ctors_aux first in
349 the list, results in it being called last. User specified initializers,
350 either using the linker +init command or a plabel, run before the
351 initializers specified here. */
353 /* We need to add frame_dummy to the initializer list if EH_FRAME_SECTION_NAME
354 or JCR_SECTION_NAME is defined. */
355 #if defined(EH_FRAME_SECTION_NAME) || defined(JCR_SECTION_NAME)
356 #define PA_INIT_FRAME_DUMMY_ASM_OP ".dword P%frame_dummy"
357 #else
358 #define PA_INIT_FRAME_DUMMY_ASM_OP ""
359 #endif
361 /* The following hack sets up the .init, .init_array, .fini and
362 .fini_array sections. */
363 #define PA_CRTBEGIN_HACK \
364 asm (TEXT_SECTION_ASM_OP); \
365 static void __attribute__((used)) \
366 __do_global_ctors_aux (void) \
368 func_ptr *p = __CTOR_LIST__; \
369 while (*(p + 1)) \
370 p++; \
371 for (; *p != (func_ptr) -1; p--) \
372 (*p) (); \
375 asm (HP_INIT_ARRAY_SECTION_ASM_OP); \
376 asm (".align 8"); \
377 asm (".dword P%__do_global_ctors_aux"); \
378 asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
379 asm (GNU_INIT_ARRAY_SECTION_ASM_OP); \
380 asm (".align 8"); \
381 asm (".dword P%__do_global_ctors_aux"); \
382 asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
383 asm (HP_FINI_ARRAY_SECTION_ASM_OP); \
384 asm (".align 8"); \
385 asm (".dword P%__do_global_dtors_aux"); \
386 asm (GNU_FINI_ARRAY_SECTION_ASM_OP); \
387 asm (".align 8"); \
388 asm (".dword P%__do_global_dtors_aux")
390 /* The following two variants of DTOR_LIST_BEGIN are identical to those
391 in crtstuff.c except for the addition of the above crtbegin hack. */
392 #ifdef DTORS_SECTION_ASM_OP
393 #define DTOR_LIST_BEGIN \
394 asm (DTORS_SECTION_ASM_OP); \
395 STATIC func_ptr __DTOR_LIST__[1] \
396 __attribute__ ((aligned(sizeof(func_ptr)))) \
397 = { (func_ptr) (-1) }; \
398 PA_CRTBEGIN_HACK
399 #else
400 #define DTOR_LIST_BEGIN \
401 STATIC func_ptr __DTOR_LIST__[1] \
402 __attribute__ ((section(".dtors"), aligned(sizeof(func_ptr)))) \
403 = { (func_ptr) (-1) }; \
404 PA_CRTBEGIN_HACK
405 #endif
407 /* If using HP ld do not call pxdb. Use size as a program that does nothing
408 and returns 0. /bin/true cannot be used because it is a script without
409 an interpreter. */
410 #define INIT_ENVIRONMENT "LD_PXDB=/usr/ccs/bin/size"
412 /* The HPUX dynamic linker objects to undefined weak symbols, so do
413 not use them in gthr-posix.h. */
414 #define GTHREAD_USE_WEAK 0
416 /* We don't want undefined weak references to __register_frame_info,
417 __deregister_frame_info, _Jv_RegisterClasses and __cxa_finalize
418 introduced by crtbegin.o. The GNU linker only resolves weak
419 references if they appear in a shared library. Thus, it would be
420 impossible to create a static executable if the symbols were weak.
421 So, the best solution seems to be to make the symbols strong and
422 provide an archive library of empty stub functions. */
423 #define TARGET_ATTRIBUTE_WEAK