diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/csu/i386/Makefile | 6 | ||||
-rw-r--r-- | lib/csu/i386/crt0.c | 136 | ||||
-rw-r--r-- | lib/libc/gen/Makefile.inc | 10 | ||||
-rw-r--r-- | lib/libc/gen/dladdr.3 (renamed from lib/csu/i386/dladdr.3) | 2 | ||||
-rw-r--r-- | lib/libc/gen/dlfcn.c | 96 | ||||
-rw-r--r-- | lib/libc/gen/dlopen.3 (renamed from lib/csu/i386/dlopen.3) | 0 |
6 files changed, 122 insertions, 128 deletions
diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile index 42907dc..a05ecaf 100644 --- a/lib/csu/i386/Makefile +++ b/lib/csu/i386/Makefile @@ -1,13 +1,9 @@ # from: @(#)Makefile 5.6 (Berkeley) 5/22/91 -# $Id: Makefile,v 1.33 1998/01/12 18:29:02 eivind Exp $ +# $Id: Makefile,v 1.34 1998/02/06 16:46:31 jdp Exp $ CFLAGS+= -DLIBC_SCCS -fno-omit-frame-pointer -I${.CURDIR} OBJS= crt0.o c++rt0.o gcrt0.o scrt0.o sgcrt0.o CLEANFILES+= a.out -MAN3+= dladdr.3 dlopen.3 -MLINKS+= dlopen.3 dlsym.3 \ - dlopen.3 dlerror.3 \ - dlopen.3 dlclose.3 all: ${OBJS} diff --git a/lib/csu/i386/crt0.c b/lib/csu/i386/crt0.c index 80759cf..75b1ac5 100644 --- a/lib/csu/i386/crt0.c +++ b/lib/csu/i386/crt0.c @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: crt0.c,v 1.31 1997/11/22 03:34:45 brian Exp $ + * $Id: crt0.c,v 1.32 1998/02/06 16:46:33 jdp Exp $ */ #include <sys/param.h> @@ -84,7 +84,6 @@ static int _strncmp(); #endif /* LDSO */ extern struct _dynamic _DYNAMIC; -static struct ld_entry *ld_entry; static void __do_dynamic_link(char **argv); #endif /* DYNAMIC */ @@ -94,7 +93,9 @@ static char empty[1]; char *__progname = empty; char **environ; -static int ldso_version; +/* Globals used by dlopen() and related functions in libc */ +struct ld_entry *__ldso_entry; +int __ldso_version; extern unsigned char etext; extern unsigned char eprol asm ("eprol"); @@ -257,22 +258,22 @@ __do_dynamic_link(argv) crt.crt_argv = argv; entry = (int (*)())(crt.crt_ba + sizeof hdr); - ldso_version = (*entry)(CRT_VERSION_BSD_5, &crt); - ld_entry = crt.crt_ldentry; - if (ldso_version == -1 && ld_entry == NULL) { + __ldso_version = (*entry)(CRT_VERSION_BSD_5, &crt); + __ldso_entry = crt.crt_ldentry; + if (__ldso_version == -1 && __ldso_entry == NULL) { /* If version 5 not recognised, try version 4 */ - ldso_version = (*entry)(CRT_VERSION_BSD_4, &crt); - ld_entry = crt.crt_ldentry; - if (ldso_version == -1 && ld_entry == NULL) { + __ldso_version = (*entry)(CRT_VERSION_BSD_4, &crt); + __ldso_entry = crt.crt_ldentry; + if (__ldso_version == -1 && __ldso_entry == NULL) { /* if version 4 not recognised, try version 3 */ - ldso_version = (*entry)(CRT_VERSION_BSD_3, &crt); - ld_entry = _DYNAMIC.d_entry; + __ldso_version = (*entry)(CRT_VERSION_BSD_3, &crt); + __ldso_entry = _DYNAMIC.d_entry; } } - if (ldso_version == -1) { + if (__ldso_version == -1) { _PUTMSG("ld.so failed"); - if (ld_entry != NULL) { - const char *msg = (ld_entry->dlerror)(); + if (__ldso_entry != NULL) { + const char *msg = (__ldso_entry->dlerror)(); if(msg != NULL) { const char *endp; _PUTMSG(": "); @@ -285,74 +286,13 @@ __do_dynamic_link(argv) } - if (ldso_version >= LDSO_VERSION_HAS_DLEXIT) - atexit(ld_entry->dlexit); + if (__ldso_version >= LDSO_VERSION_HAS_DLEXIT) + atexit(__ldso_entry->dlexit); return; } /* - * DL stubs - */ - -void * -dlopen(name, mode) -const char *name; -int mode; -{ - if (ld_entry == NULL) - return NULL; - - return (ld_entry->dlopen)(name, mode); -} - -int -dlclose(fd) -void *fd; -{ - if (ld_entry == NULL) - return -1; - - return (ld_entry->dlclose)(fd); -} - -void * -dlsym(fd, name) -void *fd; -const char *name; -{ - if (ld_entry == NULL) - return NULL; - - if (ldso_version >= LDSO_VERSION_HAS_DLSYM3) { - void *retaddr = *(&fd - 1); /* XXX - ABI/machine dependent */ - return (ld_entry->dlsym3)(fd, name, retaddr); - } else - return (ld_entry->dlsym)(fd, name); -} - - -const char * -dlerror() -{ - if (ld_entry == NULL) - return "Service unavailable"; - - return (ld_entry->dlerror)(); -} - -int -dladdr(addr, dlip) - const void *addr; - Dl_info *dlip; -{ - if (ld_entry == NULL || ldso_version < LDSO_VERSION_HAS_DLADDR) - return 0; - return (ld_entry->dladdr)(addr, dlip); -} - - -/* * Support routines */ @@ -407,48 +347,6 @@ _getenv(name) asm(" movl $-1,%eax"); asm(" ret"); -#else /* DYNAMIC */ - -/* - * DL stubs for static linking case (just return error) - */ - -void * -dlopen(name, mode) -const char *name; -int mode; -{ - return NULL; -} - -int -dlclose(fd) -void *fd; -{ - return -1; -} - -void * -dlsym(fd, name) -void *fd; -const char *name; -{ - return NULL; -} - -const char * -dlerror() -{ - return "Service unavailable"; -} - -int -dladdr(addr, dlip) - const void *addr; - Dl_info *dlip; -{ - return 0; -} #endif /* DYNAMIC */ diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index e0b087f..fbf76bd 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,5 +1,5 @@ # @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 -# $Id: Makefile.inc,v 1.40 1997/10/15 16:15:24 bde Exp $ +# $Id: Makefile.inc,v 1.41 1997/10/21 08:41:06 bde Exp $ # machine-independent gen sources .PATH: ${.CURDIR}/../libc/${MACHINE}/gen ${.CURDIR}/../libc/gen @@ -7,7 +7,7 @@ SRCS+= _rand48.c alarm.c arc4random.c assert.c \ clock.c closedir.c config.c confstr.c \ crypt.c ctermid.c daemon.c devname.c disklabel.c \ - drand48.c erand48.c err.c errlst.c \ + dlfcn.c drand48.c erand48.c err.c errlst.c \ exec.c fnmatch.c fstab.c fts.c getbootfile.c getbsize.c \ getcap.c getcwd.c getdomainname.c getgrent.c getgrouplist.c \ gethostname.c getloadavg.c getlogin.c getmntinfo.c getnetgrent.c \ @@ -45,7 +45,8 @@ errlst.o errlst.po: .if ${LIB} == "c" MAN3+= alarm.3 arc4random.3 clock.3 config_open.3 \ confstr.3 crypt.3 ctermid.3 daemon.3 \ - devname.3 directory.3 err.3 exec.3 fnmatch.3 frexp.3 fts.3 \ + devname.3 directory.3 dladdr.3 dlopen.3 \ + err.3 exec.3 fnmatch.3 frexp.3 fts.3 \ getbootfile.3 getbsize.3 getcap.3 getcwd.3 \ getdiskbyname.3 getdomainname.3 getfsent.3 \ getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \ @@ -69,6 +70,9 @@ MLINKS+=crypt.3 des_cipher.3 crypt.3 des_setkey.3 crypt.3 encrypt.3 \ MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \ directory.3 readdir.3 directory.3 rewinddir.3 directory.3 seekdir.3 \ directory.3 telldir.3 +MLINKS+=dlopen.3 dlsym.3 \ + dlopen.3 dlerror.3 \ + dlopen.3 dlclose.3 MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 exect.3 \ exec.3 execv.3 exec.3 execvp.3 MLINKS+=err.3 err_set_exit.3 err.3 err_set_file.3 err.3 errx.3 err.3 verr.3 \ diff --git a/lib/csu/i386/dladdr.3 b/lib/libc/gen/dladdr.3 index 97af8ce..bb5ab41 100644 --- a/lib/csu/i386/dladdr.3 +++ b/lib/libc/gen/dladdr.3 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id$ +.\" $Id: dladdr.3,v 1.1 1998/02/06 16:46:34 jdp Exp $ .\" .Dd February 5, 1998 .Os FreeBSD diff --git a/lib/libc/gen/dlfcn.c b/lib/libc/gen/dlfcn.c new file mode 100644 index 0000000..3f00346 --- /dev/null +++ b/lib/libc/gen/dlfcn.c @@ -0,0 +1,96 @@ +/*- + * Copyright (c) 1998 John D. Polstra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +/* + * Trampolines to services provided by the dynamic linker. + */ + +#include <sys/types.h> +#include <nlist.h> /* XXX - Required by link.h */ +#include <dlfcn.h> +#include <link.h> +#include <stddef.h> + +/* + * These variables are set by code in crt0.o. For compatibility with + * old executables, they must be common, not extern. + */ +struct ld_entry *__ldso_entry; /* Entry points to dynamic linker */ +int __ldso_version; /* Dynamic linker version number */ + +void * +dlopen(name, mode) + const char *name; + int mode; +{ + if (__ldso_entry == NULL) + return NULL; + return (__ldso_entry->dlopen)(name, mode); +} + +int +dlclose(fd) + void *fd; +{ + if (__ldso_entry == NULL) + return -1; + return (__ldso_entry->dlclose)(fd); +} + +void * +dlsym(fd, name) + void *fd; + const char *name; +{ + if (__ldso_entry == NULL) + return NULL; + if (__ldso_version >= LDSO_VERSION_HAS_DLSYM3) { + void *retaddr = *(&fd - 1); /* XXX - ABI/machine dependent */ + return (__ldso_entry->dlsym3)(fd, name, retaddr); + } else + return (__ldso_entry->dlsym)(fd, name); +} + + +const char * +dlerror() +{ + if (__ldso_entry == NULL) + return "Service unavailable"; + return (__ldso_entry->dlerror)(); +} + +int +dladdr(addr, dlip) + const void *addr; + Dl_info *dlip; +{ + if (__ldso_entry == NULL || __ldso_version < LDSO_VERSION_HAS_DLADDR) + return 0; + return (__ldso_entry->dladdr)(addr, dlip); +} diff --git a/lib/csu/i386/dlopen.3 b/lib/libc/gen/dlopen.3 index b9a987c..b9a987c 100644 --- a/lib/csu/i386/dlopen.3 +++ b/lib/libc/gen/dlopen.3 |