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