]>
Commit | Line | Data |
---|---|---|
65074d23 | 1 | /* Machine-dependent ELF dynamic relocation inline functions. SH version. |
aff4519d | 2 | Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
65074d23 UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
65074d23 UD |
9 | |
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 | |
41bdb6e2 AJ |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. | |
65074d23 | 14 | |
41bdb6e2 AJ |
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. */ | |
65074d23 UD |
19 | |
20 | #ifndef dl_machine_h | |
21 | #define dl_machine_h | |
22 | ||
23 | /* Only dummy. This doesn't work. */ | |
24 | ||
25 | #define ELF_MACHINE_NAME "SH" | |
26 | ||
27 | #include <sys/param.h> | |
28 | ||
29 | #include <assert.h> | |
30 | ||
ceb579a3 | 31 | /* Return nonzero iff ELF header is compatible with the running host. */ |
65074d23 | 32 | static inline int __attribute__ ((unused)) |
ceb579a3 | 33 | elf_machine_matches_host (const Elf32_Ehdr *ehdr) |
65074d23 | 34 | { |
ceb579a3 | 35 | return ehdr->e_machine == EM_SH; |
65074d23 UD |
36 | } |
37 | ||
38 | ||
39 | /* Return the link-time address of _DYNAMIC. Conveniently, this is the | |
40 | first element of the GOT. This must be inlined in a function which | |
41 | uses global data. */ | |
42 | static inline Elf32_Addr __attribute__ ((unused)) | |
43 | elf_machine_dynamic (void) | |
44 | { | |
45 | register Elf32_Addr *got; | |
46 | asm ("mov r12,%0" :"=r" (got)); | |
47 | return *got; | |
48 | } | |
49 | ||
50 | ||
51 | /* Return the run-time load address of the shared object. */ | |
52 | static inline Elf32_Addr __attribute__ ((unused)) | |
53 | elf_machine_load_address (void) | |
54 | { | |
55 | Elf32_Addr addr; | |
e438a468 UD |
56 | asm ("mov.l 1f,r0\n\ |
57 | mov.l 3f,r2\n\ | |
045fcd26 UD |
58 | add r12,r2\n\ |
59 | mov.l @(r0,r12),r0\n\ | |
e438a468 | 60 | bra 2f\n\ |
045fcd26 UD |
61 | sub r0,r2\n\ |
62 | .align 2\n\ | |
e438a468 UD |
63 | 1: .long _dl_start@GOT\n\ |
64 | 3: .long _dl_start@GOTOFF\n\ | |
65 | 2: mov r2,%0" | |
65074d23 UD |
66 | : "=r" (addr) : : "r0", "r1", "r2"); |
67 | return addr; | |
68 | } | |
69 | ||
70 | ||
71 | /* Set up the loaded object described by L so its unrelocated PLT | |
72 | entries will jump to the on-demand fixup code in dl-runtime.c. */ | |
73 | ||
74 | static inline int __attribute__ ((unused)) | |
75 | elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) | |
76 | { | |
77 | Elf32_Addr *got; | |
78 | extern void _dl_runtime_resolve (Elf32_Word); | |
79 | extern void _dl_runtime_profile (Elf32_Word); | |
80 | ||
81 | if (l->l_info[DT_JMPREL] && lazy) | |
82 | { | |
83 | /* The GOT entries for functions in the PLT have not yet been filled | |
84 | in. Their initial contents will arrange when called to load an | |
85 | offset into the .rela.plt section and _GLOBAL_OFFSET_TABLE_[1], | |
86 | and then jump to _GLOBAL_OFFSET_TABLE[2]. */ | |
87 | got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]); | |
32e6df36 UD |
88 | /* If a library is prelinked but we have to relocate anyway, |
89 | we have to be able to undo the prelinking of .got.plt. | |
90 | The prelinker saved us here address of .plt + 36. */ | |
91 | if (got[1]) | |
92 | { | |
93 | l->l_mach.plt = got[1] + l->l_addr; | |
94 | l->l_mach.gotplt = (Elf32_Addr) &got[3]; | |
95 | } | |
65074d23 UD |
96 | got[1] = (Elf32_Addr) l; /* Identify this shared object. */ |
97 | ||
98 | /* The got[2] entry contains the address of a function which gets | |
99 | called to get the address of a so far unresolved function and | |
100 | jump to it. The profiling extension of the dynamic linker allows | |
101 | to intercept the calls to collect information. In this case we | |
102 | don't store the address in the GOT so that all future calls also | |
103 | end in this function. */ | |
104 | if (profile) | |
105 | { | |
106 | got[2] = (Elf32_Addr) &_dl_runtime_profile; | |
107 | /* Say that we really want profiling and the timers are started. */ | |
5688da55 | 108 | GL(dl_profile_map) = l; |
65074d23 UD |
109 | } |
110 | else | |
111 | /* This function will get called to fix up the GOT entry indicated by | |
112 | the offset on the stack, and then jump to the resolved address. */ | |
113 | got[2] = (Elf32_Addr) &_dl_runtime_resolve; | |
114 | } | |
115 | return lazy; | |
116 | } | |
117 | ||
118 | /* This code is used in dl-runtime.c to call the `fixup' function | |
119 | and then redirect to the address it returns. */ | |
120 | ||
121 | #define ELF_MACHINE_RUNTIME_FIXUP_ARGS int plt_type | |
122 | ||
123 | #ifdef SHARED | |
124 | #define FUN_ADDR "\ | |
045fcd26 UD |
125 | mov.l 1f,r2\n\ |
126 | mova 1f,r0\n\ | |
127 | bra 2f\n\ | |
128 | add r0,r2 ! Get GOT address in r2\n\ | |
129 | 0: .align 2\n\ | |
130 | 1: .long _GLOBAL_OFFSET_TABLE_\n\ | |
131 | 2: mov.l 3f,r0\n\ | |
65074d23 UD |
132 | add r2,r0" |
133 | #define GOTJMP(x) #x "@GOTOFF" | |
134 | #else | |
135 | #define FUN_ADDR "\ | |
136 | mov.l 3f,r0" | |
137 | #define GOTJMP(x) #x | |
138 | #endif | |
139 | ||
afa0db7a | 140 | #ifdef HAVE_FPU |
65074d23 | 141 | #define FGR_SAVE "\ |
045fcd26 UD |
142 | sts.l fpscr, @-r15\n\ |
143 | mov #8,r3\n\ | |
144 | swap.w r3, r3\n\ | |
145 | lds r3, fpscr\n\ | |
146 | fmov.s fr11, @-r15\n\ | |
147 | fmov.s fr10, @-r15\n\ | |
148 | fmov.s fr9, @-r15\n\ | |
149 | fmov.s fr8, @-r15\n\ | |
150 | fmov.s fr7, @-r15\n\ | |
151 | fmov.s fr6, @-r15\n\ | |
152 | fmov.s fr5, @-r15\n\ | |
65074d23 UD |
153 | fmov.s fr4, @-r15" |
154 | #define FGR_LOAD "\ | |
045fcd26 UD |
155 | fmov.s @r15+, fr4\n\ |
156 | fmov.s @r15+, fr5\n\ | |
157 | fmov.s @r15+, fr6\n\ | |
158 | fmov.s @r15+, fr7\n\ | |
159 | fmov.s @r15+, fr8\n\ | |
160 | fmov.s @r15+, fr9\n\ | |
161 | fmov.s @r15+, fr10\n\ | |
162 | fmov.s @r15+, fr11\n\ | |
65074d23 UD |
163 | lds.l @r15+, fpscr" |
164 | #else | |
165 | #define FGR_SAVE "" | |
166 | #define FGR_LOAD "" | |
167 | #endif | |
168 | ||
169 | #ifndef PROF | |
170 | # define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\ | |
045fcd26 UD |
171 | .text\n\ |
172 | .globl _dl_runtime_resolve\n\ | |
173 | .type _dl_runtime_resolve, @function\n\ | |
174 | .align 5\n\ | |
175 | _dl_runtime_resolve:\n\ | |
176 | mov.l r2,@-r15\n\ | |
177 | mov.l r3,@-r15\n\ | |
178 | mov.l r4,@-r15\n\ | |
179 | mov.l r5,@-r15\n\ | |
180 | mov.l r6,@-r15\n\ | |
181 | mov.l r7,@-r15\n\ | |
182 | mov.l r12,@-r15\n\ | |
183 | movt r3 ! Save T flag.\n\ | |
184 | mov.l r3,@-r15\n\ | |
185 | " FGR_SAVE "\n\ | |
186 | sts.l pr,@-r15\n\ | |
187 | tst r0,r0\n\ | |
188 | bt 1f\n\ | |
189 | mov r0,r2\n\ | |
190 | 1:\n\ | |
191 | mov r0,r4 ! PLT type\n\ | |
192 | mov r2,r5 ! link map address\n\ | |
193 | " FUN_ADDR "\n\ | |
194 | jsr @r0 ! Call resolver.\n\ | |
195 | mov r1,r6 ! reloc offset\n\ | |
196 | lds.l @r15+,pr ! Get register content back.\n\ | |
197 | " FGR_LOAD "\n\ | |
198 | mov.l @r15+,r3\n\ | |
199 | shal r3 ! Lode T flag.\n\ | |
200 | mov.l @r15+,r12\n\ | |
201 | mov.l @r15+,r7\n\ | |
202 | mov.l @r15+,r6\n\ | |
203 | mov.l @r15+,r5\n\ | |
204 | mov.l @r15+,r4\n\ | |
205 | mov.l @r15+,r3\n\ | |
206 | jmp @r0 ! Jump to function address.\n\ | |
207 | mov.l @r15+,r2\n\ | |
208 | .align 2\n\ | |
209 | 3:\n\ | |
210 | .long " GOTJMP (fixup) "\n\ | |
211 | .size _dl_runtime_resolve, .-_dl_runtime_resolve\n\ | |
212 | \n\ | |
213 | .globl _dl_runtime_profile\n\ | |
214 | .type _dl_runtime_profile, @function\n\ | |
215 | .align 5\n\ | |
216 | _dl_runtime_profile:\n\ | |
217 | mov.l r2,@-r15\n\ | |
218 | mov.l r3,@-r15\n\ | |
219 | mov.l r4,@-r15\n\ | |
220 | mov.l r5,@-r15\n\ | |
221 | mov.l r6,@-r15\n\ | |
222 | mov.l r7,@-r15\n\ | |
223 | mov.l r12,@-r15\n\ | |
224 | movt r3 ! Save T flag.\n\ | |
225 | mov.l r3,@-r15\n\ | |
226 | " FGR_SAVE "\n\ | |
227 | sts.l pr,@-r15\n\ | |
228 | tst r0,r0\n\ | |
229 | bt 1f\n\ | |
230 | mov r0,r2\n\ | |
231 | 1:\n\ | |
232 | mov r0,r4 ! PLT type\n\ | |
233 | mov r2,r5 ! link map address\n\ | |
234 | sts pr,r7 ! return address\n\ | |
235 | " FUN_ADDR "\n\ | |
236 | jsr @r0 ! Call resolver.\n\ | |
237 | mov r1,r6 ! reloc offset\n\ | |
238 | lds.l @r15+,pr ! Get register content back.\n\ | |
239 | " FGR_LOAD "\n\ | |
240 | mov.l @r15+,r3\n\ | |
241 | shal r3 ! Lode T flag.\n\ | |
242 | mov.l @r15+,r12\n\ | |
243 | mov.l @r15+,r7\n\ | |
244 | mov.l @r15+,r6\n\ | |
245 | mov.l @r15+,r5\n\ | |
246 | mov.l @r15+,r4\n\ | |
247 | mov.l @r15+,r3\n\ | |
248 | jmp @r0 ! Jump to function address.\n\ | |
249 | mov.l @r15+,r2\n\ | |
250 | .align 2\n\ | |
251 | 3:\n\ | |
252 | .long " GOTJMP (profile_fixup) "\n\ | |
253 | .size _dl_runtime_profile, .-_dl_runtime_profile\n\ | |
254 | .previous\n\ | |
65074d23 UD |
255 | "); |
256 | #else | |
257 | # define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\ | |
045fcd26 UD |
258 | .text\n\ |
259 | .globl _dl_runtime_resolve\n\ | |
260 | .globl _dl_runtime_profile\n\ | |
261 | .type _dl_runtime_resolve, @function\n\ | |
262 | .type _dl_runtime_profile, @function\n\ | |
263 | .align 5\n\ | |
264 | _dl_runtime_resolve:\n\ | |
265 | _dl_runtime_profile:\n\ | |
266 | mov.l r2,@-r15\n\ | |
267 | mov.l r3,@-r15\n\ | |
268 | mov.l r4,@-r15\n\ | |
269 | mov.l r5,@-r15\n\ | |
270 | mov.l r6,@-r15\n\ | |
271 | mov.l r7,@-r15\n\ | |
272 | mov.l r12,@-r15\n\ | |
273 | movt r3 ! Save T flag.\n\ | |
274 | mov.l r3,@-r15\n\ | |
275 | " FGR_SAVE "\n\ | |
276 | sts.l pr,@-r15\n\ | |
277 | tst r0,r0\n\ | |
278 | bt 1f\n\ | |
279 | mov r0,r2\n\ | |
280 | 1:\n\ | |
281 | mov r0,r4 ! PLT type\n\ | |
282 | mov r2,r5 ! link map address\n\ | |
283 | sts pr,r7 ! return address\n\ | |
284 | " FUN_ADDR "\n\ | |
285 | jsr @r0 ! Call resolver.\n\ | |
286 | mov r1,r6 ! reloc offset\n\ | |
287 | lds.l @r15+,pr ! Get register content back.\n\ | |
288 | " FGR_LOAD "\n\ | |
289 | mov.l @r15+,r3\n\ | |
290 | shal r3 ! Lode T flag.\n\ | |
291 | mov.l @r15+,r12\n\ | |
292 | mov.l @r15+,r7\n\ | |
293 | mov.l @r15+,r6\n\ | |
294 | mov.l @r15+,r5\n\ | |
295 | mov.l @r15+,r4\n\ | |
296 | mov.l @r15+,r3\n\ | |
297 | jmp @r0 ! Jump to function address.\n\ | |
298 | mov.l @r15+,r2\n\ | |
299 | .align 2\n\ | |
300 | 3:\n\ | |
301 | .long " GOTJMP (fixup) "\n\ | |
302 | .size _dl_runtime_resolve, .-_dl_runtime_resolve\n\ | |
303 | .size _dl_runtime_profile, .-_dl_runtime_profile\n\ | |
304 | .previous\n\ | |
65074d23 UD |
305 | "); |
306 | #endif | |
307 | ||
308 | /* Mask identifying addresses reserved for the user program, | |
309 | where the dynamic linker should not map anything. */ | |
310 | #define ELF_MACHINE_USER_ADDRESS_MASK 0x80000000UL | |
311 | ||
312 | /* Initial entry point code for the dynamic linker. | |
313 | The C function `_dl_start' is the real entry point; | |
314 | its return value is the user program's entry point. */ | |
315 | ||
316 | #define RTLD_START asm ("\ | |
317 | .text\n\ | |
318 | .globl _start\n\ | |
319 | .globl _dl_start_user\n\ | |
320 | _start:\n\ | |
321 | mov r15,r4\n\ | |
322 | mov.l .L_dl_start,r1\n\ | |
323 | mova .L_dl_start,r0\n\ | |
324 | add r1,r0\n\ | |
325 | jsr @r0\n\ | |
326 | nop\n\ | |
327 | _dl_start_user:\n\ | |
328 | ! Save the user entry point address in r8.\n\ | |
329 | mov r0,r8\n\ | |
330 | ! Point r12 at the GOT.\n\ | |
331 | mov.l 1f,r12\n\ | |
332 | mova 1f,r0\n\ | |
333 | bra 2f\n\ | |
334 | add r0,r12\n\ | |
335 | .align 2\n\ | |
336 | 1: .long _GLOBAL_OFFSET_TABLE_\n\ | |
337 | 2: ! Store the highest stack address\n\ | |
338 | mov.l .L_stack_end,r0\n\ | |
339 | mov.l @(r0,r12),r0\n\ | |
340 | mov.l r15,@r0\n\ | |
341 | ! See if we were run as a command with the executable file\n\ | |
342 | ! name as an extra leading argument.\n\ | |
343 | mov.l .L_dl_skip_args,r0\n\ | |
344 | mov.l @(r0,r12),r0\n\ | |
345 | mov.l @r0,r0\n\ | |
346 | ! Get the original argument count.\n\ | |
347 | mov.l @r15,r5\n\ | |
348 | ! Subtract _dl_skip_args from it.\n\ | |
349 | sub r0,r5\n\ | |
350 | ! Adjust the stack pointer to skip _dl_skip_args words.\n\ | |
351 | shll2 r0\n\ | |
352 | add r0,r15\n\ | |
353 | ! Store back the modified argument count.\n\ | |
354 | mov.l r5,@r15\n\ | |
355 | ! Compute argv address and envp.\n\ | |
356 | mov r15,r6\n\ | |
357 | add #4,r6\n\ | |
358 | mov r5,r7\n\ | |
359 | shll2 r7\n\ | |
360 | add r15,r7\n\ | |
361 | mov.l .L_dl_loaded,r0\n\ | |
362 | mov.l @(r0,r12),r0\n\ | |
363 | mov.l @r0,r4\n\ | |
364 | ! Call _dl_init.\n\ | |
365 | mov.l .L_dl_init,r1\n\ | |
366 | mova .L_dl_init,r0\n\ | |
367 | add r1,r0\n\ | |
368 | jsr @r0\n\ | |
369 | nop\n\ | |
370 | 1: ! Clear the startup flag.\n\ | |
371 | mov.l .L_dl_starting_up,r0\n\ | |
372 | mov.l @(r0,r12),r0\n\ | |
373 | mov #0,r2\n\ | |
374 | mov.l r2,@r0\n\ | |
375 | ! Pass our finalizer function to the user in r4, as per ELF ABI.\n\ | |
376 | mov.l .L_dl_fini,r0\n\ | |
377 | mov.l @(r0,r12),r4\n\ | |
378 | ! Jump to the user's entry point.\n\ | |
379 | jmp @r8\n\ | |
380 | nop\n\ | |
381 | .align 2\n\ | |
382 | .L_dl_start:\n\ | |
383 | .long _dl_start@PLT\n\ | |
384 | .L_stack_end:\n\ | |
385 | .long __libc_stack_end@GOT\n\ | |
386 | .L_dl_skip_args:\n\ | |
387 | .long _dl_skip_args@GOT\n\ | |
388 | .L_dl_init:\n\ | |
7969407a | 389 | .long _dl_init_internal@PLT\n\ |
65074d23 | 390 | .L_dl_loaded:\n\ |
0d01dace | 391 | .long _rtld_local@GOT\n\ |
65074d23 UD |
392 | .L_dl_starting_up:\n\ |
393 | .long _dl_starting_up@GOT\n\ | |
394 | .L_dl_fini:\n\ | |
395 | .long _dl_fini@GOT\n\ | |
396 | .previous\n\ | |
397 | "); | |
398 | ||
3632a260 UD |
399 | /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or |
400 | TLS variable, so undefined references should not be allowed to | |
401 | define the value. | |
cf5a372e UD |
402 | ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one |
403 | of the main executable's symbols, as for a COPY reloc. */ | |
ce460d04 | 404 | #if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD) |
3632a260 UD |
405 | # define elf_machine_type_class(type) \ |
406 | ((((type) == R_SH_JMP_SLOT || (type) == R_SH_TLS_DTPMOD32 \ | |
407 | || (type) == R_SH_TLS_DTPOFF32 || (type) == R_SH_TLS_TPOFF32) \ | |
408 | * ELF_RTYPE_CLASS_PLT) \ | |
409 | | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY)) | |
410 | #else | |
cf5a372e UD |
411 | #define elf_machine_type_class(type) \ |
412 | ((((type) == R_SH_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \ | |
413 | | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY)) | |
3632a260 | 414 | #endif |
65074d23 UD |
415 | |
416 | /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */ | |
417 | #define ELF_MACHINE_JMP_SLOT R_SH_JMP_SLOT | |
418 | ||
419 | /* We define an initialization functions. This is called very early in | |
420 | _dl_sysdep_start. */ | |
421 | #define DL_PLATFORM_INIT dl_platform_init () | |
422 | ||
65074d23 UD |
423 | static inline void __attribute__ ((unused)) |
424 | dl_platform_init (void) | |
425 | { | |
5688da55 | 426 | if (GL(dl_platform) != NULL && *GL(dl_platform) == '\0') |
65074d23 | 427 | /* Avoid an empty string which would disturb us. */ |
5688da55 | 428 | GL(dl_platform) = NULL; |
65074d23 UD |
429 | } |
430 | ||
431 | static inline Elf32_Addr | |
432 | elf_machine_fixup_plt (struct link_map *map, lookup_t t, | |
433 | const Elf32_Rela *reloc, | |
434 | Elf32_Addr *reloc_addr, Elf32_Addr value) | |
435 | { | |
436 | return *reloc_addr = value; | |
437 | } | |
438 | ||
439 | /* Return the final value of a plt relocation. */ | |
440 | static inline Elf32_Addr | |
441 | elf_machine_plt_value (struct link_map *map, const Elf32_Rela *reloc, | |
442 | Elf32_Addr value) | |
443 | { | |
444 | return value + reloc->r_addend; | |
445 | } | |
446 | ||
447 | #endif /* !dl_machine_h */ | |
448 | ||
449 | #ifdef RESOLVE | |
450 | ||
451 | /* SH never uses Elf32_Rel relocations. */ | |
452 | #define ELF_MACHINE_NO_REL 1 | |
453 | ||
65074d23 UD |
454 | /* Perform the relocation specified by RELOC and SYM (which is fully resolved). |
455 | MAP is the object containing the reloc. */ | |
456 | ||
457 | static inline void | |
458 | elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc, | |
459 | const Elf32_Sym *sym, const struct r_found_version *version, | |
460 | Elf32_Addr *const reloc_addr) | |
461 | { | |
1721af3f | 462 | const unsigned int r_type = ELF32_R_TYPE (reloc->r_info); |
045fcd26 UD |
463 | Elf32_Addr value; |
464 | ||
465 | #define COPY_UNALIGNED_WORD(sw, tw, align) \ | |
466 | { \ | |
467 | void *__s = &(sw), *__t = &(tw); \ | |
468 | switch ((align)) \ | |
469 | { \ | |
470 | case 0: \ | |
471 | *(unsigned long *) __t = *(unsigned long *) __s; \ | |
472 | break; \ | |
473 | case 2: \ | |
474 | *((unsigned short *) __t)++ = *((unsigned short *) __s)++; \ | |
475 | *((unsigned short *) __t) = *((unsigned short *) __s); \ | |
476 | break; \ | |
477 | default: \ | |
478 | *((unsigned char *) __t)++ = *((unsigned char *) __s)++; \ | |
479 | *((unsigned char *) __t)++ = *((unsigned char *) __s)++; \ | |
480 | *((unsigned char *) __t)++ = *((unsigned char *) __s)++; \ | |
481 | *((unsigned char *) __t) = *((unsigned char *) __s); \ | |
482 | break; \ | |
483 | } \ | |
484 | } | |
485 | ||
1721af3f | 486 | if (__builtin_expect (r_type == R_SH_RELATIVE, 0)) |
65074d23 UD |
487 | { |
488 | #ifndef RTLD_BOOTSTRAP | |
5688da55 | 489 | if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */ |
65074d23 | 490 | #endif |
876f9634 UD |
491 | { |
492 | if (reloc->r_addend) | |
045fcd26 | 493 | value = map->l_addr + reloc->r_addend; |
876f9634 | 494 | else |
045fcd26 UD |
495 | { |
496 | COPY_UNALIGNED_WORD (*reloc_addr, value, (int) reloc_addr & 3); | |
497 | value += map->l_addr; | |
498 | } | |
499 | COPY_UNALIGNED_WORD (value, *reloc_addr, (int) reloc_addr & 3); | |
876f9634 | 500 | } |
65074d23 | 501 | } |
1721af3f | 502 | #ifndef RTLD_BOOTSTRAP |
9596d0dd | 503 | else if (__builtin_expect (r_type == R_SH_NONE, 0)) |
1721af3f UD |
504 | return; |
505 | #endif | |
506 | else | |
65074d23 UD |
507 | { |
508 | const Elf32_Sym *const refsym = sym; | |
3632a260 UD |
509 | #if defined USE_TLS && !defined RTLD_BOOTSTRAP |
510 | struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type); | |
045fcd26 | 511 | |
3632a260 UD |
512 | value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value; |
513 | #else | |
514 | ||
515 | value = RESOLVE (&sym, version, r_type); | |
516 | # ifndef RTLD_BOOTSTRAP | |
517 | if (sym != NULL) | |
518 | # endif | |
65074d23 | 519 | value += sym->st_value; |
3632a260 | 520 | #endif |
65074d23 UD |
521 | value += reloc->r_addend; |
522 | ||
3632a260 | 523 | switch (r_type) |
65074d23 UD |
524 | { |
525 | case R_SH_COPY: | |
526 | if (sym == NULL) | |
527 | /* This can happen in trace mode if an object could not be | |
528 | found. */ | |
529 | break; | |
530 | if (sym->st_size > refsym->st_size | |
5c1159b6 | 531 | || (sym->st_size < refsym->st_size && GL(dl_verbose))) |
65074d23 UD |
532 | { |
533 | const char *strtab; | |
534 | ||
535 | strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]); | |
35fc382a | 536 | _dl_error_printf ("\ |
729399c3 | 537 | %s: Symbol `%s' has different size in shared object, consider re-linking\n", |
e6caf4e1 | 538 | rtld_progname ?: "<program name unknown>", |
35fc382a | 539 | strtab + refsym->st_name); |
65074d23 UD |
540 | } |
541 | memcpy (reloc_addr, (void *) value, MIN (sym->st_size, | |
542 | refsym->st_size)); | |
543 | break; | |
544 | case R_SH_GLOB_DAT: | |
545 | case R_SH_JMP_SLOT: | |
045fcd26 | 546 | /* These addresses are always aligned. */ |
65074d23 UD |
547 | *reloc_addr = value; |
548 | break; | |
ce460d04 | 549 | #if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD) |
3632a260 UD |
550 | /* XXX Remove TLS relocations which are not needed. */ |
551 | case R_SH_TLS_DTPMOD32: | |
552 | # ifdef RTLD_BOOTSTRAP | |
553 | /* During startup the dynamic linker is always the module | |
554 | with index 1. | |
555 | XXX If this relocation is necessary move before RESOLVE | |
556 | call. */ | |
557 | *reloc_addr = 1; | |
558 | # else | |
559 | /* Get the information from the link map returned by the | |
560 | resolv function. */ | |
561 | if (sym_map != NULL) | |
562 | *reloc_addr = sym_map->l_tls_modid; | |
563 | # endif | |
564 | break; | |
565 | case R_SH_TLS_DTPOFF32: | |
566 | # ifndef RTLD_BOOTSTRAP | |
567 | /* During relocation all TLS symbols are defined and used. | |
568 | Therefore the offset is already correct. */ | |
569 | if (sym != NULL) | |
570 | *reloc_addr = sym->st_value; | |
571 | # endif | |
572 | break; | |
573 | case R_SH_TLS_TPOFF32: | |
574 | /* The offset is positive, afterward from the thread pointer. */ | |
575 | # ifdef RTLD_BOOTSTRAP | |
aa298c08 | 576 | *reloc_addr = map->l_tls_offset + sym->st_value + reloc->r_addend; |
3632a260 UD |
577 | # else |
578 | /* We know the offset of object the symbol is contained in. | |
579 | It is a positive value which will be added to the thread | |
580 | pointer. To get the variable position in the TLS block | |
581 | we add the offset from that of the TLS block. */ | |
aff4519d | 582 | CHECK_STATIC_TLS (map, sym_map); |
aa298c08 UD |
583 | *reloc_addr |
584 | = ((sym == NULL ? 0 : sym_map->l_tls_offset + sym->st_value) | |
585 | + reloc->r_addend); | |
3632a260 UD |
586 | # endif |
587 | break; | |
588 | #endif /* use TLS */ | |
65074d23 UD |
589 | case R_SH_DIR32: |
590 | { | |
591 | #ifndef RTLD_BOOTSTRAP | |
592 | /* This is defined in rtld.c, but nowhere in the static | |
593 | libc.a; make the reference weak so static programs can | |
594 | still link. This declaration cannot be done when | |
595 | compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) because | |
596 | rtld.c contains the common defn for _dl_rtld_map, which | |
597 | is incompatible with a weak decl in the same file. */ | |
5688da55 UD |
598 | # ifndef SHARED |
599 | weak_extern (GL(dl_rtld_map)); | |
600 | # endif | |
601 | if (map == &GL(dl_rtld_map)) | |
65074d23 UD |
602 | /* Undo the relocation done here during bootstrapping. |
603 | Now we will relocate it anew, possibly using a | |
604 | binding found in the user program or a loaded library | |
605 | rather than the dynamic linker's built-in definitions | |
606 | used while loading those libraries. */ | |
607 | value -= map->l_addr + refsym->st_value + reloc->r_addend; | |
608 | #endif | |
045fcd26 | 609 | COPY_UNALIGNED_WORD (value, *reloc_addr, (int) reloc_addr & 3); |
65074d23 UD |
610 | break; |
611 | } | |
612 | case R_SH_REL32: | |
045fcd26 UD |
613 | value = (value - (Elf32_Addr) reloc_addr); |
614 | COPY_UNALIGNED_WORD (value, *reloc_addr, (int) reloc_addr & 3); | |
65074d23 UD |
615 | break; |
616 | default: | |
3632a260 | 617 | _dl_reloc_bad_type (map, r_type, 0); |
65074d23 UD |
618 | break; |
619 | } | |
620 | } | |
1721af3f UD |
621 | } |
622 | ||
623 | static inline void | |
1f2a1df3 UD |
624 | elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc, |
625 | Elf32_Addr *const reloc_addr) | |
1721af3f | 626 | { |
9596d0dd UD |
627 | Elf32_Addr value; |
628 | ||
1721af3f UD |
629 | if (reloc->r_addend) |
630 | value = l_addr + reloc->r_addend; | |
631 | else | |
632 | { | |
633 | COPY_UNALIGNED_WORD (*reloc_addr, value, (int) reloc_addr & 3); | |
634 | value += l_addr; | |
635 | } | |
636 | COPY_UNALIGNED_WORD (value, *reloc_addr, (int) reloc_addr & 3); | |
045fcd26 UD |
637 | |
638 | #undef COPY_UNALIGNED_WORD | |
65074d23 UD |
639 | } |
640 | ||
641 | static inline void | |
642 | elf_machine_lazy_rel (struct link_map *map, | |
643 | Elf32_Addr l_addr, const Elf32_Rela *reloc) | |
644 | { | |
645 | Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset); | |
646 | /* Check for unexpected PLT reloc type. */ | |
647 | if (ELF32_R_TYPE (reloc->r_info) == R_SH_JMP_SLOT) | |
32e6df36 UD |
648 | { |
649 | if (__builtin_expect (map->l_mach.plt, 0) == 0) | |
650 | *reloc_addr += l_addr; | |
651 | else | |
652 | *reloc_addr = | |
653 | map->l_mach.plt | |
654 | + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 7; | |
655 | } | |
65074d23 UD |
656 | else |
657 | _dl_reloc_bad_type (map, ELF32_R_TYPE (reloc->r_info), 1); | |
658 | } | |
659 | ||
660 | #endif /* RESOLVE */ |