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