1  /* Definitions of target machine for GNU compiler, for HPs running
       2     HPUX using the 64bit runtime model.
       3     Copyright (C) 1999-2023 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 3, 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 COPYING3.  If not see
      19  <http://www.gnu.org/licenses/>.  */
      20  
      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.  */
      25  #undef LINK_SPEC
      26  #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_GNU_LD)
      27  #define LINK_SPEC \
      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}}"
      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     %{!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}}"
      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:%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
      62                    %{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  	   %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
      69               %{static:-a shared} -lrt %{static:-a archive}}\
      70  	   %{mt|pthread:-lpthread} -lc\
      71  	   %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
      72  		%{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      73       %{pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
      74         -lgprof %{static:-a archive}\
      75         %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
      76           %{static:-a shared} -lrt %{static:-a archive}}\
      77         %{mt|pthread:-lpthread} -lc\
      78         %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
      79  		%{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      80     %{shared:%{mt|pthread:-lpthread}}"
      81  #else
      82  #define LIB_SPEC \
      83    "%{!shared:\
      84       %{!p:%{!pg:%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
      85                    %{static:-a shared} -lrt %{static:-a archive}}\
      86  	    %{mt|pthread:-lpthread} -lc\
      87  	    %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
      88  		%{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      89       %{p:%{!pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
      90  	   -lprof %{static:-a archive}\
      91  	   %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
      92               %{static:-a shared} -lrt %{static:-a archive}}\
      93  	   %{mt|pthread:-lpthread} -lc\
      94  	   %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
      95  		%{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
      96       %{pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
      97         -lgprof %{static:-a archive}\
      98         %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
      99           %{static:-a shared} -lrt %{static:-a archive}}\
     100         %{mt|pthread:-lpthread} -lc\
     101         %{static:%{!nolibdld:-a shared -ldld -a archive -lc}\
     102  		%{!mt:%{!pthread:-a shared -lc -a archive}}}}}\
     103     %{shared:%{mt|pthread:-lpthread}}"
     104  #endif
     105  
     106  /* Under hpux11, the normal location of the `ld' and `as' programs is the
     107     /usr/ccs/bin directory.  */
     108  
     109  #ifndef CROSS_DIRECTORY_STRUCTURE
     110  #undef MD_EXEC_PREFIX
     111  #define MD_EXEC_PREFIX "/usr/ccs/bin"
     112  #endif
     113  
     114  /* Default prefixes.  */
     115  
     116  #undef STANDARD_STARTFILE_PREFIX_1
     117  #define STANDARD_STARTFILE_PREFIX_1 "/lib/pa20_64/"
     118  
     119  #undef STANDARD_STARTFILE_PREFIX_2
     120  #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/pa20_64/"
     121  
     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.  */
     125  
     126  #ifndef CROSS_DIRECTORY_STRUCTURE
     127  #undef MD_STARTFILE_PREFIX
     128  #define MD_STARTFILE_PREFIX "/usr/ccs/lib/pa20_64/"
     129  #endif
     130  
     131  #ifndef CROSS_DIRECTORY_STRUCTURE
     132  #undef MD_STARTFILE_PREFIX_1
     133  #define MD_STARTFILE_PREFIX_1 "/opt/langtools/lib/pa20_64/"
     134  #endif
     135  
     136  /* This macro specifies the biggest alignment supported by the object
     137     file format of this machine.
     138  
     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
     145  
     146  /* Due to limitations in the target structure, it isn't currently possible
     147     to dynamically switch between the GNU and HP assemblers.  */
     148  #undef TARGET_GAS
     149  
     150  /* Configure selects the standard ELFOS defines for use with GAS.  */
     151  #ifdef USING_ELFOS_H
     152  
     153  /* We are using GAS.  */
     154  #define TARGET_GAS 1
     155  
     156  #undef TARGET_ASM_FILE_START
     157  #define TARGET_ASM_FILE_START pa_hpux64_gas_file_start
     158  
     159  /* This is how we output a null terminated string.  */
     160  #undef STRING_ASM_OP
     161  #define STRING_ASM_OP	"\t.stringz\t"
     162  
     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"
     166  
     167  #define HP_INIT_ARRAY_SECTION_ASM_OP	"\t.section\t.init"
     168  #define GNU_INIT_ARRAY_SECTION_ASM_OP	"\t.section\t.init_array"
     169  #define HP_FINI_ARRAY_SECTION_ASM_OP	"\t.section\t.fini"
     170  #define GNU_FINI_ARRAY_SECTION_ASM_OP	"\t.section\t.fini_array"
     171  
     172  /* We need to override the following two macros defined in elfos.h since
     173     the .comm directive has a different syntax and it can't be used for
     174     local common symbols.  */
     175  #undef ASM_OUTPUT_ALIGNED_COMMON
     176  #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
     177    pa_asm_output_aligned_common (FILE, NAME, SIZE, ALIGN)
     178  
     179  #undef ASM_OUTPUT_ALIGNED_LOCAL
     180  #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)		\
     181    pa_asm_output_aligned_local (FILE, NAME, SIZE, ALIGN)
     182  
     183  /* The define in pa.h doesn't work with the alias attribute.  The
     184     default is ok with the following define for GLOBAL_ASM_OP.  */
     185  #undef TARGET_ASM_GLOBALIZE_LABEL
     186  
     187  /* This is how we globalize a label.  */
     188  #define GLOBAL_ASM_OP	"\t.globl\t"
     189  
     190  /* Hacked version from defaults.h that uses assemble_name_raw
     191     instead of assemble_name.  A symbol in a type directive that
     192     isn't otherwise referenced doesn't cause the symbol to be
     193     placed in the symbol table of the assembled object.  */
     194  #undef ASM_OUTPUT_TYPE_DIRECTIVE
     195  #define ASM_OUTPUT_TYPE_DIRECTIVE(STREAM, NAME, TYPE)		\
     196  do {								\
     197    fputs (TYPE_ASM_OP, STREAM);					\
     198    assemble_name_raw (STREAM, NAME);				\
     199    fputs (", ", STREAM);						\
     200    fprintf (STREAM, TYPE_OPERAND_FMT, TYPE);			\
     201    putc ('\n', STREAM);						\
     202  } while (0)
     203  
     204  /* Hacked version from elfos.h that doesn't output a label.  */
     205  #undef ASM_DECLARE_FUNCTION_NAME
     206  #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)		\
     207  do {								\
     208    ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");		\
     209    ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));		\
     210  } while (0)
     211  
     212  /* The type of external references must be set correctly for the
     213     dynamic loader to work correctly.  This is equivalent to the
     214     HP assembler's .IMPORT directive but relates more directly to
     215     ELF object file types.  */
     216  #undef ASM_OUTPUT_EXTERNAL
     217  #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)			\
     218    pa_hpux_asm_output_external ((FILE), (DECL), (NAME))
     219  #define ASM_OUTPUT_EXTERNAL_REAL(FILE, DECL, NAME)		\
     220  do {								\
     221    if (FUNCTION_NAME_P (NAME))					\
     222      ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");		\
     223    else								\
     224      ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");		\
     225    default_elf_asm_output_external (FILE, DECL, NAME);		\
     226  } while (0)
     227  
     228  /* We need set the type for external libcalls.  Also note that not all
     229     libcall names are passed to targetm.encode_section_info (e.g., __main).
     230     Thus, we also have to do the section encoding if it hasn't been done
     231     already.  */
     232  #undef ASM_OUTPUT_EXTERNAL_LIBCALL
     233  #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN)			\
     234  do {								\
     235    if (!FUNCTION_NAME_P (XSTR (FUN, 0)))				\
     236      pa_encode_label (FUN);					\
     237    ASM_OUTPUT_TYPE_DIRECTIVE (FILE, XSTR (FUN, 0), "function");	\
     238  } while (0)
     239  
     240  /* We need to use the HP style for internal labels.  */
     241  #undef ASM_GENERATE_INTERNAL_LABEL
     242  #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM)		\
     243    do								\
     244      {								\
     245        char *__p;						\
     246        (LABEL)[0] = '*';						\
     247        (LABEL)[1] = (PREFIX)[0];					\
     248        (LABEL)[2] = '$';						\
     249        __p = stpcpy (&(LABEL)[3], &(PREFIX)[1]);			\
     250        sprint_ul (__p, (unsigned long) (NUM));			\
     251      }								\
     252    while (0)
     253  
     254  
     255  #else /* USING_ELFOS_H */
     256  
     257  /* We are not using GAS.  */
     258  #define TARGET_GAS 0
     259  
     260  /* HPUX 11 has the "new" HP assembler.  It's still lousy, but it's a whole
     261     lot better than the assembler shipped with older versions of hpux.
     262     However, it doesn't support weak symbols and is a bad fit with ELF.  */
     263  #undef NEW_HP_ASSEMBLER
     264  #define NEW_HP_ASSEMBLER 1
     265  
     266  /* It looks like DWARF2 will be the easiest debug format to handle on this
     267     platform.  */
     268  #define DWARF2_DEBUGGING_INFO 1
     269  
     270  /* This target uses the ELF object file format.  */
     271  #define OBJECT_FORMAT_ELF
     272  
     273  #undef TARGET_ASM_FILE_START
     274  #define TARGET_ASM_FILE_START pa_hpux64_hpas_file_start
     275  
     276  #undef TEXT_SECTION_ASM_OP
     277  #define TEXT_SECTION_ASM_OP		"\t.SUBSPA $CODE$\n"
     278  #undef READONLY_DATA_SECTION_ASM_OP
     279  #define READONLY_DATA_SECTION_ASM_OP	"\t.SUBSPA $LIT$\n"
     280  #undef DATA_SECTION_ASM_OP
     281  #define DATA_SECTION_ASM_OP		"\t.SUBSPA $DATA$\n"
     282  #undef BSS_SECTION_ASM_OP
     283  #define BSS_SECTION_ASM_OP		"\t.SUBSPA $BSS$\n"
     284  
     285  /* We provide explicit defines for CTORS_SECTION_ASM_OP and
     286     DTORS_SECTION_ASM_OP since we don't yet have support for
     287     named sections with the HP assembler.  */
     288  #undef CTORS_SECTION_ASM_OP
     289  #define CTORS_SECTION_ASM_OP "\t.SUBSPA \\.ctors,QUAD=1,ALIGN=8,ACCESS=31"
     290  #undef DTORS_SECTION_ASM_OP
     291  #define DTORS_SECTION_ASM_OP "\t.SUBSPA \\.dtors,QUAD=1,ALIGN=8,ACCESS=31"
     292  
     293  #define HP_INIT_ARRAY_SECTION_ASM_OP \
     294    "\t.SUBSPA \\.init,QUAD=1,ALIGN=8,ACCESS=31"
     295  #define GNU_INIT_ARRAY_SECTION_ASM_OP \
     296    "\t.SUBSPA \\.init_array,QUAD=1,ALIGN=8,ACCESS=31"
     297  #define HP_FINI_ARRAY_SECTION_ASM_OP \
     298    "\t.SUBSPA \\.fini,QUAD=1,ALIGN=8,ACCESS=31"
     299  #define GNU_FINI_ARRAY_SECTION_ASM_OP \
     300    "\t.SUBSPA \\.fini_array,QUAD=1,ALIGN=8,ACCESS=31"
     301  
     302  #endif /* USING_ELFOS_H */
     303  
     304  /* The following defines, used to run constructors and destructors with
     305     the SOM linker under HP-UX 11, are not needed.  */
     306  #undef HAS_INIT_SECTION
     307  #undef LD_INIT_SWITCH
     308  #undef LD_FINI_SWITCH
     309  
     310  /* The following STARTFILE_SPEC and ENDFILE_SPEC defines provide the
     311     magic needed to run initializers and finalizers.  */
     312  #undef STARTFILE_SPEC
     313  #if TARGET_HPUX_11_31
     314  #define STARTFILE_SPEC \
     315    "%{!shared: %{!symbolic: crt0%O%s} \
     316       %{munix=95:unix95.o%s} %{munix=98:unix98.o%s} \
     317       %{!munix=93:%{!munix=95:%{!munix=98:unix2003%O%s}}}} \
     318       %{static:crtbeginT%O%s} \
     319     %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
     320  #elif TARGET_HPUX_11_11
     321  #define STARTFILE_SPEC \
     322    "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95.o%s} \
     323       %{!munix=93:%{!munix=95:unix98%O%s}}} %{static:crtbeginT%O%s} \
     324     %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
     325  #else
     326  #define STARTFILE_SPEC \
     327    "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95%O%s}} \
     328     %{static:crtbeginT%O%s} %{!static:%{!shared:crtbegin%O%s} \
     329     %{shared:crtbeginS%O%s}}"
     330  #endif
     331  
     332  /* The libgcc_stub.a and milli.a libraries must come last.  We need
     333     to link with these libraries whenever start files are needed.  */
     334  #undef ENDFILE_SPEC
     335  #define ENDFILE_SPEC \
     336    "%{!shared:crtend%O%s libgcc_stub.a%s} %{shared:crtendS%O%s} milli.a%s"
     337  
     338  /* Since HP uses the .init and .fini sections for array initializers
     339     and finalizers, we need different defines for INIT_SECTION_ASM_OP
     340     and FINI_SECTION_ASM_OP.  With the implementation adopted below,
     341     the sections are not actually used.  However, we still must provide
     342     defines to select the proper code path.  */
     343  #undef INIT_SECTION_ASM_OP
     344  #define INIT_SECTION_ASM_OP ""
     345  #undef FINI_SECTION_ASM_OP
     346  #define FINI_SECTION_ASM_OP ""
     347  
     348  /* We are using array initializers and don't want calls in the INIT
     349     and FINI sections.  */
     350  #undef CRT_CALL_STATIC_FUNCTION
     351  #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)
     352  
     353  /* The init_priority attribute is not supported with HP ld.  This could be
     354     supported if collect2 was used with LD_INIT_SWITCH.  Unfortunately, this
     355     approach doesn't work with GNU ld since HP-UX doesn't support DT_INIT,
     356     and therefore the -init and -fini GNU ld switches.  */
     357  #undef SUPPORTS_INIT_PRIORITY
     358  #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0)
     359  
     360  /* If using HP ld do not call pxdb.  Use size as a program that does nothing
     361     and returns 0.  /bin/true cannot be used because it is a script without
     362     an interpreter.  */
     363  #define INIT_ENVIRONMENT "LD_PXDB=/usr/ccs/bin/size"
     364  
     365  /* The HPUX dynamic linker objects to undefined weak symbols, so do
     366     not use them in gthr-posix.h.  */
     367  #define GTHREAD_USE_WEAK 0
     368  
     369  /* Support attribute weak.  However, the GNU linker only resolves weak
     370     references if they appear in a shared library.  Thus, it is impossible
     371     to create a static executable containing weak symbols.  This is a problem
     372     for the various crt files in libgcc.  We don't want undefined weak
     373     references to __register_frame_info, __deregister_frame_info and
     374     __cxa_finalize introduced by crtbegin.o.  So, we provide an archive
     375     library of empty stub functions to resolve these symbols.  */
     376  #define TARGET_ATTRIBUTE_WEAK