arm: Unless arm4t, pop return address directly into pc
[glibc.git] / ports / sysdeps / arm / dl-tlsdesc.S
blobe810d0db3787eddb67130b1b681be1145e2f8504
1 /* Thread-local storage handling in the ELF dynamic linker.  ARM version.
2    Copyright (C) 2006-2013 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library.  If not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #include <tls.h>
21 #include "tlsdesc.h"
23         .text
24         @ emit debug information with cfi
25         @ use arm-specific pseudos for unwinding itself
26         CFI_SECTIONS
27         .hidden _dl_tlsdesc_return
28         .global _dl_tlsdesc_return
29         .type   _dl_tlsdesc_return,#function
30         cfi_startproc
31         .fnstart
32         .align 2
33 _dl_tlsdesc_return:
34         ldr     r0, [r0]
35         BX      (lr)
36         .fnend
37         cfi_endproc
38         .size   _dl_tlsdesc_return, .-_dl_tlsdesc_return
40         .hidden _dl_tlsdesc_undefweak
41         .global _dl_tlsdesc_undefweak
42         .type   _dl_tlsdesc_undefweak,#function
43         cfi_startproc
44         .fnstart
45         .align 2
46 _dl_tlsdesc_undefweak:
47         GET_TLS (r1)
48         rsb     r0, r0, #0
49         BX      (lr)
50         cfi_endproc
51         .fnend
52         .size   _dl_tlsdesc_undefweak, .-_dl_tlsdesc_undefweak
54 #ifdef SHARED
55         .hidden _dl_tlsdesc_dynamic
56         .global _dl_tlsdesc_dynamic
57         .type   _dl_tlsdesc_dynamic,#function
61         The assembly code that follows is a rendition of the following
62         C code, hand-optimized a little bit.
64 ptrdiff_t
65 _dl_tlsdesc_dynamic(struct tlsdesc *tdp)
67        struct tlsdesc_dynamic_arg *td = tdp->argument.pointer;
68        dtv_t *dtv = (dtv_t *)THREAD_DTV();
69        if (__builtin_expect (td->gen_count <= dtv[0].counter
70                              && dtv[td->tlsinfo.ti_module].pointer.val
71                                 != TLS_DTV_UNALLOCATED,
72                              1))
73                return dtv[td->tlsinfo.ti_module].pointer.val +
74                        td->tlsinfo.ti_offset - __builtin_thread_pointer();
76        return __tls_get_addr (&td->tlsinfo) - __builtin_thread_pointer();
80         cfi_startproc
81         .fnstart
82         .align 2
83 _dl_tlsdesc_dynamic:
84         /* Our calling convention is to clobber r0, r1 and the processor
85            flags.  All others that are modified must be saved */
86         .save   {r2,r3,r4,lr}
87         push    {r2,r3,r4,lr}
88         cfi_adjust_cfa_offset (16)
89         cfi_rel_offset (r2,0)
90         cfi_rel_offset (r3,4)
91         cfi_rel_offset (r4,8)
92         cfi_rel_offset (lr,12)
93         ldr     r1, [r0] /* td */
94         GET_TLS (lr)
95         mov     r4, r0 /* r4 = tp */
96         ldr     r0, [r0]
97         ldr     r2, [r1, #8] /* gen_count */
98         ldr     r3, [r0]
99         cmp     r2, r3
100         bhi     1f
101         ldr     r3, [r1]
102         ldr     r2, [r0, r3, lsl #3]
103         cmn     r2, #1
104         ittt    ne
105         ldrne   r3, [r1, #4]
106         addne   r3, r2, r3
107         rsbne   r0, r4, r3
108         bne     2f
109 1:      mov     r0, r1
110         bl      __tls_get_addr
111         rsb     r0, r4, r0
113 #if defined (__ARM_ARCH_4T__) && defined (__THUMB_INTERWORK__)
114         pop     {r2,r3,r4, lr}
115         cfi_adjust_cfa_offset (-16)
116         cfi_restore (lr)
117         cfi_restore (r4)
118         cfi_restore (r3)
119         cfi_restore (r2)
120         bx      lr
121 #else
122         pop     {r2,r3,r4, pc}
123 #endif
124         .fnend
125         cfi_endproc
126         .size   _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic
127 #endif /* SHARED */
129 /* lazy resolved for tls descriptors.  */
130         .hidden _dl_tlsdesc_lazy_resolver
131         .global _dl_tlsdesc_lazy_resolver
132         .type   _dl_tlsdesc_lazy_resolver,#function
133         cfi_startproc
134         .fnstart
135         .align 2
136 _dl_tlsdesc_lazy_resolver:
137         /* r0 points at the tlsdesc,
138            r1 points at the GOT
139            r2 was pushed by the trampoline and used as a temp,
140               we need to pop it here.
141           We push the remaining call-clobbered registers here, and also
142           R1 -- to keep the stack correctly aligned.  */
143         /* Tell the unwinder that r2 has already been pushed.  */
144         .save   {r2}
145         cfi_adjust_cfa_offset (4)
146         cfi_rel_offset (r2, 0)
147         .save   {r0,r1,r3,ip,lr}
148         push    {r0, r1, r3, ip, lr}
149         cfi_adjust_cfa_offset (20)
150         cfi_rel_offset (r0, 0)
151         cfi_rel_offset (r1, 4)
152         cfi_rel_offset (r3, 8)
153         cfi_rel_offset (ip, 12)
154         cfi_rel_offset (lr, 16)
155         bl      _dl_tlsdesc_lazy_resolver_fixup
156         pop     {r0, r1, r3, ip, lr}
157         cfi_adjust_cfa_offset (-20)
158         cfi_restore (lr)
159         cfi_restore (ip)
160         cfi_restore (r3)
161         cfi_restore (r1)
162         cfi_restore (r0)
163         pop     {r2}
164         cfi_adjust_cfa_offset (-4)
165         cfi_restore (r2)
166         ldr     r1, [r0, #4]
167         BX      (r1)
168         .fnend
169         cfi_endproc
170         .size   _dl_tlsdesc_lazy_resolver, .-_dl_tlsdesc_lazy_resolver
172 /* Holder for lazy tls descriptors being resolve in another thread.
173    Same ABI as the lazy resolver itself.  */
174         .hidden _dl_tlsdesc_resolve_hold
175         .global _dl_tlsdesc_resolve_hold
176         .type   _dl_tlsdesc_resolve_hold,#function
177         cfi_startproc
178         .fnstart
179         .align 2
180 _dl_tlsdesc_resolve_hold:
181         /* Tell the unwinder that r2 has already been pushed.  */
182         .save   {r2}
183         cfi_adjust_cfa_offset (4)
184         cfi_rel_offset (r2, 0)
185         .save   {r0,r1,r3,ip,lr}
186         push    {r0, r1, r3, ip, lr}
187         cfi_adjust_cfa_offset (20)
188         cfi_rel_offset (r0, 0)
189         cfi_rel_offset (r1, 4)
190         cfi_rel_offset (r3, 8)
191         cfi_rel_offset (ip, 12)
192         cfi_rel_offset (lr, 16)
193         adr     r2, _dl_tlsdesc_resolve_hold
194         bl      _dl_tlsdesc_resolve_hold_fixup
195         pop     {r0, r1, r3, ip, lr}
196         cfi_adjust_cfa_offset (-20)
197         cfi_restore (lr)
198         cfi_restore (ip)
199         cfi_restore (r3)
200         cfi_restore (r1)
201         cfi_restore (r0)
202         pop     {r2}
203         cfi_adjust_cfa_offset (-4)
204         cfi_restore (r2)
205         ldr     r1, [r0, #4]
206         BX      (r1)
207         .fnend
208         cfi_endproc
209         .size   _dl_tlsdesc_resolve_hold, .-_dl_tlsdesc_resolve_hold