diff options
Diffstat (limited to 'elf')
-rw-r--r-- | elf/Makefile | 2 | ||||
-rw-r--r-- | elf/dl-dst.h | 2 | ||||
-rw-r--r-- | elf/dl-libc.c | 122 | ||||
-rw-r--r-- | elf/dl-open.c | 2 | ||||
-rw-r--r-- | elf/dl-profstub.c | 5 | ||||
-rw-r--r-- | elf/ldsodefs.h | 4 |
6 files changed, 130 insertions, 7 deletions
diff --git a/elf/Makefile b/elf/Makefile index 6c52643..b5145ea 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -22,7 +22,7 @@ subdir := elf headers = elf.h bits/elfclass.h bits/dlfcn.h link.h dlfcn.h routines = $(dl-routines) dl-open dl-close dl-symbol dl-support \ - dl-addr enbl-secure dl-profstub dl-origin + dl-addr enbl-secure dl-profstub dl-origin dl-libc # The core dynamic linking functions are in libc for the static and # profiled libraries. diff --git a/elf/dl-dst.h b/elf/dl-dst.h index 4b014d6..ca32e25 100644 --- a/elf/dl-dst.h +++ b/elf/dl-dst.h @@ -33,7 +33,7 @@ extern size_t _dl_dst_count (const char *name, int is_path); -/* Guess from the number of DSTs the length of the restul string. */ +/* Guess from the number of DSTs the length of the result string. */ #define DL_DST_REQUIRED(l, name, len, cnt) \ ({ \ size_t origin_len; \ diff --git a/elf/dl-libc.c b/elf/dl-libc.c new file mode 100644 index 0000000..afb3f2d --- /dev/null +++ b/elf/dl-libc.c @@ -0,0 +1,122 @@ +/* Handle loading and unloading shared objects for internal libc purposes. + Copyright (C) 1999 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Zack Weinberg <zack@rabi.columbia.edu>, 1999. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <dlfcn.h> +#include <stdlib.h> +#include <ldsodefs.h> + +/* The purpose of this file is to provide wrappers around the dynamic + linker error mechanism (similar to dlopen() et al in libdl) which + are usable from within libc. Generally we want to throw away the + string that dlerror() would return and just pass back a null pointer + for errors. This also lets the rest of libc not know about the error + handling mechanism. + + Much of this code came from gconv_dl.c with slight modifications. */ + +static int +internal_function +dlerror_run (void (*operate) (void *), void *args) +{ + char *last_errstring = NULL; + int result; + + (void) _dl_catch_error (&last_errstring, operate, args); + + result = last_errstring != NULL; + if (result) + free (last_errstring); + + return result; +} + +/* These functions are called by dlerror_run... */ + +struct do_dlopen_args +{ + /* Argument to do_dlopen. */ + const char *name; + + /* Return from do_dlopen. */ + struct link_map *map; +}; + +struct do_dlsym_args +{ + /* Arguments to do_dlsym. */ + struct link_map *map; + const char *name; + + /* Return values of do_dlsym. */ + ElfW(Addr) loadbase; + const ElfW(Sym) *ref; +}; + +static void +do_dlopen (void *ptr) +{ + struct do_dlopen_args *args = (struct do_dlopen_args *) ptr; + /* Open and relocate the shared object. */ + args->map = _dl_open (args->name, RTLD_LAZY, NULL); +} + +static void +do_dlsym (void *ptr) +{ + struct do_dlsym_args *args = (struct do_dlsym_args *) ptr; + args->ref = NULL; + args->loadbase = _dl_lookup_symbol (args->name, &args->ref, + args->map->l_local_scope, + args->map->l_name, 0); +} + +static void +do_dlclose (void *ptr) +{ + _dl_close ((struct link_map *) ptr); +} + +/* ... and these functions call dlerror_run. */ + +void * +__libc_dlopen (const char *__name) +{ + struct do_dlopen_args args; + args.name = __name; + + return (dlerror_run (do_dlopen, &args) ? NULL : (void *) args.map); +} + +void * +__libc_dlsym (void *__map, const char *__name) +{ + struct do_dlsym_args args; + args.map = __map; + args.name = __name; + + return (dlerror_run (do_dlsym, &args) ? NULL + : (void *) (args.loadbase + args.ref->st_value)); +} + +int +__libc_dlclose (void *__map) +{ + return dlerror_run (do_dlclose, __map); +} diff --git a/elf/dl-open.c b/elf/dl-open.c index 149badd..a9d81c7 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -127,7 +127,7 @@ dl_open_worker (void *a) /* If the substitution failed don't try to load. */ if (*new_file == '\0') _dl_signal_error (0, "dlopen", - "empty dynamics string token substitution"); + "empty dynamic string token substitution"); /* Now we have a new file name. */ file = new_file; diff --git a/elf/dl-profstub.c b/elf/dl-profstub.c index 10db640..55304a7 100644 --- a/elf/dl-profstub.c +++ b/elf/dl-profstub.c @@ -28,9 +28,10 @@ extern struct link_map *_dl_profile_map; void -_dl_mcount_wrapper (ElfW(Addr) selfpc) +_dl_mcount_wrapper (void *selfpc) { - _dl_mcount ((ElfW(Addr)) __builtin_return_address (0), selfpc); + _dl_mcount ((ElfW(Addr)) __builtin_return_address (0), + (ElfW(Addr)) selfpc); } diff --git a/elf/ldsodefs.h b/elf/ldsodefs.h index f8db76c..bd33ba1 100644 --- a/elf/ldsodefs.h +++ b/elf/ldsodefs.h @@ -407,7 +407,7 @@ extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc); /* This function is simply a wrapper around the _dl_mcount function which does not require a FROMPC parameter since this is the calling function. */ -extern void _dl_mcount_wrapper (ElfW(Addr) selfpc); +extern void _dl_mcount_wrapper (void *selfpc); /* Show the members of the auxiliary array passed up from the kernel. */ @@ -432,7 +432,7 @@ extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform, helps do it. */ #define _CALL_DL_FCT(fctp, args) \ ({ if (_dl_profile_map != NULL) \ - _dl_mcount_wrapper ((ElfW(Addr)) fctp); \ + _dl_mcount_wrapper (fctp); \ (*fctp) args; \ }) |