aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/bits/link.h4
-rw-r--r--sysdeps/ia64/bits/link.h5
-rw-r--r--sysdeps/ia64/dl-fptr.c357
-rw-r--r--sysdeps/ia64/dl-lookupcfg.h24
-rw-r--r--sysdeps/ia64/dl-machine.h596
-rw-r--r--sysdeps/ia64/dl-symaddr.c10
6 files changed, 539 insertions, 457 deletions
diff --git a/sysdeps/generic/bits/link.h b/sysdeps/generic/bits/link.h
new file mode 100644
index 0000000000..470b4d3e5f
--- /dev/null
+++ b/sysdeps/generic/bits/link.h
@@ -0,0 +1,4 @@
+struct link_map_machine
+ {
+ /* empty by default */
+ };
diff --git a/sysdeps/ia64/bits/link.h b/sysdeps/ia64/bits/link.h
new file mode 100644
index 0000000000..7f8b0550d9
--- /dev/null
+++ b/sysdeps/ia64/bits/link.h
@@ -0,0 +1,5 @@
+struct link_map_machine
+ {
+ size_t fptr_table_len;
+ Elf64_Addr *fptr_table;
+ };
diff --git a/sysdeps/ia64/dl-fptr.c b/sysdeps/ia64/dl-fptr.c
index 588bb9d599..c31de86079 100644
--- a/sysdeps/ia64/dl-fptr.c
+++ b/sysdeps/ia64/dl-fptr.c
@@ -1,5 +1,5 @@
-/* Unmap a loaded object. IA-64 version.
- Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+/* Manage function descriptors. IA-64 version.
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <ia64intrin.h>
#include <unistd.h>
#include <string.h>
#include <sys/param.h>
@@ -27,186 +28,260 @@
#include <dl-machine.h>
#ifdef _LIBC_REENTRANT
# include <pt-machine.h>
-
-static int __ia64_fptr_lock = 0;
+# include <signal.h>
+# include <time.h>
#endif
-/* Because ld.so is now versioned, these functions can be in their own
- file; no relocations need to be done to call them. Of course, if
- ld.so is not versioned... */
-#if 0
-#ifndef DO_VERSIONING
-# error "This will not work with versioning turned off, sorry."
-#endif
+Elf64_Addr __ia64_boot_fptr_table[IA64_BOOT_FPTR_TABLE_LEN];
+
+static struct local
+ {
+ struct ia64_fdesc_table *root;
+ struct ia64_fdesc *free_list;
+ unsigned int npages; /* # of pages to allocate */
+#ifdef _LIBC_REENTRANT
+ volatile int lock;
+ sigset_t full_sigset;
#endif
+ /* the next to members MUST be consecutive! */
+ struct ia64_fdesc_table boot_table;
+ struct ia64_fdesc boot_fdescs[1024];
+ }
+local =
+ {
+ root: &local.boot_table,
+ npages: 2,
+ boot_table:
+ {
+ len: sizeof (local.boot_fdescs) / sizeof (local.boot_fdescs[0]),
+ first_unused: 0
+ }
+ };
-#ifdef MAP_ANON
-/* The fd is not examined when using MAP_ANON. */
-#define ANONFD -1
+/* Locking is tricky: we may get a signal while holding the lock and
+ the signal handler may end up calling into the dynamic loader
+ again. Also, if a real-time process spins on the lock, a
+ non-realtime process may never get the chance to release it's lock,
+ unless the realtime process relinquishes the CPU from time to time.
+ Hence we (a) block signals before acquiring the lock and (b) do a
+ nanosleep() when we detect prolongued contention. */
+#ifdef _LIBC_REENTRANT
+# define lock(l) \
+{ \
+ sigset_t _saved_set; \
+ int i = 10000; \
+ if (!__sigismember (&(l)->full_sigset, SIGINT)) \
+ __sigfillset (&(l)->full_sigset); \
+ \
+ while (testandset ((int *) &(l)->lock)) \
+ { \
+ struct timespec ts; \
+ if (i > 0) \
+ { \
+ --i; \
+ continue; \
+ } \
+ ts.tv_sec = 0; \
+ ts.tv_nsec = 1*1000*1000; \
+ __nanosleep (&ts, NULL); \
+ } \
+ __sigprocmask (SIG_BLOCK, &(l)->full_sigset, &_saved_set);
+# define unlock(l) \
+ __sigprocmask (SIG_SETMASK, &_saved_set, NULL); \
+ (l)->lock = 0; \
+}
#else
-extern int _dl_zerofd;
-#define ANONFD _dl_zerofd
+# define lock(l)
+# define unlock(l)
#endif
+/* Create a new fdesc table and return a pointer to the first fdesc
+ entry. The fdesc lock must have been acquired already. */
-/* ld.so currently has 14 FPTR relocs, we take 256 and use them for
- the relocs for the dynamic app itself. */
-struct ia64_fptr __boot_ldso_fptr[IA64_BOOT_FPTR_SIZE];
-struct ia64_fptr *__fptr_root = NULL;
-struct ia64_fptr *__fptr_next = __boot_ldso_fptr;
-static struct ia64_fptr *__fptr_free = NULL;
-int __fptr_count = IA64_BOOT_FPTR_SIZE;
-
-Elf64_Addr
-__ia64_make_fptr (const struct link_map *sym_map, Elf64_Addr value,
- struct ia64_fptr **root, struct ia64_fptr *mem)
+static struct ia64_fdesc *
+new_fdesc_table (struct local *l)
{
- struct ia64_fptr **loc;
- struct ia64_fptr *f;
+ size_t size = l->npages * _dl_pagesize;
+ struct ia64_fdesc_table *new_table;
+ struct ia64_fdesc *fdesc;
-#ifdef _LIBC_REENTRANT
- /* Make sure we are alone. We don't need a lock during bootstrap. */
- if (mem == NULL)
- while (testandset (&__ia64_fptr_lock));
-#endif
+ l->npages += l->npages;
+ new_table = __mmap (0, size, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+ if (new_table == MAP_FAILED)
+ _dl_signal_error (errno, NULL, "cannot map pages for fdesc table");
- /* Search the sorted linked list for an existing entry for this
- symbol. */
- loc = root;
- f = *loc;
- while (f != NULL && f->func <= value)
- {
- if (f->func == value)
- goto found;
- loc = &f->next;
- f = *loc;
- }
+ new_table->len = (size - sizeof (*new_table)) / sizeof (struct ia64_fdesc);
+ fdesc = &new_table->fdesc[0];
+ new_table->first_unused = 1;
+ new_table->next = l->root;
+ l->root = new_table;
+ return fdesc;
+}
- /* Not found. Create a new one. */
- if (mem != NULL)
- f = mem;
- else if (__fptr_free != NULL)
- {
- f = __fptr_free;
- __fptr_free = f->next;
- }
- else
+static Elf64_Addr
+make_fdesc (Elf64_Addr ip, Elf64_Addr gp)
+{
+ struct ia64_fdesc *fdesc = NULL;
+ struct ia64_fdesc_table *t;
+ unsigned int old;
+ struct local *l;
+
+ asm ("addl %0 = @gprel (local), gp" : "=r" (l));
+
+ t = l->root;
+ while (1)
{
- if (__fptr_count == 0)
+ old = t->first_unused;
+ if (old >= t->len)
+ break;
+ else if (__sync_bool_compare_and_swap (&t->first_unused, old, old + 1))
{
-#ifndef MAP_ANON
-# define MAP_ANON 0
- if (_dl_zerofd == -1)
- {
- _dl_zerofd = _dl_sysdep_open_zero_fill ();
- if (_dl_zerofd == -1)
- {
- __close (fd);
- _dl_signal_error (errno, NULL,
- "cannot open zero fill device");
- }
- }
-#endif
-
- __fptr_next = __mmap (0, _dl_pagesize, PROT_READ | PROT_WRITE,
- MAP_ANON | MAP_PRIVATE, ANONFD, 0);
- if (__fptr_next == MAP_FAILED)
- _dl_signal_error(errno, NULL, "cannot map page for fptr");
- __fptr_count = _dl_pagesize / sizeof (struct ia64_fptr);
+ fdesc = &t->fdesc[old];
+ goto install;
}
- f = __fptr_next++;
- __fptr_count--;
}
- f->func = value;
- /* GOT has already been relocated in elf_get_dynamic_info - don't
- try to relocate it again. */
- f->gp = sym_map->l_info[DT_PLTGOT]->d_un.d_ptr;
- f->next = *loc;
- *loc = f;
+ lock (l);
+ {
+ if (l->free_list)
+ {
+ fdesc = l->free_list; /* get it from free-list */
+ l->free_list = (struct ia64_fdesc *) fdesc->ip;
+ }
+ else
+ fdesc = new_fdesc_table (l); /* create new fdesc table */
+ }
+ unlock (l);
-found:
-#ifdef _LIBC_REENTRANT
- /* Release the lock. */
- if (mem == NULL)
- __ia64_fptr_lock = 0;
+ install:
+ fdesc->ip = ip;
+ fdesc->gp = gp;
+
+ return (Elf64_Addr) fdesc;
+}
+
+static inline Elf64_Addr *
+make_fptr_table (struct link_map *map)
+{
+ const Elf64_Sym *symtab = (const void *) D_PTR (map, l_info[DT_SYMTAB]);
+ const char *strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
+ Elf64_Addr *fptr_table;
+ size_t size;
+ size_t len;
+
+ /* XXX Apparently the only way to find out the size of the dynamic
+ symbol section is to assume that the string table follows right
+ afterwards... */
+ len = ((strtab - (char *) symtab) / map->l_info[DT_SYMENT]->d_un.d_val);
+ size = ((len * sizeof (fptr_table[0]) + _dl_pagesize - 1) & -_dl_pagesize);
+ /* XXX We don't support here in the moment systems without MAP_ANON.
+ There probably are none for IA-64. In case this is proven wrong
+ we will have to open /dev/null here and use the file descriptor
+ instead of the hard-coded -1. */
+ fptr_table = __mmap (NULL, size, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+ if (fptr_table == MAP_FAILED)
+ _dl_signal_error (errno, NULL, "cannot map pages for fptr table");
+
+ map->l_mach.fptr_table_len = len;
+ map->l_mach.fptr_table = fptr_table;
+ return fptr_table;
+}
+
+Elf64_Addr
+__ia64_make_fptr (struct link_map *map, const Elf64_Sym *sym, Elf64_Addr ip)
+{
+ Elf64_Addr *ftab = map->l_mach.fptr_table;
+ const Elf64_Sym *symtab;
+ Elf_Symndx symidx;
+
+ if (__builtin_expect (!map->l_mach.fptr_table, 0))
+ ftab = make_fptr_table (map);
+
+ symtab = (const void *) D_PTR (map, l_info[DT_SYMTAB]);
+ symidx = sym - symtab;
+
+ if (symidx >= map->l_mach.fptr_table_len)
+ _dl_signal_error (0, NULL,
+ "internal error: symidx out of range of fptr table");
+
+ if (!ftab[symidx])
+ {
+ /* GOT has already been relocated in elf_get_dynamic_info -
+ don't try to relocate it again. */
+ ftab[symidx] = make_fdesc (ip, map->l_info[DT_PLTGOT]->d_un.d_ptr);
+#if 0
+ {
+ const char *strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
+ struct local *l;
+
+ asm ("addl %0 = @gprel (local), gp" : "=r" (l));
+ if (l->root != &l->boot_table || l->boot_table.first_unused > 20)
+ _dl_debug_printf ("created fdesc symbol `%s' at %lx\n",
+ strtab + sym->st_name, ftab[symidx]);
+ }
#endif
+ }
- return (Elf64_Addr) f;
+ return ftab[symidx];
}
void
_dl_unmap (struct link_map *map)
{
- struct ia64_fptr **floc;
- struct ia64_fptr *f;
- struct ia64_fptr **lloc;
- struct ia64_fptr *l;
+ Elf64_Addr *ftab = map->l_mach.fptr_table;
+ struct ia64_fdesc *head = NULL, *tail = NULL;
+ size_t i;
__munmap ((void *) map->l_map_start, map->l_map_end - map->l_map_start);
-#ifdef _LIBC_REENTRANT
- /* Make sure we are alone. */
- while (testandset (&__ia64_fptr_lock));
-#endif
+ if (!ftab)
+ return;
- /* Search the sorted linked list for the first entry for this object. */
- floc = &__fptr_root;
- f = *floc;
- while (f != NULL && f->func < map->l_map_start)
+ /* String together the fdesc structures that are being freed. */
+ for (i = 0; i < map->l_mach.fptr_table_len; ++i)
{
- floc = &f->next;
- f = *floc;
- }
-
- /* We found one. */
- if (f != NULL && f->func < map->l_map_end)
- {
- /* Get the last entry. */
- lloc = floc;
- l = f;
- while (l && l->func < map->l_map_end)
+ if (ftab[i])
{
- lloc = &l->next;
- l = *lloc;
+ *(struct ia64_fdesc **) ftab[i] = head;
+ head = (struct ia64_fdesc *) ftab[i];
+ if (!tail)
+ tail = head;
}
+ }
- /* Updated FPTR. */
- *floc = l;
-
- /* Prepend them to the free list. */
- *lloc = __fptr_free;
- __fptr_free = f;
+ /* Prepend the new list to the free_list: */
+ if (tail)
+ {
+ lock (&local);
+ {
+ *(struct ia64_fdesc **) tail = local.free_list;
+ local.free_list = head;
+ }
+ unlock (&local);
}
-#ifdef _LIBC_REENTRANT
- /* Release the lock. */
- __ia64_fptr_lock = 0;
-#endif
+ __munmap (ftab,
+ map->l_mach.fptr_table_len * sizeof (map->l_mach.fptr_table[0]));
+ map->l_mach.fptr_table = NULL;
}
Elf64_Addr
_dl_lookup_address (const void *address)
{
Elf64_Addr addr = (Elf64_Addr) address;
- struct ia64_fptr *f;
-
-#ifdef _LIBC_REENTRANT
- /* Make sure we are alone. */
- while (testandset (&__ia64_fptr_lock));
-#endif
-
- for (f = __fptr_root; f != NULL; f = f->next)
- if (f == address)
- {
- addr = f->func;
- break;
- }
-
-#ifdef _LIBC_REENTRANT
- /* Release the lock. */
- __ia64_fptr_lock = 0;
-#endif
+ struct ia64_fdesc_table *t;
+ unsigned long int i;
+ for (t = local.root; t != NULL; t = t->next)
+ {
+ i = (struct ia64_fdesc *) addr - &t->fdesc[0];
+ if (i < t->first_unused && addr == (Elf64_Addr) &t->fdesc[i])
+ {
+ addr = t->fdesc[i].ip;
+ break;
+ }
+ }
return addr;
}
diff --git a/sysdeps/ia64/dl-lookupcfg.h b/sysdeps/ia64/dl-lookupcfg.h
index 884968e895..2f5ba8ed6c 100644
--- a/sysdeps/ia64/dl-lookupcfg.h
+++ b/sysdeps/ia64/dl-lookupcfg.h
@@ -36,9 +36,21 @@ extern void _dl_unmap (struct link_map *map);
#define DL_UNMAP(map) _dl_unmap (map)
-extern Elf64_Addr _dl_function_address (const struct link_map *map,
- Elf64_Addr start);
-
-#define DL_FUNCTION_ADDRESS(map, addr) _dl_function_address (map, addr)
-#define DL_DT_INIT_ADDRESS(map, addr) DL_FUNCTION_ADDRESS (map, addr)
-#define DL_DT_FINI_ADDRESS(map, addr) DL_FUNCTION_ADDRESS (map, addr)
+#define DL_AUTO_FUNCTION_ADDRESS(map, addr) \
+({ \
+ unsigned long fptr[2]; \
+ fptr[0] = (addr); \
+ fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
+ (Elf64_Addr) fptr; \
+})
+
+#define DL_STATIC_FUNCTION_ADDRESS(map, addr) \
+({ \
+ static unsigned long fptr[2]; \
+ fptr[0] = (addr); \
+ fptr[1] = (map)->l_info[DT_PLTGOT]->d_un.d_ptr; \
+ (Elf64_Addr) fptr; \
+})
+
+#define DL_DT_INIT_ADDRESS(map, addr) DL_AUTO_FUNCTION_ADDRESS (map, addr)
+#define DL_DT_FINI_ADDRESS(map, addr) DL_AUTO_FUNCTION_ADDRESS (map, addr)
diff --git a/sysdeps/ia64/dl-machine.h b/sysdeps/ia64/dl-machine.h
index 9ad777e99f..a2192a1e2e 100644
--- a/sysdeps/ia64/dl-machine.h
+++ b/sysdeps/ia64/dl-machine.h
@@ -1,5 +1,5 @@
/* Machine-dependent ELF dynamic relocation inline functions. IA-64 version.
- Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -32,26 +32,43 @@
in l_info array. */
#define DT_IA_64(x) (DT_IA_64_##x - DT_LOPROC + DT_NUM)
+/* There are currently 123 dynamic symbols in ld.so.
+ IA64_BOOT_FPTR_TABLE_LEN needs to be at least that big. */
+#define IA64_BOOT_FPTR_TABLE_LEN 200
-/* An FPTR is a function descriptor. Properly they consist of just
- FUNC and GP. But we want to traverse a binary tree too. */
+/* An FDESC is a function descriptor. */
-#define IA64_BOOT_FPTR_SIZE 256
+struct ia64_fdesc
+ {
+ Elf64_Addr ip; /* code entry point */
+ Elf64_Addr gp; /* global pointer */
+ };
-struct ia64_fptr
+struct ia64_fdesc_table
+ {
+ struct ia64_fdesc_table *next;
+ unsigned int len; /* # of entries in fdesc table */
+ volatile unsigned int first_unused; /* index of first available entry */
+ struct ia64_fdesc fdesc[0];
+ };
+
+extern Elf64_Addr __ia64_make_fptr (struct link_map *, const Elf64_Sym *,
+ Elf64_Addr);
+
+static inline void
+__ia64_init_bootstrap_fdesc_table (struct link_map *map)
{
- Elf64_Addr func;
- Elf64_Addr gp;
- struct ia64_fptr *next;
-};
+ Elf64_Addr *boot_table;
-extern struct ia64_fptr __boot_ldso_fptr[];
-extern struct ia64_fptr *__fptr_next;
-extern struct ia64_fptr *__fptr_root;
-extern int __fptr_count;
+ /* careful: this will be called before got has been relocated... */
+ asm ("addl %0 = @gprel (__ia64_boot_fptr_table), gp" : "=r"(boot_table));
-extern Elf64_Addr __ia64_make_fptr (const struct link_map *, Elf64_Addr,
- struct ia64_fptr **, struct ia64_fptr *);
+ map->l_mach.fptr_table_len = IA64_BOOT_FPTR_TABLE_LEN;
+ map->l_mach.fptr_table = boot_table;
+}
+
+#define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
+ __ia64_init_bootstrap_fdesc_table (&bootstrap_map);
/* Return nonzero iff ELF header is compatible with the running host. */
static inline int
@@ -67,7 +84,7 @@ elf_machine_dynamic (void)
{
Elf64_Addr *p;
- __asm__(
+ __asm__ (
".section .sdata\n"
" .type __dynamic_ltv#, @object\n"
" .size __dynamic_ltv#, 8\n"
@@ -75,7 +92,7 @@ elf_machine_dynamic (void)
" data8 @ltv(_DYNAMIC#)\n"
".previous\n"
" addl %0 = @gprel(__dynamic_ltv#), gp ;;"
- : "=r"(p));
+ : "=r" (p));
return *p;
}
@@ -88,19 +105,18 @@ elf_machine_load_address (void)
Elf64_Addr ip;
int *p;
- __asm__(
+ __asm__ (
"1: mov %0 = ip\n"
".section .sdata\n"
"2: data4 @ltv(1b)\n"
" .align 8\n"
".previous\n"
" addl %1 = @gprel(2b), gp ;;"
- : "=r"(ip), "=r"(p));
+ : "=r" (ip), "=r" (p));
- return ip - (Elf64_Addr)*p;
+ return ip - (Elf64_Addr) *p;
}
-
/* Set up the loaded object described by L so its unrelocated PLT
entries will jump to the on-demand fixup code in dl-runtime.c. */
@@ -112,21 +128,21 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
if (lazy)
{
- register Elf64_Addr gp __asm__("gp");
+ register Elf64_Addr gp __asm__ ("gp");
Elf64_Addr *reserve, doit;
/*
* Careful with the typecast here or it will try to add l-l_addr
* pointer elements
*/
- reserve = (Elf64_Addr *)
- (l->l_info[DT_IA_64(PLT_RESERVE)]->d_un.d_ptr + l->l_addr);
+ reserve = ((Elf64_Addr *)
+ (l->l_info[DT_IA_64 (PLT_RESERVE)]->d_un.d_ptr + l->l_addr));
/* Identify this shared object. */
reserve[0] = (Elf64_Addr) l;
/* This function will be called to perform the relocation. */
if (!profile)
- doit = (Elf64_Addr) ((struct ia64_fptr *)&_dl_runtime_resolve)->func;
+ doit = (Elf64_Addr) ((struct ia64_fdesc *) &_dl_runtime_resolve)->ip;
else
{
if (_dl_name_match_p (_dl_profile, l))
@@ -135,7 +151,7 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
want profiling and the timers are started. */
_dl_profile_map = l;
}
- doit = (Elf64_Addr) ((struct ia64_fptr *)&_dl_runtime_profile)->func;
+ doit = (Elf64_Addr) ((struct ia64_fdesc *) &_dl_runtime_profile)->ip;
}
reserve[1] = doit;
@@ -149,111 +165,111 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
/*
This code is used in dl-runtime.c to call the `fixup' function
and then redirect to the address it returns. `fixup()' takes two
- arguments, however fixup_profile() takes three.
+ arguments, however profile_fixup() takes three.
The ABI specifies that we will never see more than 8 input
registers to a function call, thus it is safe to simply allocate
those, and simpler than playing stack games.
- 12/09/99 Jes
*/
-#define TRAMPOLINE_TEMPLATE(tramp_name, fixup_name) \
- extern void tramp_name (void); \
- asm ( "\
- .global " #tramp_name "#
- .proc " #tramp_name "#
-" #tramp_name ":
- { .mmi
- alloc loc0 = ar.pfs, 8, 6, 3, 0
- adds r2 = -144, r12
- adds r3 = -128, r12
- }
- { .mii
- adds r12 = -160, r12
- mov loc1 = b0
- mov out2 = b0 /* needed by fixup_profile */
- ;;
- }
- { .mfb
- mov loc2 = r8 /* preserve struct value register */
- nop.f 0
- nop.b 0
- }
- { .mii
- mov loc3 = r9 /* preserve language specific register */
- mov loc4 = r10 /* preserve language specific register */
- mov loc5 = r11 /* preserve language specific register */
- }
- { .mmi
- stf.spill [r2] = f8, 32
- stf.spill [r3] = f9, 32
- mov out0 = r16
- ;;
- }
- { .mmi
- stf.spill [r2] = f10, 32
- stf.spill [r3] = f11, 32
- shl out1 = r15, 4
- ;;
- }
- { .mmi
- stf.spill [r2] = f12, 32
- stf.spill [r3] = f13, 32
- shladd out1 = r15, 3, out1
- ;;
- }
- { .mmb
- stf.spill [r2] = f14
- stf.spill [r3] = f15
- br.call.sptk.many b0 = " #fixup_name "#
- }
- { .mii
- ld8 r9 = [ret0], 8
- adds r2 = 16, r12
- adds r3 = 32, r12
- ;;
- }
- { .mmi
- ldf.fill f8 = [r2], 32
- ldf.fill f9 = [r3], 32
- mov b0 = loc1
- ;;
- }
- { .mmi
- ldf.fill f10 = [r2], 32
- ldf.fill f11 = [r3], 32
- mov b6 = r9
- ;;
- }
- { .mmi
- ldf.fill f12 = [r2], 32
- ldf.fill f13 = [r3], 32
- mov ar.pfs = loc0
- ;;
- }
- { .mmi
- ldf.fill f14 = [r2], 32
- ldf.fill f15 = [r3], 32
- adds r12 = 160, r12
- ;;
- }
- { .mii
- mov r9 = loc3 /* restore language specific register */
- mov r10 = loc4 /* restore language specific register */
- mov r11 = loc5 /* restore language specific register */
- }
- { .mii
- ld8 gp = [ret0]
- mov r8 = loc2 /* restore struct value register */
- ;;
- }
- /* An alloc is needed for the break system call to work.
- We don't care about the old value of the pfs register. */
- { .mmb
- alloc r2 = ar.pfs, 0, 0, 8, 0
- br.sptk.many b6
- ;;
- }
- .endp " #tramp_name "#")
+#define TRAMPOLINE_TEMPLATE(tramp_name, fixup_name) \
+ extern void tramp_name (void); \
+ asm ( \
+" .global " #tramp_name "#\n" \
+" .proc " #tramp_name "#\n" \
+#tramp_name ":\n" \
+" { .mmi\n" \
+" alloc loc0 = ar.pfs, 8, 6, 3, 0\n" \
+" adds r2 = -144, r12\n" \
+" adds r3 = -128, r12\n" \
+" }\n" \
+" { .mii\n" \
+" adds r12 = -160, r12\n" \
+" mov loc1 = b0\n" \
+" mov out2 = b0 /* needed by fixup_profile */\n" \
+" ;;\n" \
+" }\n" \
+" { .mfb\n" \
+" mov loc2 = r8 /* preserve struct value register */\n" \
+" nop.f 0\n" \
+" nop.b 0\n" \
+" }\n" \
+" { .mii\n" \
+" mov loc3 = r9 /* preserve language specific register */\n" \
+" mov loc4 = r10 /* preserve language specific register */\n" \
+" mov loc5 = r11 /* preserve language specific register */\n" \
+" }\n" \
+" { .mmi\n" \
+" stf.spill [r2] = f8, 32\n" \
+" stf.spill [r3] = f9, 32\n" \
+" mov out0 = r16\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" stf.spill [r2] = f10, 32\n" \
+" stf.spill [r3] = f11, 32\n" \
+" shl out1 = r15, 4\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" stf.spill [r2] = f12, 32\n" \
+" stf.spill [r3] = f13, 32\n" \
+" shladd out1 = r15, 3, out1\n" \
+" ;;\n" \
+" }\n" \
+" { .mmb\n" \
+" stf.spill [r2] = f14\n" \
+" stf.spill [r3] = f15\n" \
+" br.call.sptk.many b0 = " #fixup_name "#\n" \
+" }\n" \
+" { .mii\n" \
+" ld8 r9 = [ret0], 8\n" \
+" adds r2 = 16, r12\n" \
+" adds r3 = 32, r12\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" ldf.fill f8 = [r2], 32\n" \
+" ldf.fill f9 = [r3], 32\n" \
+" mov b0 = loc1\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" ldf.fill f10 = [r2], 32\n" \
+" ldf.fill f11 = [r3], 32\n" \
+" mov b6 = r9\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" ldf.fill f12 = [r2], 32\n" \
+" ldf.fill f13 = [r3], 32\n" \
+" mov ar.pfs = loc0\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" ldf.fill f14 = [r2], 32\n" \
+" ldf.fill f15 = [r3], 32\n" \
+" adds r12 = 160, r12\n" \
+" ;;\n" \
+" }\n" \
+" { .mii\n" \
+" mov r9 = loc3 /* restore language specific register */\n" \
+" mov r10 = loc4 /* restore language specific register */\n" \
+" mov r11 = loc5 /* restore language specific register */\n" \
+" }\n" \
+" { .mii\n" \
+" ld8 gp = [ret0]\n" \
+" mov r8 = loc2 /* restore struct value register */\n" \
+" ;;\n" \
+" }\n" \
+" /* An alloc is needed for the break system call to work.\n" \
+" We don't care about the old value of the pfs register. */\n" \
+" { .mmb\n" \
+" alloc r2 = ar.pfs, 0, 0, 8, 0\n" \
+" br.sptk.many b6\n" \
+" ;;\n" \
+" }\n" \
+" .endp " #tramp_name "#\n");
#ifndef PROF
#define ELF_MACHINE_RUNTIME_TRAMPOLINE \
@@ -270,148 +286,148 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
The C function `_dl_start' is the real entry point;
its return value is the user program's entry point. */
-#define RTLD_START asm ("\
-.text
- .global _start#
- .proc _start#
-_start:
-0: { .mii
- alloc loc0 = ar.pfs, 0, 3, 4, 0
- mov r2 = ip
- addl r3 = @gprel(0b), r0
- ;;
- }
- { .mlx
- /* Calculate the GP, and save a copy in loc1. */
- sub gp = r2, r3
- movl r8 = 0x9804c0270033f
- ;;
- }
- { .mii
- mov ar.fpsr = r8
- sub loc1 = r2, r3
- /* _dl_start wants a pointer to the pointer to the arg block
- and the arg block starts with an integer, thus the magic 16. */
- adds out0 = 16, sp
- }
- { .bbb
- br.call.sptk.many b0 = _dl_start#
- ;;
- }
- .endp _start#
- /* FALLTHRU */
- .global _dl_start_user#
- .proc _dl_start_user#
-_dl_start_user:
- { .mii
- /* Save the pointer to the user entry point fptr in loc2. */
- mov loc2 = ret0
- /* Store the highest stack address. */
- addl r2 = @ltoff(__libc_stack_end#), gp
- addl r3 = @gprel(_dl_skip_args), gp
- ;;
- }
- { .mmi
- ld8 r2 = [r2]
- ld4 r3 = [r3]
- adds r11 = 24, sp /* Load the address of argv. */
- ;;
- }
- { .mii
- st8 [r2] = sp
- adds r10 = 16, sp /* Load the address of argc. */
- mov out2 = r11
- ;;
- /* See if we were run as a command with the executable file
- name as an extra leading argument. If so, adjust the argv
- pointer to skip _dl_skip_args words.
- Note that _dl_skip_args is an integer, not a long - Jes
-
- The stack pointer has to be 16 byte aligned. We cannot simply
- addjust the stack pointer. We have to move the whole argv and
- envp and adjust _dl_argv by _dl_skip_args. H.J. */
- }
- { .mib
- ld8 out1 = [r10] /* is argc actually stored as a long
- or as an int? */
- addl r2 = @ltoff(_dl_argv), gp
- ;;
- }
- { .mmi
- ld8 r2 = [r2] /* Get the address of _dl_argv. */
- sub out1 = out1, r3 /* Get the new argc. */
- shladd r3 = r3, 3, r0
- ;;
- }
- {
- .mib
- ld8 r17 = [r2] /* Get _dl_argv. */
- add r15 = r11, r3 /* The address of the argv we move */
- ;;
- }
- /* ??? Could probably merge these two loops into 3 bundles.
- using predication to control which set of copies we're on. */
-1: /* Copy argv. */
- { .mfi
- ld8 r16 = [r15], 8 /* Load the value in the old argv. */
- ;;
- }
- { .mib
- st8 [r11] = r16, 8 /* Store it in the new argv. */
- cmp.ne p6, p7 = 0, r16
-(p6) br.cond.dptk.few 1b
- ;;
- }
- { .mmi
- mov out3 = r11
- sub r17 = r17, r3 /* Substract _dl_skip_args. */
- addl out0 = @ltoff(_dl_loaded), gp
- }
-1: /* Copy env. */
- { .mfi
- ld8 r16 = [r15], 8 /* Load the value in the old env. */
- ;;
- }
- { .mib
- st8 [r11] = r16, 8 /* Store it in the new env. */
- cmp.ne p6, p7 = 0, r16
-(p6) br.cond.dptk.few 1b
- ;;
- }
- { .mmb
- st8 [r10] = out1 /* Record the new argc. */
- ld8 out0 = [out0]
- ;;
- }
- { .mmb
- ld8 out0 = [out0] /* get the linkmap */
- st8 [r2] = r17 /* Load the new _dl_argv. */
- br.call.sptk.many b0 = _dl_init#
- ;;
- }
- /* Pass our finializer function to the user,
- and jump to the user's entry point. */
- { .mmi
- ld8 r3 = [loc2], 8
- mov b0 = r0
- }
- { .mmi
- addl ret0 = @ltoff(@fptr(_dl_fini#)), gp
- ;;
- mov b6 = r3
- }
- { .mmi
- ld8 ret0 = [ret0]
- ld8 gp = [loc2]
- mov ar.pfs = loc0
- ;;
- }
- { .mfb
- br.sptk.many b6
- ;;
- }
- .endp _dl_start_user#
-.previous");
+#define RTLD_START asm ( \
+".text\n" \
+" .global _start#\n" \
+" .proc _start#\n" \
+"_start:\n" \
+"0: { .mii\n" \
+" alloc loc0 = ar.pfs, 0, 3, 4, 0\n" \
+" mov r2 = ip\n" \
+" addl r3 = @gprel(0b), r0\n" \
+" ;;\n" \
+" }\n" \
+" { .mlx\n" \
+" /* Calculate the GP, and save a copy in loc1. */\n" \
+" sub gp = r2, r3\n" \
+" movl r8 = 0x9804c0270033f\n" \
+" ;;\n" \
+" }\n" \
+" { .mii\n" \
+" mov ar.fpsr = r8\n" \
+" sub loc1 = r2, r3\n" \
+" /* _dl_start wants a pointer to the pointer to the arg block and\n" \
+" the arg block starts with an integer, thus the magic 16. */\n" \
+" adds out0 = 16, sp\n" \
+" }\n" \
+" { .bbb\n" \
+" br.call.sptk.many b0 = _dl_start#\n" \
+" ;;\n" \
+" }\n" \
+" .endp _start#\n" \
+" /* FALLTHRU */\n" \
+" .global _dl_start_user#\n" \
+" .proc _dl_start_user#\n" \
+"_dl_start_user:\n" \
+" { .mii\n" \
+" /* Save the pointer to the user entry point fptr in loc2. */\n" \
+" mov loc2 = ret0\n" \
+" /* Store the highest stack address. */\n" \
+" addl r2 = @ltoff(__libc_stack_end#), gp\n" \
+" addl r3 = @gprel(_dl_skip_args), gp\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" ld8 r2 = [r2]\n" \
+" ld4 r3 = [r3]\n" \
+" adds r11 = 24, sp /* Load the address of argv. */\n" \
+" ;;\n" \
+" }\n" \
+" { .mii\n" \
+" st8 [r2] = sp\n" \
+" adds r10 = 16, sp /* Load the address of argc. */\n" \
+" mov out2 = r11\n" \
+" ;;\n" \
+" /* See if we were run as a command with the executable file\n" \
+" name as an extra leading argument. If so, adjust the argv\n" \
+" pointer to skip _dl_skip_args words.\n" \
+" Note that _dl_skip_args is an integer, not a long - Jes\n" \
+"\n" \
+" The stack pointer has to be 16 byte aligned. We cannot simply\n" \
+" addjust the stack pointer. We have to move the whole argv and\n" \
+" envp and adjust _dl_argv by _dl_skip_args. H.J. */\n" \
+" }\n" \
+" { .mib\n" \
+" ld8 out1 = [r10] /* is argc actually stored as a long\n" \
+" or as an int? */\n" \
+" addl r2 = @ltoff(_dl_argv), gp\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" ld8 r2 = [r2] /* Get the address of _dl_argv. */\n" \
+" sub out1 = out1, r3 /* Get the new argc. */\n" \
+" shladd r3 = r3, 3, r0\n" \
+" ;;\n" \
+" }\n" \
+" {\n" \
+" .mib\n" \
+" ld8 r17 = [r2] /* Get _dl_argv. */\n" \
+" add r15 = r11, r3 /* The address of the argv we move */\n" \
+" ;;\n" \
+" }\n" \
+" /* ??? Could probably merge these two loops into 3 bundles.\n" \
+" using predication to control which set of copies we're on. */\n" \
+"1: /* Copy argv. */\n" \
+" { .mfi\n" \
+" ld8 r16 = [r15], 8 /* Load the value in the old argv. */\n" \
+" ;;\n" \
+" }\n" \
+" { .mib\n" \
+" st8 [r11] = r16, 8 /* Store it in the new argv. */\n" \
+" cmp.ne p6, p7 = 0, r16\n" \
+"(p6) br.cond.dptk.few 1b\n" \
+" ;;\n" \
+" }\n" \
+" { .mmi\n" \
+" mov out3 = r11\n" \
+" sub r17 = r17, r3 /* Substract _dl_skip_args. */\n" \
+" addl out0 = @ltoff(_dl_loaded), gp\n" \
+" }\n" \
+"1: /* Copy env. */\n" \
+" { .mfi\n" \
+" ld8 r16 = [r15], 8 /* Load the value in the old env. */\n" \
+" ;;\n" \
+" }\n" \
+" { .mib\n" \
+" st8 [r11] = r16, 8 /* Store it in the new env. */\n" \
+" cmp.ne p6, p7 = 0, r16\n" \
+"(p6) br.cond.dptk.few 1b\n" \
+" ;;\n" \
+" }\n" \
+" { .mmb\n" \
+" st8 [r10] = out1 /* Record the new argc. */\n" \
+" ld8 out0 = [out0]\n" \
+" ;;\n" \
+" }\n" \
+" { .mmb\n" \
+" ld8 out0 = [out0] /* get the linkmap */\n" \
+" st8 [r2] = r17 /* Load the new _dl_argv. */\n" \
+" br.call.sptk.many b0 = _dl_init#\n" \
+" ;;\n" \
+" }\n" \
+" /* Pass our finializer function to the user,\n" \
+" and jump to the user's entry point. */\n" \
+" { .mmi\n" \
+" ld8 r3 = [loc2], 8\n" \
+" mov b0 = r0\n" \
+" }\n" \
+" { .mmi\n" \
+" addl ret0 = @ltoff(@fptr(_dl_fini#)), gp\n" \
+" ;;\n" \
+" mov b6 = r3\n" \
+" }\n" \
+" { .mmi\n" \
+" ld8 ret0 = [ret0]\n" \
+" ld8 gp = [loc2]\n" \
+" mov ar.pfs = loc0\n" \
+" ;;\n" \
+" }\n" \
+" { .mfb\n" \
+" br.sptk.many b6\n" \
+" ;;\n" \
+" }\n" \
+" .endp _dl_start_user#\n" \
+".previous\n");
#ifndef RTLD_START_SPECIAL_INIT
@@ -434,8 +450,8 @@ _dl_start_user:
#define ELF_MACHINE_NO_REL 1
/* Return the address of the entry point. */
-#define ELF_MACHINE_START_ADDRESS(map, start) \
- DL_FUNCTION_ADDRESS (map, start)
+#define ELF_MACHINE_START_ADDRESS(map, start) \
+ DL_STATIC_FUNCTION_ADDRESS (map, start)
#define elf_machine_profile_fixup_plt(l, reloc, rel_addr, value) \
elf_machine_fixup_plt (l, reloc, rel_addr, value)
@@ -452,7 +468,9 @@ elf_machine_fixup_plt (struct link_map *l, lookup_t t,
* being called */
/* got has already been relocated in elf_get_dynamic_info() */
reloc_addr[1] = t->l_info[DT_PLTGOT]->d_un.d_ptr;
- reloc_addr[0] = value;
+ /* we need a "release" here to ensure that the gp is visible before
+ the code entry point is updated: */
+ ((volatile Elf64_Addr *) reloc_addr)[0] = value;
return (Elf64_Addr) reloc_addr;
}
@@ -487,7 +505,7 @@ elf_machine_rela (struct link_map *map,
const struct r_found_version *version,
Elf64_Addr *const reloc_addr)
{
- unsigned long const r_type = ELF64_R_TYPE (reloc->r_info);
+ const unsigned long int r_type = ELF64_R_TYPE (reloc->r_info);
Elf64_Addr value;
#ifndef RTLD_BOOTSTRAP
@@ -533,35 +551,9 @@ elf_machine_rela (struct link_map *map,
return;
}
else if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_FPTR64LSB))
-#ifndef RTLD_BOOTSTRAP
- value = __ia64_make_fptr (sym_map, value, &__fptr_root, NULL);
-#else
- {
- struct ia64_fptr *p_boot_ldso_fptr;
- struct ia64_fptr **p_fptr_root;
- int *p_fptr_count;
-
- /* Special care must be taken to address these variables
- during bootstrap. Further, since we don't know exactly
- when __fptr_next will be relocated, we index directly
- off __boot_ldso_fptr. */
- asm ("addl %0 = @gprel(__boot_ldso_fptr#), gp\n\t"
- "addl %1 = @gprel(__fptr_root#), gp\n\t"
- "addl %2 = @gprel(__fptr_count#), gp"
- : "=r"(p_boot_ldso_fptr),
- "=r"(p_fptr_root),
- "=r"(p_fptr_count));
-
- /*
- * Go from the top - __ia64_make_fptr goes from the bottom,
- * this way we will never clash.
- */
- value = __ia64_make_fptr (sym_map, value, p_fptr_root,
- &p_boot_ldso_fptr[--*p_fptr_count]);
- }
-#endif
+ value = __ia64_make_fptr (sym_map, sym, value);
else if (R_IA64_TYPE (r_type) == R_IA64_TYPE (R_IA64_PCREL64LSB))
- value -= (Elf64_Addr)reloc_addr & -16;
+ value -= (Elf64_Addr) reloc_addr & -16;
else
assert (! "unexpected dynamic reloc type");
}
@@ -573,7 +565,7 @@ elf_machine_rela (struct link_map *map,
if (R_IA64_FORMAT (r_type) == R_IA64_FORMAT_64LSB)
*reloc_addr = value;
else if (R_IA64_FORMAT (r_type) == R_IA64_FORMAT_32LSB)
- *(int *)reloc_addr = value;
+ *(int *) reloc_addr = value;
else if (r_type == R_IA64_IPLTLSB)
{
reloc_addr[0] = 0;
@@ -589,8 +581,8 @@ static inline void
elf_machine_lazy_rel (struct link_map *map,
Elf64_Addr l_addr, const Elf64_Rela *reloc)
{
- Elf64_Addr * const reloc_addr = (void *)(l_addr + reloc->r_offset);
- unsigned long const r_type = ELF64_R_TYPE (reloc->r_info);
+ Elf64_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
+ const unsigned long int r_type = ELF64_R_TYPE (reloc->r_info);
if (r_type == R_IA64_IPLTLSB)
{
diff --git a/sysdeps/ia64/dl-symaddr.c b/sysdeps/ia64/dl-symaddr.c
index 99b05baa60..52c5a12e14 100644
--- a/sysdeps/ia64/dl-symaddr.c
+++ b/sysdeps/ia64/dl-symaddr.c
@@ -1,5 +1,5 @@
/* Get the symbol address. IA-64 version.
- Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -27,13 +27,7 @@ _dl_symbol_address (const struct link_map *map, const Elf64_Sym *ref)
/* On ia64, we have to return the pointer to function descriptor. */
if (ELFW(ST_TYPE) (ref->st_info) == STT_FUNC)
- return (void *) __ia64_make_fptr (map, value, &__fptr_root, NULL);
+ return (void *) __ia64_make_fptr (map, ref, value);
else
return (void *) value;
}
-
-Elf64_Addr
-_dl_function_address (const struct link_map *map, Elf64_Addr start)
-{
- return __ia64_make_fptr (map, start, &__fptr_root, NULL);
-}