OSDN Git Service

gcc:
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / pa64-hpux.h
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 Free Software Foundation, 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 2, 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 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #undef SUBTARGET_SWITCHES
23 #define SUBTARGET_SWITCHES                              \
24   { "sio",       MASK_SIO,                              \
25      N_("Generate cpp defines for server IO") },        \
26   { "wsio",     -MASK_SIO,                              \
27      N_("Generate cpp defines for workstation IO") },   \
28   {"gnu-ld",     MASK_GNU_LD,                           \
29      N_("Assume code will be linked by GNU ld") },      \
30   {"hp-ld",     -MASK_GNU_LD,                           \
31      N_("Assume code will be linked by HP ld") },
32
33 /* We can debug dynamically linked executables on hpux11; we also
34    want dereferencing of a NULL pointer to cause a SEGV.  Do not move
35    the "+Accept TypeMismatch" switch.  We check for it in collect2
36    to determine which init/fini is needed.  */
37 #undef LINK_SPEC
38 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
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    %{mhp-ld:+Accept TypeMismatch} -E %{mlinker-opt:-O} %{!shared:-u main}\
47    %{static:-a archive} %{shared:%{mhp-ld:-b}%{!mhp-ld:-shared}}"
48 #else
49 #define LINK_SPEC \
50   "%{!shared:%{p:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
51      %nWarning: consider linking with `-static' as system libraries with\n\
52      %n  profiling support are only provided in archive format}}}\
53    %{!shared:%{pg:-L/lib/pa20_64/libp -L/usr/lib/pa20_64/libp %{!static:\
54      %nWarning: consider linking with `-static' as system libraries with\n\
55      %n  profiling support are only provided in archive format}}}\
56    %{!mgnu-ld:+Accept TypeMismatch} -E %{mlinker-opt:-O} %{!shared:-u main}\
57    %{static:-a archive} %{shared:%{mgnu-ld:-shared}%{!mgnu-ld:-b}}"
58 #endif
59
60 /* Like the default, except no -lg.  */
61 #undef LIB_SPEC
62 #define LIB_SPEC \
63   "%{!shared:\
64      %{!p:%{!pg: -lc %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
65      %{p:%{!pg:-lprof -lc\
66        %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
67      %{pg:-lgprof -lc\
68        %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
69    /usr/lib/pa20_64/milli.a"
70
71 /* Under hpux11, the normal location of the `ld' and `as' programs is the
72    /usr/ccs/bin directory.  */
73
74 #ifndef CROSS_COMPILE
75 #undef MD_EXEC_PREFIX
76 #define MD_EXEC_PREFIX "/usr/ccs/bin"
77 #endif
78
79 /* Under hpux11 the normal location of the various pa20_64 *crt*.o files
80    is the /usr/ccs/lib/pa20_64 directory.  Some files may also be in the
81    /opt/langtools/lib/pa20_64 directory.  */
82
83 #ifndef CROSS_COMPILE
84 #undef MD_STARTFILE_PREFIX
85 #define MD_STARTFILE_PREFIX "/usr/ccs/lib/pa20_64/"
86 #endif
87
88 #ifndef CROSS_COMPILE
89 #undef MD_STARTFILE_PREFIX_1
90 #define MD_STARTFILE_PREFIX_1 "/opt/langtools/lib/pa20_64/"
91 #endif
92
93 /* Due to limitations in the target structure, it isn't currently possible
94    to dynamically switch between the GNU and HP assemblers.  */
95 #undef TARGET_GAS
96
97 /* Configure selects the standard ELFOS defines for use with GAS.  */
98 #ifdef USING_ELFOS_H
99
100 /* We are using GAS.  */
101 #define TARGET_GAS 1
102
103 #undef TARGET_ASM_FILE_START
104 #define TARGET_ASM_FILE_START pa_hpux64_gas_file_start
105
106 /* This is how we output a null terminated string.  */
107 #undef STRING_ASM_OP
108 #define STRING_ASM_OP   "\t.stringz\t"
109
110 #define TEXT_SECTION_ASM_OP     "\t.text"
111 #define DATA_SECTION_ASM_OP     "\t.data"
112 #define BSS_SECTION_ASM_OP      "\t.section\t.bss"
113
114 #define JCR_SECTION_NAME        ".jcr"
115
116 #define HP_INIT_ARRAY_SECTION_ASM_OP    "\t.section\t.init"
117 #define GNU_INIT_ARRAY_SECTION_ASM_OP   "\t.section\t.init_array"
118 #define HP_FINI_ARRAY_SECTION_ASM_OP    "\t.section\t.fini"
119 #define GNU_FINI_ARRAY_SECTION_ASM_OP   "\t.section\t.fini_array"
120
121 #undef ASM_OUTPUT_ALIGNED_COMMON
122 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)              \
123 do {                                                                    \
124   bss_section ();                                                       \
125   assemble_name ((FILE), (NAME));                                       \
126   fprintf ((FILE), "\t.comm "HOST_WIDE_INT_PRINT_UNSIGNED"\n",          \
127            MAX ((unsigned HOST_WIDE_INT)(SIZE),                         \
128                 ((unsigned HOST_WIDE_INT)(ALIGN) / BITS_PER_UNIT)));    \
129 } while (0)
130
131 #undef ASM_OUTPUT_ALIGNED_LOCAL
132 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)               \
133 do {                                                                    \
134   bss_section ();                                                       \
135   fprintf ((FILE), "\t.align %d\n", ((ALIGN) / BITS_PER_UNIT));         \
136   assemble_name ((FILE), (NAME));                                       \
137   fprintf ((FILE), "\n\t.block "HOST_WIDE_INT_PRINT_UNSIGNED"\n",       \
138            (unsigned HOST_WIDE_INT)(SIZE));                             \
139 } while (0)
140
141 /* The define in pa.h doesn't work with the alias attribute.  The
142    default is ok with the following define for GLOBAL_ASM_OP.  */
143 #undef TARGET_ASM_GLOBALIZE_LABEL
144
145 /* This is how we globalize a label.  */
146 #define GLOBAL_ASM_OP   "\t.globl\t"
147
148 /* Hacked version from elfos.h that doesn't output a label.  */
149 #undef ASM_DECLARE_FUNCTION_NAME
150 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)             \
151 do {                                                            \
152   ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");           \
153   ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));                \
154 } while (0)
155
156 /* The type of external references must be set correctly for the
157    dynamic loader to work correctly.  This is equivalent to the
158    HP assembler's .IMPORT directive but relates more directly to
159    ELF object file types.  */
160 #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)                           \
161 do {                                                                    \
162   int save_referenced;                                                  \
163   save_referenced = TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL));\
164   if (FUNCTION_NAME_P (NAME))                                           \
165     ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");                 \
166   else                                                                  \
167     ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");                   \
168   TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)) = save_referenced;\
169 } while (0)
170
171 /* We need set the type for external libcalls.  Also note that not all
172    libcall names are passed to targetm.encode_section_info (e.g., __main).
173    Thus, we also have to do the section encoding if it hasn't been done
174    already.  */
175 #undef ASM_OUTPUT_EXTERNAL_LIBCALL
176 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN)                  \
177 do {                                                            \
178   if (!FUNCTION_NAME_P (XSTR (FUN, 0)))                         \
179     hppa_encode_label (FUN);                                    \
180   ASM_OUTPUT_TYPE_DIRECTIVE (FILE, XSTR (FUN, 0), "function");  \
181 } while (0)
182
183 /* We need to use the HP style for internal labels.  */
184 #undef ASM_GENERATE_INTERNAL_LABEL
185 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
186   sprintf (LABEL, "*%c$%s%04ld", (PREFIX)[0], (PREFIX) + 1, (long)(NUM))
187
188 #else /* USING_ELFOS_H */
189
190 /* We are not using GAS.  */
191 #define TARGET_GAS 0
192
193 /* HPUX 11 has the "new" HP assembler.  It's still lousy, but it's a whole
194    lot better than the assembler shipped with older versions of hpux.
195    However, it doesn't support weak symbols and is a bad fit with ELF.  */
196 #undef NEW_HP_ASSEMBLER
197 #define NEW_HP_ASSEMBLER 1
198
199 /* It looks like DWARF2 will be the easiest debug format to handle on this
200    platform.  */
201 #define DWARF2_DEBUGGING_INFO 1
202 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
203
204 /* This target uses the ELF object file format.  */
205 #define OBJECT_FORMAT_ELF
206
207 #undef TARGET_ASM_FILE_START
208 #define TARGET_ASM_FILE_START pa_hpux64_hpas_file_start
209
210 #undef TEXT_SECTION_ASM_OP
211 #define TEXT_SECTION_ASM_OP             "\t.SUBSPA $CODE$\n"
212 #undef READONLY_DATA_SECTION_ASM_OP
213 #define READONLY_DATA_SECTION_ASM_OP    "\t.SUBSPA $LIT$\n"
214 #undef DATA_SECTION_ASM_OP
215 #define DATA_SECTION_ASM_OP             "\t.SUBSPA $DATA$\n"
216 #undef BSS_SECTION_ASM_OP
217 #define BSS_SECTION_ASM_OP              "\t.SUBSPA $BSS$\n"
218
219 /* We provide explicit defines for CTORS_SECTION_ASM_OP and
220    DTORS_SECTION_ASM_OP since we don't yet have support for
221    named sections with the HP assembler.  */
222 #undef CTORS_SECTION_ASM_OP
223 #define CTORS_SECTION_ASM_OP "\t.SUBSPA \\.ctors,QUAD=1,ALIGN=8,ACCESS=31"
224 #undef DTORS_SECTION_ASM_OP
225 #define DTORS_SECTION_ASM_OP "\t.SUBSPA \\.dtors,QUAD=1,ALIGN=8,ACCESS=31"
226
227 #define HP_INIT_ARRAY_SECTION_ASM_OP \
228   "\t.SUBSPA \\.init,QUAD=1,ALIGN=8,ACCESS=31"
229 #define GNU_INIT_ARRAY_SECTION_ASM_OP \
230   "\t.SUBSPA \\.init_array,QUAD=1,ALIGN=8,ACCESS=31"
231 #define HP_FINI_ARRAY_SECTION_ASM_OP \
232   "\t.SUBSPA \\.fini,QUAD=1,ALIGN=8,ACCESS=31"
233 #define GNU_FINI_ARRAY_SECTION_ASM_OP \
234   "\t.SUBSPA \\.fini_array,QUAD=1,ALIGN=8,ACCESS=31"
235
236 #endif /* USING_ELFOS_H */
237
238 /* The following defines, used to run constructors and destructors with
239    the SOM linker under HP-UX 11, are not needed.  */
240 #undef HAS_INIT_SECTION
241 #undef LD_INIT_SWITCH
242 #undef LD_FINI_SWITCH
243
244 /* The following STARTFILE_SPEC and ENDFILE_SPEC defines provide the
245    magic needed to run initializers and finalizers.  */
246 #undef STARTFILE_SPEC
247 #define STARTFILE_SPEC \
248   "%{!shared: %{!symbolic: crt0.o%s}} %{static:crtbeginT.o%s} \
249    %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}"
250 #undef ENDFILE_SPEC
251 #define ENDFILE_SPEC "%{!shared:crtend.o%s} %{shared:crtendS.o%s}"
252
253 /* Since HP uses the .init and .fini sections for array initializers
254    and finalizers, we need different defines for INIT_SECTION_ASM_OP
255    and FINI_SECTION_ASM_OP.  With the implementation adopted below,
256    the sections are not actually used.  However, we still must provide
257    defines to select the proper code path.  */
258 #undef INIT_SECTION_ASM_OP
259 #define INIT_SECTION_ASM_OP
260 #undef FINI_SECTION_ASM_OP
261 #define FINI_SECTION_ASM_OP
262
263 /* We are using array initializers and don't want calls in the INIT
264    and FINI sections.  */
265 #undef CRT_CALL_STATIC_FUNCTION
266 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)
267
268 /* The init_priority attribute is not supported with HP ld.  This could be
269    supported if collect2 was used with LD_INIT_SWITCH.  Unfortunately, this
270    approach doesn't work with GNU ld since HP-UX doesn't support DT_INIT,
271    and therefore the -init and -fini GNU ld switches.  */
272 #undef SUPPORTS_INIT_PRIORITY
273 #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0)
274
275 /* We use DTOR_LIST_BEGIN to carry a bunch of hacks to allow us to use
276    the init and fini array sections with both the HP and GNU linkers.
277    The linkers setup the required dynamic entries in the dynamic segment
278    and the dynamic linker does the calls.  This approach avoids using
279    collect2.
280
281    The first hack is to implement __do_global_ctors_aux in crtbegin as
282    it needs to be the first entry in the init array so that it is called
283    last.  HP got the order of the init array backwards.  The DT_INIT_ARRAY
284    is supposed to be executed in the same order as the addresses appear in
285    the array.  DT_FINI_ARRAY is supposed to be executed in the opposite
286    order.
287
288    The second hack is stubs for __cxa_finalize and _Jv_RegisterClasses.
289    The HP implementation of undefined weak symbols is broken.  The linker
290    and dynamic loader both search for undefined weak symbols contrary the
291    generic System V ABI.  An undefined weak symbol should resolve to a
292    value of 0 rather than causing an error.  The prototypes for
293    __cxa_finalize and _Jv_RegisterClasses in crtstuff.c are weak when
294    weak is supported (GNU as), so in theory a strong define should override
295    the stub functions provided here.
296
297    The final hack is a set of plabels to implement the effect of
298    CRT_CALL_STATIC_FUNCTION.  HP-UX 11 only supports DI_INIT_ARRAY and
299    DT_FINI_ARRAY and they put the arrays in .init and .fini, rather than
300    in .init_array and .fini_array.  The standard defines for .init and
301    .fini have the execute flag set.  So, the assembler has to be hacked
302    to munge the standard flags for these sections to make them agree
303    with what the HP linker expects.  With the GNU linker, we need to
304    used the .init_array and .fini_array sections.  So, we set up for
305    both just in case.  Once we have built the table, the linker does
306    the rest of the work.
307
308    The order is significant.  Placing __do_global_ctors_aux first in
309    the list, results in it being called last.  User specified initializers,
310    either using the linker +init command or a plabel, run before the
311    initializers specified here.  */
312
313 /* We need a __cxa_finalize stub if CRTSTUFFS_O is defined.  */
314 #ifdef CRTSTUFFS_O
315 #define PA_CXA_FINALIZE_STUB \
316 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;              \
317 void                                                                    \
318 __cxa_finalize (void *p __attribute__((unused))) {}
319 #else
320 #define PA_CXA_FINALIZE_STUB
321 #endif
322
323 /* We need a _Jv_RegisterClasses stub if JCR_SECTION_NAME is defined.  */
324 #ifdef JCR_SECTION_NAME
325 #define PA_JV_REGISTERCLASSES_STUB \
326 void                                                                    \
327 _Jv_RegisterClasses (void *p __attribute__((unused))) {}
328 #else
329 #define PA_JV_REGISTERCLASSES_STUB
330 #endif
331
332 /* We need to add frame_dummy to the initializer list if EH_FRAME_SECTION_NAME
333    or JCR_SECTION_NAME is defined.  */
334 #if defined(EH_FRAME_SECTION_NAME) || defined(JCR_SECTION_NAME)
335 #define PA_INIT_FRAME_DUMMY_ASM_OP ".dword P%frame_dummy"
336 #else
337 #define PA_INIT_FRAME_DUMMY_ASM_OP ""
338 #endif
339
340 #define PA_INIT_FINI_HACK \
341 static void __attribute__((used))                                       \
342 __do_global_ctors_aux (void)                                            \
343 {                                                                       \
344   func_ptr *p = __CTOR_LIST__;                                          \
345   while (*(p + 1))                                                      \
346     p++;                                                                \
347   for (; *p != (func_ptr) -1; p--)                                      \
348     (*p) ();                                                            \
349 }                                                                       \
350                                                                         \
351 PA_CXA_FINALIZE_STUB                                                    \
352 PA_JV_REGISTERCLASSES_STUB                                              \
353                                                                         \
354 asm (HP_INIT_ARRAY_SECTION_ASM_OP);                                     \
355 asm (".dword P%__do_global_ctors_aux");                                 \
356 asm (PA_INIT_FRAME_DUMMY_ASM_OP);                                       \
357 asm (GNU_INIT_ARRAY_SECTION_ASM_OP);                                    \
358 asm (".dword P%__do_global_ctors_aux");                                 \
359 asm (PA_INIT_FRAME_DUMMY_ASM_OP);                                       \
360 asm (HP_FINI_ARRAY_SECTION_ASM_OP);                                     \
361 asm (".dword P%__do_global_dtors_aux");                                 \
362 asm (GNU_FINI_ARRAY_SECTION_ASM_OP);                                    \
363 asm (".dword P%__do_global_dtors_aux")
364
365 /* The following two variants of DTOR_LIST_BEGIN are identical to those
366    in crtstuff.c except for the addition of the above init-fini hack.  */
367 #ifdef DTORS_SECTION_ASM_OP
368 #define DTOR_LIST_BEGIN \
369 asm (DTORS_SECTION_ASM_OP);                                             \
370 STATIC func_ptr __DTOR_LIST__[1]                                        \
371   __attribute__ ((aligned(sizeof(func_ptr))))                           \
372   = { (func_ptr) (-1) };                                                \
373 PA_INIT_FINI_HACK
374 #else
375 #define DTOR_LIST_BEGIN \
376 STATIC func_ptr __DTOR_LIST__[1]                                        \
377   __attribute__ ((section(".dtors"), aligned(sizeof(func_ptr))))        \
378   = { (func_ptr) (-1) };                                                \
379 PA_INIT_FINI_HACK
380 #endif
381
382 /* If using HP ld do not call pxdb.  Use size as a program that does nothing
383    and returns 0.  /bin/true cannot be used because it is a script without
384    an interpreter.  */
385 #define INIT_ENVIRONMENT "LD_PXDB=/usr/ccs/bin/size"
386
387 /* The HPUX dynamic linker objects to weak symbols with no
388    definitions, so do not use them in gthr-posix.h.  */
389 #define GTHREAD_USE_WEAK 0