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 
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 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 \
60 asm (TEXT_SECTION_ASM_OP);                                              \
61 static 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                                                                         \
71 asm (HP_INIT_ARRAY_SECTION_ASM_OP);                                     \
72 asm (".align 8");                                                       \
73 asm (".dword P%__do_global_ctors_aux");                                 \
74 asm (PA_INIT_FRAME_DUMMY_ASM_OP);                                       \
75 asm (GNU_INIT_ARRAY_SECTION_ASM_OP);                                    \
76 asm (".align 8");                                                       \
77 asm (".dword P%__do_global_ctors_aux");                                 \
78 asm (PA_INIT_FRAME_DUMMY_ASM_OP);                                       \
79 asm (HP_FINI_ARRAY_SECTION_ASM_OP);                                     \
80 asm (".align 8");                                                       \
81 asm (".dword P%__do_global_dtors_aux");                                 \
82 asm (GNU_FINI_ARRAY_SECTION_ASM_OP);                                    \
83 asm (".align 8");                                                       \
84 asm (".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 \
90 asm (DTORS_SECTION_ASM_OP);                                             \
91 STATIC func_ptr __DTOR_LIST__[1]                                        \
92   __attribute__ ((aligned(sizeof(func_ptr))))                           \
93   = { (func_ptr) (-1) };                                                \
94 PA_CRTBEGIN_HACK
95 #else
96 #define DTOR_LIST_BEGIN \
97 STATIC func_ptr __DTOR_LIST__[1]                                        \
98   __attribute__ ((section(".dtors"), aligned(sizeof(func_ptr))))        \
99   = { (func_ptr) (-1) };                                                \
100 PA_CRTBEGIN_HACK
101 #endif
102