2.9
[glibc/nacl-glibc.git] / sysdeps / x86_64 / dl-trampoline.S
blob3e2d18275896dc33b626955926b58dc27b86675b
1 /* PLT trampolines.  x86-64 version.
2    Copyright (C) 2004, 2005, 2007 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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
22         .text
23         .globl _dl_runtime_resolve
24         .type _dl_runtime_resolve, @function
25         .align 16
26         cfi_startproc
27 _dl_runtime_resolve:
28         subq $56,%rsp
29         cfi_adjust_cfa_offset(72) # Incorporate PLT
30         movq %rax,(%rsp)        # Preserve registers otherwise clobbered.
31         movq %rcx, 8(%rsp)
32         movq %rdx, 16(%rsp)
33         movq %rsi, 24(%rsp)
34         movq %rdi, 32(%rsp)
35         movq %r8, 40(%rsp)
36         movq %r9, 48(%rsp)
37         movq 64(%rsp), %rsi     # Copy args pushed by PLT in register.
38         movq %rsi, %r11         # Multiply by 24
39         addq %r11, %rsi
40         addq %r11, %rsi
41         shlq $3, %rsi
42         movq 56(%rsp), %rdi     # %rdi: link_map, %rsi: reloc_offset
43         call _dl_fixup          # Call resolver.
44         movq %rax, %r11         # Save return value
45         movq 48(%rsp), %r9      # Get register content back.
46         movq 40(%rsp), %r8
47         movq 32(%rsp), %rdi
48         movq 24(%rsp), %rsi
49         movq 16(%rsp), %rdx
50         movq 8(%rsp), %rcx
51         movq (%rsp), %rax
52         addq $72, %rsp          # Adjust stack(PLT did 2 pushes)
53         cfi_adjust_cfa_offset(-72)
54         jmp *%r11               # Jump to function address.
55         cfi_endproc
56         .size _dl_runtime_resolve, .-_dl_runtime_resolve
59 #ifndef PROF
60         .globl _dl_runtime_profile
61         .type _dl_runtime_profile, @function
62         .align 16
63         cfi_startproc
64 _dl_runtime_profile:
65         subq $88, %rsp
66         cfi_adjust_cfa_offset(104) # Incorporate PLT
67         movq %rax, (%rsp)       # Preserve registers otherwise clobbered.
68         movq %rdx, 8(%rsp)
69         movq %r8, 16(%rsp)
70         movq %r9, 24(%rsp)
71         movq %rcx, 32(%rsp)
72         movq %rsi, 40(%rsp)
73         movq %rdi, 48(%rsp)
74         movq %rbp, 56(%rsp)     # Information for auditors.
75         leaq 104(%rsp), %rax
76         movq %rax, 64(%rsp)
77         leaq 8(%rsp), %rcx
78         movq 104(%rsp), %rdx    # Load return address if needed
79         movq 96(%rsp), %rsi     # Copy args pushed by PLT in register.
80         movq %rsi,%r11          # Multiply by 24
81         addq %r11,%rsi
82         addq %r11,%rsi
83         shlq $3, %rsi
84         movq 88(%rsp), %rdi     # %rdi: link_map, %rsi: reloc_offset
85         leaq 72(%rsp), %r8
86         call _dl_profile_fixup  # Call resolver.
87         movq %rax, %r11         # Save return value
88         movq 8(%rsp), %rdx      # Get back register content.
89         movq 16(%rsp), %r8
90         movq 24(%rsp), %r9
91         movq (%rsp),%rax
92         movq 72(%rsp), %r10
93         testq %r10, %r10
94         jns 1f
95         movq 32(%rsp), %rcx
96         movq 40(%rsp), %rsi
97         movq 48(%rsp), %rdi
98         addq $104,%rsp          # Adjust stack
99         cfi_adjust_cfa_offset (-104)
100         jmp *%r11               # Jump to function address.
102         /*
103             +104     return address
104             +96     PLT2
105             +88     PLT1
106             +80     free
107             +72     free
108             +64     %rsp
109             +56     %rbp
110             +48     %rdi
111             +40     %rsi
112             +32     %rcx
113             +24     %r9
114             +16     %r8
115             +8      %rdx
116            %rsp     %rax
117         */
118         cfi_adjust_cfa_offset (104)
119 1:      movq %rbx, 72(%rsp)
120         cfi_rel_offset (rbx, 72)
121         leaq 112(%rsp), %rsi
122         movq %rsp, %rbx
123         cfi_def_cfa_register (%rbx)
124         movq %r10, %rcx
125         addq $8, %r10
126         andq $0xfffffffffffffff0, %r10
127         subq %r10, %rsp
128         movq %rsp, %rdi
129         shrq $3, %rcx
130         rep
131         movsq
132         movq 32(%rbx), %rcx
133         movq 40(%rbx), %rsi
134         movq 48(%rbx), %rdi
135         call *%r11
136         movq %rbx, %rsp
137         cfi_def_cfa_register (%rsp)
138         subq $72, %rsp
139         cfi_adjust_cfa_offset (72)
140         movq %rsp, %rcx
141         movq %rax, (%rcx)
142         movq %rdx, 8(%rcx)
143         /* Even though the stack is correctly aligned to allow using movaps
144            we use movups.  Some callers might provide an incorrectly aligned
145            stack and we do not want to have it blow up here.  */
146         movups %xmm0, 16(%rcx)
147         movups %xmm1, 32(%rcx)
148         fstpt 48(%rcx)
149         fstpt 64(%rcx)
150         /*
151             +176    return address
152             +168    PLT2
153             +160    PLT1
154             +152    free
155             +144    free
156             +136    %rsp
157             +128    %rbp
158             +120    %rdi
159             +112    %rsi
160             +104    %rcx
161             +96     %r9
162             +88     %r8
163             +80     %rdx
164             +64     %st1 result
165             +48     %st result
166             +32     %xmm1 result
167             +16     %xmm0 result
168             +8      %rdx result
169            %rsp     %rax result
170         */
171         leaq 80(%rsp), %rdx
172         movq 144(%rsp), %rbx
173         cfi_restore (rbx)
174         movq 168(%rsp), %rsi    # Copy args pushed by PLT in register.
175         movq %rsi,%r11          # Multiply by 24
176         addq %r11,%rsi
177         addq %r11,%rsi
178         shlq $3, %rsi
179         movq 160(%rsp), %rdi    # %rdi: link_map, %rsi: reloc_offset
180         call _dl_call_pltexit
181         movq (%rsp), %rax
182         movq 8(%rsp), %rdx
183         movups 16(%rsp), %xmm0
184         movups 32(%rsp), %xmm1
185         fldt 64(%rsp)
186         fldt 48(%rsp)
187         addq $176, %rsp
188         cfi_adjust_cfa_offset (-176)
189         retq
190         cfi_endproc
191         .size _dl_runtime_profile, .-_dl_runtime_profile
192 #endif