]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/dl-machine.h
1 /* Machine-dependent ELF dynamic relocation inline functions. IA-64 version.
2 Copyright (C) 1995-1997, 2000-2002, 2003 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
21 #define dl_machine_h 1
23 #define ELF_MACHINE_NAME "ia64"
31 /* Translate a processor specific dynamic tag to the index
33 #define DT_IA_64(x) (DT_IA_64_##x - DT_LOPROC + DT_NUM)
35 /* There are currently 123 dynamic symbols in ld.so.
36 IA64_BOOT_FPTR_TABLE_LEN needs to be at least that big. */
37 #define IA64_BOOT_FPTR_TABLE_LEN 200
39 /* An FDESC is a function descriptor. */
43 Elf64_Addr ip
; /* code entry point */
44 Elf64_Addr gp
; /* global pointer */
47 struct ia64_fdesc_table
49 struct ia64_fdesc_table
*next
;
50 unsigned int len
; /* # of entries in fdesc table */
51 volatile unsigned int first_unused
; /* index of first available entry */
52 struct ia64_fdesc fdesc
[0];
55 extern Elf64_Addr
__ia64_make_fptr (struct link_map
*, const Elf64_Sym
*,
59 __ia64_init_bootstrap_fdesc_table (struct link_map
*map
)
61 Elf64_Addr
*boot_table
;
63 /* careful: this will be called before got has been relocated... */
64 asm (";; addl %0 = @gprel (__ia64_boot_fptr_table), gp" : "=r"(boot_table
));
66 map
->l_mach
.fptr_table_len
= IA64_BOOT_FPTR_TABLE_LEN
;
67 map
->l_mach
.fptr_table
= boot_table
;
70 #define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
71 __ia64_init_bootstrap_fdesc_table (&bootstrap_map);
73 /* Return nonzero iff ELF header is compatible with the running host. */
75 elf_machine_matches_host (const Elf64_Ehdr
*ehdr
)
77 return ehdr
->e_machine
== EM_IA_64
;
81 /* Return the link-time address of _DYNAMIC. */
82 static inline Elf64_Addr
83 elf_machine_dynamic (void)
89 " .type __dynamic_ltv#, @object\n"
90 " .size __dynamic_ltv#, 8\n"
92 " data8 @ltv(_DYNAMIC#)\n"
94 " addl %0 = @gprel(__dynamic_ltv#), gp ;;"
101 /* Return the run-time load address of the shared object. */
102 static inline Elf64_Addr
103 elf_machine_load_address (void)
111 "2: data4 @ltv(1b)\n"
114 " addl %1 = @gprel(2b), gp ;;"
115 : "=r" (ip
), "=r" (p
));
117 return ip
- (Elf64_Addr
) *p
;
120 /* Set up the loaded object described by L so its unrelocated PLT
121 entries will jump to the on-demand fixup code in dl-runtime.c. */
124 elf_machine_runtime_setup (struct link_map
*l
, int lazy
, int profile
)
126 extern void _dl_runtime_resolve (void);
127 extern void _dl_runtime_profile (void);
131 register Elf64_Addr gp
__asm__ ("gp");
132 Elf64_Addr
*reserve
, doit
;
135 * Careful with the typecast here or it will try to add l-l_addr
138 reserve
= ((Elf64_Addr
*)
139 (l
->l_info
[DT_IA_64 (PLT_RESERVE
)]->d_un
.d_ptr
+ l
->l_addr
));
140 /* Identify this shared object. */
141 reserve
[0] = (Elf64_Addr
) l
;
143 /* This function will be called to perform the relocation. */
145 doit
= (Elf64_Addr
) ((struct ia64_fdesc
*) &_dl_runtime_resolve
)->ip
;
148 if (_dl_name_match_p (GL(dl_profile
), l
))
150 /* This is the object we are looking for. Say that we really
151 want profiling and the timers are started. */
152 GL(dl_profile_map
) = l
;
154 doit
= (Elf64_Addr
) ((struct ia64_fdesc
*) &_dl_runtime_profile
)->ip
;
166 This code is used in dl-runtime.c to call the `fixup' function
167 and then redirect to the address it returns. `fixup()' takes two
168 arguments, however profile_fixup() takes three.
170 The ABI specifies that we will never see more than 8 input
171 registers to a function call, thus it is safe to simply allocate
172 those, and simpler than playing stack games.
175 #define TRAMPOLINE_TEMPLATE(tramp_name, fixup_name) \
176 extern void tramp_name (void); \
178 " .global " #tramp_name "#\n" \
179 " .proc " #tramp_name "#\n" \
183 " .save ar.pfs, r40\n" \
184 " alloc loc0 = ar.pfs, 8, 6, 3, 0\n" \
185 " adds r2 = -144, r12\n" \
186 " adds r3 = -128, r12\n" \
190 " adds r12 = -160, r12\n" \
194 " mov out2 = b0 /* needed by fixup_profile */\n" \
198 " mov loc2 = r8 /* preserve struct value register */\n" \
203 " mov loc3 = r9 /* preserve language specific register */\n" \
204 " mov loc4 = r10 /* preserve language specific register */\n" \
205 " mov loc5 = r11 /* preserve language specific register */\n" \
208 " stf.spill [r2] = f8, 32\n" \
209 " stf.spill [r3] = f9, 32\n" \
210 " mov out0 = r16\n" \
214 " stf.spill [r2] = f10, 32\n" \
215 " stf.spill [r3] = f11, 32\n" \
216 " shl out1 = r15, 4\n" \
220 " stf.spill [r2] = f12, 32\n" \
221 " stf.spill [r3] = f13, 32\n" \
222 " shladd out1 = r15, 3, out1\n" \
226 " stf.spill [r2] = f14\n" \
227 " stf.spill [r3] = f15\n" \
228 " br.call.sptk.many b0 = " #fixup_name "#\n" \
231 " ld8 r9 = [ret0], 8\n" \
232 " adds r2 = 16, r12\n" \
233 " adds r3 = 32, r12\n" \
237 " ldf.fill f8 = [r2], 32\n" \
238 " ldf.fill f9 = [r3], 32\n" \
243 " ldf.fill f10 = [r2], 32\n" \
244 " ldf.fill f11 = [r3], 32\n" \
249 " ldf.fill f12 = [r2], 32\n" \
250 " ldf.fill f13 = [r3], 32\n" \
251 " mov ar.pfs = loc0\n" \
255 " ldf.fill f14 = [r2], 32\n" \
256 " ldf.fill f15 = [r3], 32\n" \
257 " .restore sp /* pop the unwind frame state */\n" \
258 " adds r12 = 160, r12\n" \
262 " mov r9 = loc3 /* restore language specific register */\n" \
263 " mov r10 = loc4 /* restore language specific register */\n" \
264 " mov r11 = loc5 /* restore language specific register */\n" \
267 " ld8 gp = [ret0]\n" \
268 " mov r8 = loc2 /* restore struct value register */\n" \
271 " /* An alloc is needed for the break system call to work.\n" \
272 " We don't care about the old value of the pfs register. */\n" \
276 " alloc r2 = ar.pfs, 0, 0, 8, 0\n" \
277 " br.sptk.many b6\n" \
280 " .endp " #tramp_name "#\n");
283 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
284 TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup); \
285 TRAMPOLINE_TEMPLATE (_dl_runtime_profile, profile_fixup);
287 #define ELF_MACHINE_RUNTIME_TRAMPOLINE \
288 TRAMPOLINE_TEMPLATE (_dl_runtime_resolve, fixup); \
289 strong_alias (_dl_runtime_resolve, _dl_runtime_profile);
293 /* Initial entry point code for the dynamic linker.
294 The C function `_dl_start' is the real entry point;
295 its return value is the user program's entry point. */
297 #define RTLD_START asm ( \
299 " .global _start#\n" \
304 " .save ar.pfs, r32\n" \
306 " alloc loc0 = ar.pfs, 0, 3, 4, 0\n" \
309 " addl r3 = @gprel(0b), r0\n" \
313 " /* Calculate the GP, and save a copy in loc1. */\n" \
314 " sub gp = r2, r3\n" \
315 " movl r8 = 0x9804c0270033f\n" \
319 " mov ar.fpsr = r8\n" \
320 " sub loc1 = r2, r3\n" \
321 " /* _dl_start wants a pointer to the pointer to the arg block and\n" \
322 " the arg block starts with an integer, thus the magic 16. */\n" \
323 " adds out0 = 16, sp\n" \
326 " br.call.sptk.many b0 = _dl_start#\n" \
330 " /* FALLTHRU */\n" \
331 " .global _dl_start_user#\n" \
332 " .proc _dl_start_user#\n" \
333 "_dl_start_user:\n" \
335 " .save ar.pfs, r32\n" \
339 " /* Save the pointer to the user entry point fptr in loc2. */\n" \
340 " mov loc2 = ret0\n" \
341 " /* Store the highest stack address. */\n" \
342 " addl r2 = @ltoff(__libc_stack_end#), gp\n" \
343 " addl r3 = @gprel(_dl_skip_args), gp\n" \
349 " adds r11 = 24, sp /* Load the address of argv. */\n" \
354 " adds r10 = 16, sp /* Load the address of argc. */\n" \
355 " mov out2 = r11\n" \
357 " /* See if we were run as a command with the executable file\n" \
358 " name as an extra leading argument. If so, adjust the argv\n" \
359 " pointer to skip _dl_skip_args words.\n" \
360 " Note that _dl_skip_args is an integer, not a long - Jes\n" \
362 " The stack pointer has to be 16 byte aligned. We cannot simply\n" \
363 " addjust the stack pointer. We have to move the whole argv and\n" \
364 " envp and adjust _dl_argv by _dl_skip_args. H.J. */\n" \
367 " ld8 out1 = [r10] /* is argc actually stored as a long\n" \
368 " or as an int? */\n" \
369 " addl r2 = @ltoff(_dl_argv), gp\n" \
373 " ld8 r2 = [r2] /* Get the address of _dl_argv. */\n" \
374 " sub out1 = out1, r3 /* Get the new argc. */\n" \
375 " shladd r3 = r3, 3, r0\n" \
380 " ld8 r17 = [r2] /* Get _dl_argv. */\n" \
381 " add r15 = r11, r3 /* The address of the argv we move */\n" \
384 " /* ??? Could probably merge these two loops into 3 bundles.\n" \
385 " using predication to control which set of copies we're on. */\n" \
386 "1: /* Copy argv. */\n" \
388 " ld8 r16 = [r15], 8 /* Load the value in the old argv. */\n" \
392 " st8 [r11] = r16, 8 /* Store it in the new argv. */\n" \
393 " cmp.ne p6, p7 = 0, r16\n" \
394 "(p6) br.cond.dptk.few 1b\n" \
398 " mov out3 = r11\n" \
399 " sub r17 = r17, r3 /* Substract _dl_skip_args. */\n" \
400 " addl out0 = @gprel(_rtld_local), gp\n" \
402 "1: /* Copy env. */\n" \
404 " ld8 r16 = [r15], 8 /* Load the value in the old env. */\n" \
408 " st8 [r11] = r16, 8 /* Store it in the new env. */\n" \
409 " cmp.ne p6, p7 = 0, r16\n" \
410 "(p6) br.cond.dptk.few 1b\n" \
414 " st8 [r10] = out1 /* Record the new argc. */\n" \
415 " ld8 out0 = [out0] /* get the linkmap */\n" \
418 " st8 [r2] = r17 /* Load the new _dl_argv. */\n" \
419 " br.call.sptk.many b0 = _dl_init_internal#\n" \
422 " /* Pass our finializer function to the user,\n" \
423 " and jump to the user's entry point. */\n" \
425 " ld8 r3 = [loc2], 8\n" \
429 " addl ret0 = @ltoff(@fptr(_dl_fini#)), gp\n" \
434 " ld8 ret0 = [ret0]\n" \
435 " ld8 gp = [loc2]\n" \
436 " mov ar.pfs = loc0\n" \
440 " br.sptk.many b6\n" \
443 " .endp _dl_start_user#\n" \
447 #ifndef RTLD_START_SPECIAL_INIT
448 #define RTLD_START_SPECIAL_INIT /* nothing */
451 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or TLS
452 variable, so undefined references should not be allowed to define the
454 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
455 of the main executable's symbols, as for a COPY reloc, which we don't
457 /* ??? Ignore *MSB for now. */
458 #if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD)
459 #define elf_machine_type_class(type) \
460 (((type) == R_IA64_IPLTLSB || (type) == R_IA64_DTPMOD64LSB \
461 || (type) == R_IA64_DTPREL64LSB || (type) == R_IA64_TPREL64LSB) \
462 * ELF_RTYPE_CLASS_PLT)
464 #define elf_machine_type_class(type) \
465 (((type) == R_IA64_IPLTLSB) * ELF_RTYPE_CLASS_PLT)
468 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
469 #define ELF_MACHINE_JMP_SLOT R_IA64_IPLTLSB
471 /* According to the IA-64 specific documentation, Rela is always used. */
472 #define ELF_MACHINE_NO_REL 1
474 /* Return the address of the entry point. */
475 #define ELF_MACHINE_START_ADDRESS(map, start) \
476 DL_STATIC_FUNCTION_ADDRESS (map, start)
478 #define elf_machine_profile_fixup_plt(l, reloc, rel_addr, value) \
479 elf_machine_fixup_plt (l, reloc, rel_addr, value)
481 #define elf_machine_profile_plt(reloc_addr) ((Elf64_Addr) (reloc_addr))
483 /* Fixup a PLT entry to bounce directly to the function at VALUE. */
484 static inline Elf64_Addr
485 elf_machine_fixup_plt (struct link_map
*l
, lookup_t t
,
486 const Elf64_Rela
*reloc
,
487 Elf64_Addr
*reloc_addr
, Elf64_Addr value
)
489 /* l is the link_map for the caller, t is the link_map for the object
491 /* got has already been relocated in elf_get_dynamic_info() */
492 reloc_addr
[1] = t
->l_info
[DT_PLTGOT
]->d_un
.d_ptr
;
493 /* we need a "release" here to ensure that the gp is visible before
494 the code entry point is updated: */
495 ((volatile Elf64_Addr
*) reloc_addr
)[0] = value
;
496 return (Elf64_Addr
) reloc_addr
;
499 /* Return the final value of a plt relocation. */
500 static inline Elf64_Addr
501 elf_machine_plt_value (struct link_map
*map
, const Elf64_Rela
*reloc
,
504 /* No need to handle rel vs rela since IA64 is rela only */
505 return value
+ reloc
->r_addend
;
508 #endif /* !dl_machine_h */
512 #define R_IA64_TYPE(R) ((R) & -8)
513 #define R_IA64_FORMAT(R) ((R) & 7)
515 #define R_IA64_FORMAT_32MSB 4
516 #define R_IA64_FORMAT_32LSB 5
517 #define R_IA64_FORMAT_64MSB 6
518 #define R_IA64_FORMAT_64LSB 7
521 /* Perform the relocation specified by RELOC and SYM (which is fully
522 resolved). MAP is the object containing the reloc. */
524 elf_machine_rela (struct link_map
*map
,
525 const Elf64_Rela
*reloc
,
526 const Elf64_Sym
*sym
,
527 const struct r_found_version
*version
,
528 Elf64_Addr
*const reloc_addr
)
530 const unsigned long int r_type
= ELF64_R_TYPE (reloc
->r_info
);
533 #if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC && !defined SHARED
534 /* This is defined in rtld.c, but nowhere in the static libc.a; make the
535 reference weak so static programs can still link. This declaration
536 cannot be done when compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP)
537 because rtld.c contains the common defn for _dl_rtld_map, which is
538 incompatible with a weak decl in the same file. */
539 weak_extern (_dl_rtld_map
);
542 /* We cannot use a switch here because we cannot locate the switch
543 jump table until we've self-relocated. */
545 #if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
546 if (__builtin_expect (R_IA64_TYPE (r_type
) == R_IA64_TYPE (R_IA64_REL64LSB
),
549 assert (ELF64_R_TYPE (reloc
->r_info
) == R_IA64_REL64LSB
);
551 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
552 /* Already done in dynamic linker. */
553 if (map
!= &GL(dl_rtld_map
))
555 value
+= map
->l_addr
;
559 if (__builtin_expect (r_type
== R_IA64_NONE
, 0))
563 struct link_map
*sym_map
;
565 /* RESOLVE_MAP() will return NULL if it fail to locate the symbol. */
566 if ((sym_map
= RESOLVE_MAP (&sym
, version
, r_type
)))
568 value
= sym_map
->l_addr
+ sym
->st_value
+ reloc
->r_addend
;
570 if (R_IA64_TYPE (r_type
) == R_IA64_TYPE (R_IA64_DIR64LSB
))
571 ;/* No adjustment. */
572 else if (r_type
== R_IA64_IPLTLSB
)
574 elf_machine_fixup_plt (NULL
, sym_map
, reloc
, reloc_addr
, value
);
577 else if (R_IA64_TYPE (r_type
) == R_IA64_TYPE (R_IA64_FPTR64LSB
))
578 value
= __ia64_make_fptr (sym_map
, sym
, value
);
579 else if (R_IA64_TYPE (r_type
) == R_IA64_TYPE (R_IA64_PCREL64LSB
))
580 value
-= (Elf64_Addr
) reloc_addr
& -16;
581 #if defined USE_TLS && (!defined RTLD_BOOTSTRAP || defined USE___THREAD)
582 else if (R_IA64_TYPE (r_type
) == R_IA64_TYPE (R_IA64_DTPMOD64LSB
))
583 # ifdef RTLD_BOOTSTRAP
584 /* During startup the dynamic linker is always index 1. */
587 /* Get the information from the link map returned by the
589 value
= sym_map
->l_tls_modid
;
590 else if (R_IA64_TYPE (r_type
) == R_IA64_TYPE (R_IA64_DTPREL64LSB
))
591 value
-= sym_map
->l_addr
;
593 else if (R_IA64_TYPE (r_type
) == R_IA64_TYPE (R_IA64_TPREL64LSB
))
595 # ifndef RTLD_BOOTSTRAP
596 CHECK_STATIC_TLS (map
, sym_map
);
598 value
+= sym_map
->l_tls_offset
- sym_map
->l_addr
;
602 assert (! "unexpected dynamic reloc type");
608 /* ??? Ignore MSB and Instruction format for now. */
609 if (R_IA64_FORMAT (r_type
) == R_IA64_FORMAT_64LSB
)
611 else if (R_IA64_FORMAT (r_type
) == R_IA64_FORMAT_32LSB
)
612 *(int *) reloc_addr
= value
;
613 else if (r_type
== R_IA64_IPLTLSB
)
619 assert (! "unexpected dynamic reloc format");
622 /* Let do-rel.h know that on IA-64 if l_addr is 0, all RELATIVE relocs
624 #define ELF_MACHINE_REL_RELATIVE 1
627 elf_machine_rela_relative (Elf64_Addr l_addr
, const Elf64_Rela
*reloc
,
628 Elf64_Addr
*const reloc_addr
)
630 /* ??? Ignore MSB and Instruction format for now. */
631 assert (ELF64_R_TYPE (reloc
->r_info
) == R_IA64_REL64LSB
);
633 *reloc_addr
+= l_addr
;
636 /* Perform a RELATIVE reloc on the .got entry that transfers to the .plt. */
638 elf_machine_lazy_rel (struct link_map
*map
,
639 Elf64_Addr l_addr
, const Elf64_Rela
*reloc
)
641 Elf64_Addr
*const reloc_addr
= (void *) (l_addr
+ reloc
->r_offset
);
642 const unsigned long int r_type
= ELF64_R_TYPE (reloc
->r_info
);
644 if (r_type
== R_IA64_IPLTLSB
)
646 reloc_addr
[0] += l_addr
;
647 reloc_addr
[1] += l_addr
;
649 else if (r_type
== R_IA64_NONE
)
652 assert (! "unexpected PLT reloc type");
655 #endif /* RESOLVE_MAP */