OSDN Git Service

* config/ia64/crtbegin.asm (.fini): Use pc-relative relocs to
[pf3gnuchains/gcc-fork.git] / gcc / config / ia64 / crtbegin.asm
1 /* Copyright (C) 2000, 2001 Free Software Foundation, Inc.
2    Contributed by Jes Sorensen, <Jes.Sorensen@cern.ch>
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    The GNU C Library 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 GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18
19 .section .ctors,"aw","progbits"
20         .align  8
21 __CTOR_LIST__:
22         data8   -1
23
24 .section .dtors,"aw","progbits"
25         .align  8
26 __DTOR_LIST__:
27         data8   -1
28
29 .section .sdata
30         .type dtor_ptr#,@object
31         .size dtor_ptr#,8
32 dtor_ptr:
33         data8   __DTOR_LIST__# + 8
34
35 #ifndef SHARED
36         .type __ia64_app_header#,@object
37         .size __ia64_app_header#,8
38         .global __ia64_app_header
39 __ia64_app_header:
40         data8   @segrel(.Lsegrel_ref#)
41 #endif
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 __dso_handle:
54         data8   0
55 #endif
56         .hidden __dso_handle#
57
58
59 /*
60  * Fragment of the ELF _fini routine that invokes our dtor cleanup.
61  *
62  * We make the call by indirection, because in large programs the 
63  * .fini and .init sections are not in range of the destination, and
64  * we cannot allow the linker to insert a stub at the end of this
65  * fragment of the _fini function.  Further, Itanium does not implement
66  * the long branch instructions, and we do not wish every program to
67  * trap to the kernel for emulation.
68  *
69  * Note that we require __do_global_dtors_aux to preserve the GP,
70  * so that the next fragment in .fini gets the right value.
71  */
72 .section .fini,"ax","progbits"
73         { .mlx
74           movl r2 = @pcrel(__do_global_dtors_aux# - 16)
75         }
76         { .mii
77           mov r3 = ip
78           ;;
79           add r2 = r2, r3
80           ;;
81         }
82         { .mib
83           mov b6 = r2
84           br.call.sptk.many b0 = b6
85           ;;
86         }
87
88 #ifndef SHARED
89 /*
90  * Fragment of the ELF _init routine that sets up __ia64_app_header
91  */
92
93 .section .init,"ax","progbits"
94 .Lsegrel_ref:
95         { .mmi
96           addl r2 = @gprel(__ia64_app_header), gp
97           mov r16 = ip
98           ;;
99         }
100         { .mmi
101           ld8 r3 = [r2]
102           ;;
103           sub r16 = r16, r3
104           ;;
105         }
106         { .mfb
107           st8 [r2] = r16
108           ;;
109         }
110 #endif
111
112 .section .text
113         .align  16
114         .proc   __do_global_dtors_aux#
115 __do_global_dtors_aux:
116 #ifndef SHARED
117         { .mii
118           alloc loc3 = ar.pfs, 0, 4, 1, 0
119           addl loc0 = @gprel(dtor_ptr#), gp
120           mov loc1 = b0
121         }
122         { .mib
123           mov loc2 = gp
124           br.sptk.few 1f
125           ;;
126         }
127 #else
128         /*
129                 if (__cxa_finalize)
130                   __cxa_finalize(__dso_handle)
131         */
132         { .mii
133           alloc loc3 = ar.pfs, 0, 4, 1, 0
134           addl loc0 = @gprel(dtor_ptr#), gp
135           addl r16 = @ltoff(@fptr(__cxa_finalize#)), gp
136           ;;
137         }
138         { .mmi
139           ld8 r16 = [r16]
140           ;;
141           addl out0 = @ltoff(__dso_handle#), gp
142           cmp.ne p7, p0 = r0, r16
143           ;;
144         }
145         { .mmi
146           ld8 out0 = [out0]
147 (p7)      ld8 r18 = [r16], 8
148           mov loc1 = b0
149           ;;
150         }
151         { .mfi
152           mov loc2 = gp
153 (p7)      mov b6 = r18
154         }
155         {
156           .mfb
157 (p7)      ld8 gp = [r16]
158 (p7)      br.call.sptk.many b0 = b6
159         }
160         { .mfb
161           br.sptk.few 1f
162         }
163 #endif
164         /*
165                 do {
166                   dtor_ptr++;
167                   (*(dtor_ptr-1)) ();
168                 } while (dtor_ptr);
169         */
170 0:
171         { .mmi
172           st8 [loc0] = r15
173           ld8 r17 = [r16], 8
174           ;;
175         }
176         { .mib
177           ld8 gp = [r16]
178           mov b6 = r17
179           br.call.sptk.many b0 = b6
180         }
181 1:
182         { .mmi
183           ld8 r15 = [loc0]
184           ;;
185           ld8 r16 = [r15], 8
186           ;;
187         }
188         { .mfb
189           cmp.ne p6, p0 = r0, r16
190 (p6)      br.cond.sptk.few 0b
191         }
192         { .mii
193           mov gp = loc2
194           mov b0 = loc1
195           mov ar.pfs = loc3
196         }
197         { .bbb
198           br.ret.sptk.many b0
199           ;;
200         }
201         .endp   __do_global_dtors_aux#
202
203 #ifdef SHARED
204 .weak __cxa_finalize#
205 #endif