annotate libgcc/config/arc/initfini.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* .init/.fini section handling + C++ global constructor/destructor handling.
kono
parents:
diff changeset
2 This file is based on crtstuff.c, sol2-crti.asm, sol2-crtn.asm.
kono
parents:
diff changeset
3
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
4 Copyright (C) 1995-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
5 Contributor: Joern Rennecke <joern.rennecke@embecosm.com>
kono
parents:
diff changeset
6 on behalf of Synopsys Inc.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 This file is part of GCC.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
11 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
12 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
13 any later version.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
18 GNU General Public License for more details.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
21 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
22 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
25 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
26 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
27 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 /* Declare a pointer to void function type. */
kono
parents:
diff changeset
30 typedef void (*func_ptr) (void);
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 #ifdef CRT_INIT
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 /* NOTE: In order to be able to support SVR4 shared libraries, we arrange
kono
parents:
diff changeset
35 to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
kono
parents:
diff changeset
36 __DTOR_END__ } per root executable and also one set of these symbols
kono
parents:
diff changeset
37 per shared library. So in any given whole process image, we may have
kono
parents:
diff changeset
38 multiple definitions of each of these symbols. In order to prevent
kono
parents:
diff changeset
39 these definitions from conflicting with one another, and in order to
kono
parents:
diff changeset
40 ensure that the proper lists are used for the initialization/finalization
kono
parents:
diff changeset
41 of each individual shared library (respectively), we give these symbols
kono
parents:
diff changeset
42 only internal (i.e. `static') linkage, and we also make it a point to
kono
parents:
diff changeset
43 refer to only the __CTOR_END__ symbol in crtfini.o and the __DTOR_LIST__
kono
parents:
diff changeset
44 symbol in crtinit.o, where they are defined. */
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 static func_ptr __CTOR_LIST__[1] __attribute__ ((section (".ctors")))
kono
parents:
diff changeset
47 = { (func_ptr) (-1) };
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 static func_ptr __DTOR_LIST__[1] __attribute__ ((section (".dtors")))
kono
parents:
diff changeset
50 = { (func_ptr) (-1) };
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 /* Run all the global destructors on exit from the program. */
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 /* Some systems place the number of pointers in the first word of the
kono
parents:
diff changeset
55 table. On SVR4 however, that word is -1. In all cases, the table is
kono
parents:
diff changeset
56 null-terminated. On SVR4, we start from the beginning of the list and
kono
parents:
diff changeset
57 invoke each per-compilation-unit destructor routine in order
kono
parents:
diff changeset
58 until we find that null.
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 Note that this function MUST be static. There will be one of these
kono
parents:
diff changeset
61 functions in each root executable and one in each shared library, but
kono
parents:
diff changeset
62 although they all have the same code, each one is unique in that it
kono
parents:
diff changeset
63 refers to one particular associated `__DTOR_LIST__' which belongs to the
kono
parents:
diff changeset
64 same particular root executable or shared library file. */
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 static void __do_global_dtors (void)
kono
parents:
diff changeset
67 asm ("__do_global_dtors") __attribute__ ((section (".text")));
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 static void
kono
parents:
diff changeset
70 __do_global_dtors (void)
kono
parents:
diff changeset
71 {
kono
parents:
diff changeset
72 func_ptr *p;
kono
parents:
diff changeset
73 for (p = __DTOR_LIST__ + 1; *p; p++)
kono
parents:
diff changeset
74 (*p) ();
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* .init section start.
kono
parents:
diff changeset
78 This must appear at the start of the .init section. */
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 asm ("\n\
kono
parents:
diff changeset
81 .section .init\n\
kono
parents:
diff changeset
82 .global init\n\
kono
parents:
diff changeset
83 .word 0\n\
kono
parents:
diff changeset
84 init:\n\
kono
parents:
diff changeset
85 st blink,[sp,4]\n\
kono
parents:
diff changeset
86 st fp,[sp]\n\
kono
parents:
diff changeset
87 mov fp,sp\n\
kono
parents:
diff changeset
88 sub sp,sp,16\n\
kono
parents:
diff changeset
89 ");
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 /* .fini section start.
kono
parents:
diff changeset
92 This must appear at the start of the .init section. */
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 asm ("\n\
kono
parents:
diff changeset
95 .section .fini\n\
kono
parents:
diff changeset
96 .global fini\n\
kono
parents:
diff changeset
97 .word 0\n\
kono
parents:
diff changeset
98 fini:\n\
kono
parents:
diff changeset
99 st blink,[sp,4]\n\
kono
parents:
diff changeset
100 st fp,[sp]\n\
kono
parents:
diff changeset
101 mov fp,sp\n\
kono
parents:
diff changeset
102 sub sp,sp,16\n\
kono
parents:
diff changeset
103 bl.nd __do_global_dtors\n\
kono
parents:
diff changeset
104 ");
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 #endif /* CRT_INIT */
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 #ifdef CRT_FINI
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 /* Put a word containing zero at the end of each of our two lists of function
kono
parents:
diff changeset
111 addresses. Note that the words defined here go into the .ctors and .dtors
kono
parents:
diff changeset
112 sections of the crtend.o file, and since that file is always linked in
kono
parents:
diff changeset
113 last, these words naturally end up at the very ends of the two lists
kono
parents:
diff changeset
114 contained in these two sections. */
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 static func_ptr __CTOR_END__[1] __attribute__ ((section (".ctors")))
kono
parents:
diff changeset
117 = { (func_ptr) 0 };
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 static func_ptr __DTOR_END__[1] __attribute__ ((section (".dtors")))
kono
parents:
diff changeset
120 = { (func_ptr) 0 };
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 /* Run all global constructors for the program.
kono
parents:
diff changeset
123 Note that they are run in reverse order. */
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 static void __do_global_ctors (void)
kono
parents:
diff changeset
126 asm ("__do_global_ctors") __attribute__ ((section (".text")));
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 static void
kono
parents:
diff changeset
129 __do_global_ctors (void)
kono
parents:
diff changeset
130 {
kono
parents:
diff changeset
131 func_ptr *p;
kono
parents:
diff changeset
132 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
kono
parents:
diff changeset
133 (*p) ();
kono
parents:
diff changeset
134 }
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 /* .init section end.
kono
parents:
diff changeset
137 This must live at the end of the .init section. */
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 asm ("\n\
kono
parents:
diff changeset
140 .section .init\n\
kono
parents:
diff changeset
141 bl.nd __do_global_ctors\n\
kono
parents:
diff changeset
142 ld blink,[fp,4]\n\
kono
parents:
diff changeset
143 j.d blink\n\
kono
parents:
diff changeset
144 ld.a fp,[sp,16]\n\
kono
parents:
diff changeset
145 ");
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 /* .fini section end.
kono
parents:
diff changeset
148 This must live at the end of the .fini section. */
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 asm ("\n\
kono
parents:
diff changeset
151 .section .fini\n\
kono
parents:
diff changeset
152 ld blink,[fp,4]\n\
kono
parents:
diff changeset
153 j.d blink\n\
kono
parents:
diff changeset
154 ld.a fp,[sp,16]\n\
kono
parents:
diff changeset
155 ");
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 #endif /* CRT_FINI */