diff options
author | Ulrich Drepper <drepper@redhat.com> | 1998-03-04 09:53:17 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1998-03-04 09:53:17 +0000 |
commit | ea7eb7e3eb09a7f9444e0c599fdbafaadb3e391d (patch) | |
tree | 0d80af9968048e23bd0781ee7b9759c9af27235d /elf | |
parent | f6d8a525ef354f5903f81d20ed879935c633aafd (diff) | |
download | glibc-ea7eb7e3eb09a7f9444e0c599fdbafaadb3e391d.zip glibc-ea7eb7e3eb09a7f9444e0c599fdbafaadb3e391d.tar.gz glibc-ea7eb7e3eb09a7f9444e0c599fdbafaadb3e391d.tar.bz2 |
Update.
1998-03-04 09:43 Ulrich Drepper <drepper@cygnus.com>
* elf/link.h (struct link_map): Add new field l_reloc_result.
* elf/dl-reloc.c (_dl_relocate_object): Allocate array for results
of relocation for the object to be profiled.
* elf/dl-object.c (_dl_new_object): Initialize l_reloc_result field
to NULL.
* elf/rtld.c (_dl_start): Add comment that we must not allocate an
array here.
* elf/dl-runtime.c (profile_fixup): If l_reloc_result array already
contains a result from a previous run use this instead of computing
the value again.
* elf/dl-minimal.c (malloc): Remove limit for size of allocation.
1998-03-04 11:32 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
Diffstat (limited to 'elf')
-rw-r--r-- | elf/dl-minimal.c | 10 | ||||
-rw-r--r-- | elf/dl-object.c | 3 | ||||
-rw-r--r-- | elf/dl-reloc.c | 21 | ||||
-rw-r--r-- | elf/dl-runtime.c | 97 | ||||
-rw-r--r-- | elf/rtld.c | 3 |
5 files changed, 83 insertions, 51 deletions
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index da9c33f..daf6233 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -1,5 +1,5 @@ /* Minimal replacements for basic facilities used in the dynamic linker. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998 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,7 +27,7 @@ #include <errno.h> /* Minimal `malloc' allocator for use while loading shared libraries. - Only small blocks are allocated, and none are ever freed. */ + No block is ever freed. */ static void *alloc_ptr, *alloc_end, *alloc_last_block; @@ -61,13 +61,13 @@ malloc (size_t n) { /* Insufficient space left; allocate another page. */ caddr_t page; - assert (n <= _dl_pagesize); - page = __mmap (0, _dl_pagesize, PROT_READ|PROT_WRITE, + size_t nup = (n + _dl_pagesize - 1) & ~(_dl_pagesize - 1); + page = __mmap (0, nup, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, _dl_zerofd, 0); assert (page != MAP_FAILED); if (page != alloc_end) alloc_ptr = page; - alloc_end = page + _dl_pagesize; + alloc_end = page + nup; } alloc_last_block = (void *) alloc_ptr; diff --git a/elf/dl-object.c b/elf/dl-object.c index 65f80d1..b2dbb83 100644 --- a/elf/dl-object.c +++ b/elf/dl-object.c @@ -1,5 +1,5 @@ /* Storage management for the chain of loaded shared objects. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998 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 @@ -45,6 +45,7 @@ _dl_new_object (char *realname, const char *libname, int type) new->l_libname = newname; new->l_type = type; new->l_rpath_dirs = NULL; + new->l_reloc_result = NULL; if (_dl_loaded == NULL) { diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c index 4f6eff8..531da96 100644 --- a/elf/dl-reloc.c +++ b/elf/dl-reloc.c @@ -1,5 +1,5 @@ /* Relocate a shared object and resolve its references to other loaded objects. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998 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,11 +17,12 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <errno.h> #include <link.h> -#include <sys/types.h> -#include <sys/mman.h> +#include <stdlib.h> #include <unistd.h> -#include <errno.h> +#include <sys/mman.h> +#include <sys/types.h> #include "dynamic-link.h" @@ -67,6 +68,18 @@ _dl_relocate_object (struct link_map *l, struct link_map *scope[], int lazy) #include "dynamic-link.h" ELF_DYNAMIC_RELOCATE (l, lazy, 1); + + if (_dl_profile_map == l) + { + /* Allocate the array which will contain the already found + relocations. */ + l->l_reloc_result = + (ElfW(Addr) *) calloc (sizeof (ElfW(Addr)), + l->l_info[DT_PLTRELSZ]->d_un.d_val); + if (l->l_reloc_result == NULL) + _dl_sysdep_fatal (_dl_argv[0] ?: "<program name unknown>", + "cannot allocate memory for profiling", NULL); + } } /* Mark the object so we know this work has been done. */ diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c index 8087fbd..99927a9 100644 --- a/elf/dl-runtime.c +++ b/elf/dl-runtime.c @@ -1,5 +1,5 @@ /* On-demand PLT fixup for shared objects. - Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998 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 @@ -162,55 +162,70 @@ profile_fixup ( struct link_map *l, ElfW(Word) reloc_offset, ElfW(Addr) retaddr) { void (*mcount_fct) (ElfW(Addr), ElfW(Addr)) = _dl_mcount; - - const ElfW(Sym) *const symtab - = (const ElfW(Sym) *) (l->l_addr + l->l_info[DT_SYMTAB]->d_un.d_ptr); - const char *strtab = - (const char *) (l->l_addr + l->l_info[DT_STRTAB]->d_un.d_ptr); - - const PLTREL *const reloc - = (const void *) (l->l_addr + l->l_info[DT_JMPREL]->d_un.d_ptr + - reloc_offset); - const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)]; + ElfW(Addr) *resultp; ElfW(Addr) value; - /* Set up the scope to find symbols referenced by this object. */ - struct link_map **scope = _dl_object_relocation_scope (l); + /* This is the address in the array where we store the result of previous + relocations. */ + resultp = &l->l_reloc_result[reloc_offset / sizeof (PLTREL)]; - /* Sanity check that we're really looking at a PLT relocation. */ - assert (ELFW(R_TYPE)(reloc->r_info) == ELF_MACHINE_JMP_SLOT); - - /* Look up the target symbol. */ - switch (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL) + value = *resultp; + if (value == 0) { - default: - { - const ElfW(Half) *vernum = (const ElfW(Half) *) - (l->l_addr + l->l_info[VERSYMIDX (DT_VERSYM)]->d_un.d_ptr); - ElfW(Half) ndx = vernum[ELFW(R_SYM) (reloc->r_info)]; - const struct r_found_version *version = &l->l_versions[ndx]; - - if (version->hash != 0) + /* This is the first time we have to relocate this object. */ + const ElfW(Sym) *const symtab + = (const ElfW(Sym) *) (l->l_addr + l->l_info[DT_SYMTAB]->d_un.d_ptr); + const char *strtab = + (const char *) (l->l_addr + l->l_info[DT_STRTAB]->d_un.d_ptr); + + const PLTREL *const reloc + = (const void *) (l->l_addr + l->l_info[DT_JMPREL]->d_un.d_ptr + + reloc_offset); + const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)]; + + /* Set up the scope to find symbols referenced by this object. */ + struct link_map **scope = _dl_object_relocation_scope (l); + + /* Sanity check that we're really looking at a PLT relocation. */ + assert (ELFW(R_TYPE)(reloc->r_info) == ELF_MACHINE_JMP_SLOT); + + /* Look up the target symbol. */ + switch (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL) + { + default: { - value = _dl_lookup_versioned_symbol(strtab + sym->st_name, - &sym, scope, l->l_name, - version, ELF_MACHINE_JMP_SLOT); - break; + const ElfW(Half) *vernum = (const ElfW(Half) *) + (l->l_addr + l->l_info[VERSYMIDX (DT_VERSYM)]->d_un.d_ptr); + ElfW(Half) ndx = vernum[ELFW(R_SYM) (reloc->r_info)]; + const struct r_found_version *version = &l->l_versions[ndx]; + + if (version->hash != 0) + { + value = _dl_lookup_versioned_symbol(strtab + sym->st_name, + &sym, scope, l->l_name, + version, + ELF_MACHINE_JMP_SLOT); + break; + } } - } - case 0: - value = _dl_lookup_symbol (strtab + sym->st_name, &sym, scope, - l->l_name, ELF_MACHINE_JMP_SLOT); - } + case 0: + value = _dl_lookup_symbol (strtab + sym->st_name, &sym, scope, + l->l_name, ELF_MACHINE_JMP_SLOT); + } - /* Currently value contains the base load address of the object - that defines sym. Now add in the symbol offset. */ - value = (sym ? value + sym->st_value : 0); + /* Currently value contains the base load address of the object + that defines sym. Now add in the symbol offset. */ + value = (sym ? value + sym->st_value : 0); - /* And now perhaps the relocation addend. */ - value = elf_machine_plt_value (l, reloc, value); + /* And now perhaps the relocation addend. */ + value = elf_machine_plt_value (l, reloc, value); + + *_dl_global_scope_end = NULL; + + /* Store the result for later runs. */ + *resultp = value; + } - *_dl_global_scope_end = NULL; (*mcount_fct) (retaddr, value); return value; @@ -114,6 +114,9 @@ _dl_start (void *arg) data access using the global offset table. */ ELF_DYNAMIC_RELOCATE (&bootstrap_map, 0, 0); + /* Please note that we don't allow profiling of this object and + therefore need not test whether we have to allocate the array + for the relocation results (as done in dl-reloc.c). */ /* Now life is sane; we can call functions and access global data. Set up to use the operating system facilities, and find out from |