1 /* Copyright (C) 2005-2023 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 License as
7 published by the Free Software Foundation; either version 2.1 of the
8 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 <https://www.gnu.org/licenses/>. */
20 #include <libc-symbols.h>
25 #define ip0l PTR_REG (16)
29 /* RELA relocatons are 3 pointers */
30 #define RELA_SIZE (PTR_SIZE * 3)
33 .globl _dl_runtime_resolve
34 .type _dl_runtime_resolve, #function
39 /* AArch64 we get called with:
41 ip1 temp(dl resolver entry point)
46 cfi_rel_offset (lr, 8)
48 /* Note: Saving x9 is not required by the ABI but the assembler requires
49 the immediate values of operand 3 to be a multiple of 16 */
50 stp x8, x9, [sp, #-(80+8*16)]!
51 cfi_adjust_cfa_offset (80+8*16)
52 cfi_rel_offset (x8, 0)
53 cfi_rel_offset (x9, 8)
56 cfi_rel_offset (x6, 16)
57 cfi_rel_offset (x7, 24)
60 cfi_rel_offset (x4, 32)
61 cfi_rel_offset (x5, 40)
64 cfi_rel_offset (x2, 48)
65 cfi_rel_offset (x3, 56)
68 cfi_rel_offset (x0, 64)
69 cfi_rel_offset (x1, 72)
71 stp q0, q1, [sp, #(80+0*16)]
72 cfi_rel_offset (q0, 80+0*16)
73 cfi_rel_offset (q1, 80+1*16)
75 stp q2, q3, [sp, #(80+2*16)]
76 cfi_rel_offset (q0, 80+2*16)
77 cfi_rel_offset (q1, 80+3*16)
79 stp q4, q5, [sp, #(80+4*16)]
80 cfi_rel_offset (q0, 80+4*16)
81 cfi_rel_offset (q1, 80+5*16)
83 stp q6, q7, [sp, #(80+6*16)]
84 cfi_rel_offset (q0, 80+6*16)
85 cfi_rel_offset (q1, 80+7*16)
87 /* Get pointer to linker struct. */
88 ldr PTR_REG (0), [ip0, #-PTR_SIZE]
90 /* Prepare to call _dl_fixup(). */
91 ldr x1, [sp, 80+8*16] /* Recover &PLTGOT[n] */
94 add x1, x1, x1, lsl #1
96 sub x1, x1, #(RELA_SIZE<<3)
99 /* Call fixup routine. */
102 /* Save the return. */
105 /* Get arguments and return address back. */
106 ldp q0, q1, [sp, #(80+0*16)]
107 ldp q2, q3, [sp, #(80+2*16)]
108 ldp q4, q5, [sp, #(80+4*16)]
109 ldp q6, q7, [sp, #(80+6*16)]
110 ldp x0, x1, [sp, #64]
111 ldp x2, x3, [sp, #48]
112 ldp x4, x5, [sp, #32]
113 ldp x6, x7, [sp, #16]
114 ldp x8, x9, [sp], #(80+8*16)
115 cfi_adjust_cfa_offset (-(80+8*16))
117 ldp ip1, lr, [sp], #16
118 cfi_adjust_cfa_offset (-16)
120 /* Jump to the newly found address. */
124 .size _dl_runtime_resolve, .-_dl_runtime_resolve
126 .globl _dl_runtime_profile
127 .type _dl_runtime_profile, #function
131 # if HAVE_AARCH64_PAC_RET
137 /* AArch64 we get called with:
139 ip1 temp(dl resolver entry point)
145 [sp, #...] &PLTGOT[n]
146 [sp, #256] La_aarch64_regs
147 [sp, #48] La_aarch64_retval
148 [sp, #40] frame size return from pltenter
149 [sp, #32] dl_profile_call saved x1
150 [sp, #24] dl_profile_call saved x0
152 [sp, #0] x29, lr <- x29
155 # define OFFSET_T1 16
156 # define OFFSET_SAVED_CALL_X0 OFFSET_T1 + 8
157 # define OFFSET_FS OFFSET_SAVED_CALL_X0 + 16
158 # define OFFSET_RV OFFSET_FS + 8
159 # define OFFSET_RG OFFSET_RV + DL_SIZEOF_RV
161 # define SF_SIZE OFFSET_RG + DL_SIZEOF_RG
163 # define OFFSET_PLTGOTN SF_SIZE
164 # define OFFSET_LR OFFSET_PLTGOTN + 8
166 /* Save arguments. */
168 cfi_adjust_cfa_offset (SF_SIZE)
169 stp x29, x30, [SP, #0]
171 cfi_def_cfa_register (x29)
172 cfi_rel_offset (x29, 0)
173 cfi_rel_offset (lr, 8)
175 stp x0, x1, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*0]
176 cfi_rel_offset (x0, OFFSET_RG + DL_OFFSET_RG_X0 + 16*0 + 0)
177 cfi_rel_offset (x1, OFFSET_RG + DL_OFFSET_RG_X0 + 16*0 + 8)
178 stp x2, x3, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*1]
179 cfi_rel_offset (x2, OFFSET_RG + DL_OFFSET_RG_X0 + 16*1 + 0)
180 cfi_rel_offset (x3, OFFSET_RG + DL_OFFSET_RG_X0 + 16*1 + 8)
181 stp x4, x5, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*2]
182 cfi_rel_offset (x4, OFFSET_RG + DL_OFFSET_RG_X0 + 16*2 + 0)
183 cfi_rel_offset (x5, OFFSET_RG + DL_OFFSET_RG_X0 + 16*2 + 8)
184 stp x6, x7, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*3]
185 cfi_rel_offset (x6, OFFSET_RG + DL_OFFSET_RG_X0 + 16*3 + 0)
186 cfi_rel_offset (x7, OFFSET_RG + DL_OFFSET_RG_X0 + 16*3 + 8)
187 str x8, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*4 + 0]
188 cfi_rel_offset (x8, OFFSET_RG + DL_OFFSET_RG_X0 + 16*4 + 0)
189 /* Note 8 bytes of padding is in the stack frame for alignment */
191 stp q0, q1, [X29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*0]
192 cfi_rel_offset (q0, OFFSET_RG + DL_OFFSET_RG_V0 + 32*0)
193 cfi_rel_offset (q1, OFFSET_RG + DL_OFFSET_RG_V0 + 32*0 + 16)
194 stp q2, q3, [X29, #OFFSET_RG+ DL_OFFSET_RG_V0 + 32*1]
195 cfi_rel_offset (q2, OFFSET_RG + DL_OFFSET_RG_V0 + 32*1 + 0)
196 cfi_rel_offset (q3, OFFSET_RG + DL_OFFSET_RG_V0 + 32*1 + 16)
197 stp q4, q5, [X29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*2]
198 cfi_rel_offset (q4, OFFSET_RG + DL_OFFSET_RG_V0 + 32*2 + 0)
199 cfi_rel_offset (q5, OFFSET_RG + DL_OFFSET_RG_V0 + 32*2 + 16)
200 stp q6, q7, [X29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*3]
201 cfi_rel_offset (q6, OFFSET_RG + DL_OFFSET_RG_V0 + 32*3 + 0)
202 cfi_rel_offset (q7, OFFSET_RG + DL_OFFSET_RG_V0 + 32*3 + 16)
204 /* No APCS extension supported. */
205 str xzr, [X29, #OFFSET_RG + DL_OFFSET_RG_VPCS]
207 add x0, x29, #SF_SIZE + 16
208 ldr x1, [x29, #OFFSET_LR]
209 stp x0, x1, [x29, #OFFSET_RG + DL_OFFSET_RG_SP]
211 /* Get pointer to linker struct. */
212 ldr PTR_REG (0), [ip0, #-PTR_SIZE]
214 /* Prepare to call _dl_profile_fixup(). */
215 ldr x1, [x29, OFFSET_PLTGOTN] /* Recover &PLTGOT[n] */
218 add x1, x1, x1, lsl #1
220 sub x1, x1, #(RELA_SIZE<<3)
223 stp x0, x1, [x29, #OFFSET_SAVED_CALL_X0]
225 /* Set up extra args for _dl_profile_fixup */
226 ldr x2, [x29, #OFFSET_LR] /* load saved LR */
227 add x3, x29, #OFFSET_RG /* address of La_aarch64_reg */
228 add x4, x29, #OFFSET_FS /* address of framesize */
231 ldr ip0l, [x29, #OFFSET_FS] /* framesize == 0 */
236 /* Save the return. */
239 /* Get arguments and return address back. */
240 ldp x0, x1, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*0]
241 ldp x2, x3, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*1]
242 ldp x4, x5, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*2]
243 ldp x6, x7, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*3]
244 ldr x8, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*4]
245 ldp q0, q1, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*0]
246 ldp q2, q3, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*1]
247 ldp q4, q5, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*2]
248 ldp q6, q7, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*3]
250 cfi_def_cfa_register (sp)
251 ldp x29, x30, [x29, #0]
255 # if HAVE_AARCH64_PAC_RET
257 cfi_adjust_cfa_offset (-SF_SIZE)
261 cfi_adjust_cfa_offset (-16)
263 add sp, sp, SF_SIZE + 16
264 cfi_adjust_cfa_offset (- SF_SIZE - 16)
267 /* Jump to the newly found address. */
272 /* The new frame size is in ip0. */
274 sub PTR_REG (1), PTR_REG (29), ip0l
275 and sp, x1, #0xfffffffffffffff0
277 str x0, [x29, #OFFSET_T1]
280 add x1, x29, #SF_SIZE + 16
284 ldr ip0, [x29, #OFFSET_T1]
286 /* Call the function. */
287 ldp x0, x1, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*0]
288 ldp x2, x3, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*1]
289 ldp x4, x5, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*2]
290 ldp x6, x7, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*3]
291 ldr x8, [x29, #OFFSET_RG + DL_OFFSET_RG_X0 + 16*4]
292 ldp q0, q1, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*0]
293 ldp q2, q3, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*1]
294 ldp q4, q5, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*2]
295 ldp q6, q7, [x29, #OFFSET_RG + DL_OFFSET_RG_V0 + 32*3]
297 stp x0, x1, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*0]
298 stp x2, x3, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*1]
299 stp x4, x5, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*2]
300 stp x6, x7, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*3]
301 stp q0, q1, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*0]
302 stp q2, q3, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*1]
303 stp q4, q5, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*2]
304 stp q6, q7, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*3]
305 str xzr, [X29, #OFFSET_RV + DL_OFFSET_RV_VPCS]
307 /* Setup call to pltexit */
308 ldp x0, x1, [x29, #OFFSET_SAVED_CALL_X0]
309 add x2, x29, #OFFSET_RG
310 add x3, x29, #OFFSET_RV
313 ldp x0, x1, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*0]
314 ldp x2, x3, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*1]
315 ldp x4, x5, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*2]
316 ldp x6, x7, [x29, #OFFSET_RV + DL_OFFSET_RV_X0 + 16*3]
317 ldp q0, q1, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*0]
318 ldp q2, q3, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*1]
319 ldp q4, q5, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*2]
320 ldp q6, q7, [x29, #OFFSET_RV + DL_OFFSET_RV_V0 + 32*3]
322 /* LR from within La_aarch64_reg */
323 ldr lr, [x29, #OFFSET_RG + DL_OFFSET_RG_LR]
325 # if HAVE_AARCH64_PAC_RET
326 /* Note: LR restored from La_aarch64_reg has no PAC. */
330 cfi_def_cfa_register (sp)
333 add sp, sp, SF_SIZE + 16
334 cfi_adjust_cfa_offset (- SF_SIZE - 16)
339 .size _dl_runtime_profile, .-_dl_runtime_profile