crtbegin.S revision 1.8
1/* Copyright (C) 2000-2019 Free Software Foundation, Inc.
2   Contributed by Jes Sorensen, <Jes.Sorensen@cern.ch>
3
4   This file is part of GCC.
5
6   GCC is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 3, or (at your option)
9   any later version.
10
11   GCC is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   Under Section 7 of GPL version 3, you are granted additional
17   permissions described in the GCC Runtime Library Exception, version
18   3.1, as published by the Free Software Foundation.
19
20   You should have received a copy of the GNU General Public License and
21   a copy of the GCC Runtime Library Exception along with this program;
22   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23   <http://www.gnu.org/licenses/>.  */
24
25#include "auto-host.h"
26
27.section .ctors,"aw","progbits"
28	.align	8
29__CTOR_LIST__:
30	data8	-1
31
32.section .dtors,"aw","progbits"
33	.align	8
34__DTOR_LIST__:
35	data8	-1
36
37.section .sdata
38	.type dtor_ptr,@object
39	.size dtor_ptr,8
40dtor_ptr:
41	data8	@gprel(__DTOR_LIST__ + 8)
42
43	/* A handle for __cxa_finalize to manage c++ local destructors.  */
44	.global __dso_handle
45	.type __dso_handle,@object
46	.size __dso_handle,8
47#ifdef SHARED
48	.section .data
49__dso_handle:
50	data8	__dso_handle
51#else
52	.section .bss
53	.align 8
54__dso_handle:
55	.skip	8
56#endif
57	.hidden __dso_handle
58
59
60#if HAVE_INITFINI_ARRAY_SUPPORT
61
62.section .fini_array, "a"
63	data8 @fptr(__do_global_dtors_aux)
64
65.section .init_array, "a"
66	data8 @fptr(__do_global_ctors_aux)
67
68#else /* !HAVE_INITFINI_ARRAY_SUPPORT */
69/*
70 * Fragment of the ELF _fini routine that invokes our dtor cleanup.
71 *
72 * We make the call by indirection, because in large programs the
73 * .fini and .init sections are not in range of the destination, and
74 * we cannot allow the linker to insert a stub at the end of this
75 * fragment of the _fini function.  Further, Itanium does not implement
76 * the long branch instructions, and we do not wish every program to
77 * trap to the kernel for emulation.
78 *
79 * Note that we require __do_global_dtors_aux to preserve the GP,
80 * so that the next fragment in .fini gets the right value.
81 */
82.section .fini,"ax","progbits"
83	{ .mlx
84	  movl r2 = @pcrel(__do_global_dtors_aux - 16)
85	}
86	{ .mii
87	  mov r3 = ip
88	  ;;
89	  add r2 = r2, r3
90	  ;;
91	}
92	{ .mib
93	  nop 0
94	  mov b6 = r2
95	  br.call.sptk.many b0 = b6
96	}
97#endif /* !HAVE_INITFINI_ARRAY_SUPPORT */
98
99.section .text
100	.align	32
101	.proc	__do_global_dtors_aux
102__do_global_dtors_aux:
103	.prologue
104#ifndef SHARED
105	.save ar.pfs, r35
106	alloc loc3 = ar.pfs, 0, 4, 1, 0
107	addl loc0 = @gprel(dtor_ptr), gp
108	.save rp, loc1
109	mov loc1 = rp
110	.body
111
112	mov loc2 = gp
113	nop 0
114	br.sptk.many .entry
115#else
116	/*
117		if (__cxa_finalize)
118		  __cxa_finalize(__dso_handle)
119	*/
120	.save ar.pfs, r35
121	alloc loc3 = ar.pfs, 0, 4, 1, 0
122	addl loc0 = @gprel(dtor_ptr), gp
123	addl r16 = @ltoff(@fptr(__cxa_finalize)), gp
124	;;
125
126	ld8 r16 = [r16]
127	;;
128	addl out0 = @ltoff(__dso_handle), gp
129	cmp.ne p7, p0 = r0, r16
130	;;
131
132	ld8 out0 = [out0]
133(p7)	ld8 r18 = [r16], 8
134	.save rp, loc1
135	mov loc1 = rp
136	.body
137	;;
138
139	mov loc2 = gp
140(p7)	ld8 gp = [r16]
141(p7)	mov b6 = r18
142
143	nop 0
144	nop 0
145(p7)	br.call.sptk.many rp = b6
146	;;
147
148	nop 0
149	nop 0
150	br.sptk.many .entry
151#endif
152	/*
153		do {
154		  dtor_ptr++;
155		  (*(dtor_ptr-1)) ();
156		} while (dtor_ptr);
157	*/
158.loop:
159	st8 [loc0] = r15		// update dtor_ptr (in memory)
160	ld8 r17 = [r16], 8		// r17 <- dtor's entry-point
161	nop 0
162	;;
163
164	ld8 gp = [r16]			// gp <- dtor's gp
165	mov b6 = r17
166	br.call.sptk.many rp = b6
167
168.entry:	ld8 r15 = [loc0]		// r15 <- dtor_ptr (gp-relative)
169	;;
170	add r16 = r15, loc2		// r16 <- dtor_ptr (absolute)
171	adds r15 = 8, r15
172	;;
173
174	ld8 r16 = [r16]			// r16 <- pointer to dtor's fdesc
175	mov rp = loc1
176	mov ar.pfs = loc3
177	;;
178
179	cmp.ne p6, p0 = r0, r16
180(p6)	br.cond.sptk.few .loop
181	br.ret.sptk.many rp
182	.endp __do_global_dtors_aux
183
184#ifdef SHARED
185.weak __cxa_finalize
186#endif
187.weak _Jv_RegisterClasses
188