pa64-hpux-lib.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Definitions of target machine for GNU compiler, for HPs running
  2. HP-UX using the 64bit runtime model.
  3. Copyright (C) 1999-2022 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. /* We use DTOR_LIST_BEGIN to carry a bunch of hacks to allow us to use
  21. the init and fini array sections with both the HP and GNU linkers.
  22. The linkers setup the required dynamic entries in the dynamic segment
  23. and the dynamic linker does the calls. This approach avoids using
  24. collect2.
  25. The first hack is to implement __do_global_ctors_aux in crtbegin as
  26. it needs to be the first entry in the init array so that it is called
  27. last. HP got the order of the init array backwards. The DT_INIT_ARRAY
  28. is supposed to be executed in the same order as the addresses appear in
  29. the array. DT_FINI_ARRAY is supposed to be executed in the opposite
  30. order.
  31. The second hack is a set of plabels to implement the effect of
  32. CRT_CALL_STATIC_FUNCTION. HP-UX 11 only supports DI_INIT_ARRAY and
  33. DT_FINI_ARRAY and they put the arrays in .init and .fini, rather than
  34. in .init_array and .fini_array. The standard defines for .init and
  35. .fini have the execute flag set. So, the assembler has to be hacked
  36. to munge the standard flags for these sections to make them agree
  37. with what the HP linker expects. With the GNU linker, we need to
  38. used the .init_array and .fini_array sections. So, we set up for
  39. both just in case. Once we have built the table, the linker does
  40. the rest of the work.
  41. The order is significant. Placing __do_global_ctors_aux first in
  42. the list, results in it being called last. User specified initializers,
  43. either using the linker +init command or a plabel, run before the
  44. initializers specified here. */
  45. /* We need to add frame_dummy to the initializer list if EH_FRAME_SECTION_NAME
  46. is defined. */
  47. #if defined(__LIBGCC_EH_FRAME_SECTION_NAME__)
  48. #define PA_INIT_FRAME_DUMMY_ASM_OP ".dword P%frame_dummy"
  49. #else
  50. #define PA_INIT_FRAME_DUMMY_ASM_OP ""
  51. #endif
  52. /* The following hack sets up the .init, .init_array, .fini and
  53. .fini_array sections. */
  54. #define PA_CRTBEGIN_HACK \
  55. asm (TEXT_SECTION_ASM_OP); \
  56. static void __attribute__((used)) \
  57. __do_global_ctors_aux (void) \
  58. { \
  59. func_ptr *p = __CTOR_LIST__; \
  60. while (*(p + 1)) \
  61. p++; \
  62. for (; *p != (func_ptr) -1; p--) \
  63. (*p) (); \
  64. } \
  65. \
  66. asm (HP_INIT_ARRAY_SECTION_ASM_OP); \
  67. asm (".align 8"); \
  68. asm (".dword P%__do_global_ctors_aux"); \
  69. asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
  70. asm (GNU_INIT_ARRAY_SECTION_ASM_OP); \
  71. asm (".align 8"); \
  72. asm (".dword P%__do_global_ctors_aux"); \
  73. asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
  74. asm (HP_FINI_ARRAY_SECTION_ASM_OP); \
  75. asm (".align 8"); \
  76. asm (".dword P%__do_global_dtors_aux"); \
  77. asm (GNU_FINI_ARRAY_SECTION_ASM_OP); \
  78. asm (".align 8"); \
  79. asm (".dword P%__do_global_dtors_aux")
  80. /* The following two variants of DTOR_LIST_BEGIN are identical to those
  81. in crtstuff.c except for the addition of the above crtbegin hack. */
  82. #ifdef __LIBGCC_DTORS_SECTION_ASM_OP__
  83. #define DTOR_LIST_BEGIN \
  84. asm (DTORS_SECTION_ASM_OP); \
  85. STATIC func_ptr __DTOR_LIST__[1] \
  86. __attribute__ ((aligned(sizeof(func_ptr)))) \
  87. = { (func_ptr) (-1) }; \
  88. PA_CRTBEGIN_HACK
  89. #else
  90. #define DTOR_LIST_BEGIN \
  91. STATIC func_ptr __DTOR_LIST__[1] \
  92. __attribute__ ((section(".dtors"), aligned(sizeof(func_ptr)))) \
  93. = { (func_ptr) (-1) }; \
  94. PA_CRTBEGIN_HACK
  95. #endif