diff options
Diffstat (limited to 'lib/csu')
-rw-r--r-- | lib/csu/i386/Makefile | 6 | ||||
-rw-r--r-- | lib/csu/i386/crt0.c | 136 | ||||
-rw-r--r-- | lib/csu/i386/dladdr.3 | 121 | ||||
-rw-r--r-- | lib/csu/i386/dlopen.3 | 236 |
4 files changed, 18 insertions, 481 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/csu/i386/dladdr.3 b/lib/csu/i386/dladdr.3 deleted file mode 100644 index 97af8ce..0000000 --- a/lib/csu/i386/dladdr.3 +++ /dev/null @@ -1,121 +0,0 @@ -.\" -.\" 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$ -.\" -.Dd February 5, 1998 -.Os FreeBSD -.Dt DLADDR 3 -.Sh NAME -.Nm dladdr -.Nd find the shared object containing a given address -.Sh SYNOPSIS -.Fd #include <dlfcn.h> -.Ft int -.Fn dladdr "const void *addr" "Dl_info *info" -.Sh DESCRIPTION -.Nm -queries the dynamic linker for information about the shared object -containing the address -.Fa addr . -The information is returned in the structure specified by -.Fa info . -The structure contains at least the following members: -.Bl -tag -width "XXXconst char *dli_fname" -.It Li "const char *dli_fname" -The pathname of the shared object containing the address. -.It Li "void *dli_fbase" -The base address at which the shared object is mapped into the -address space of the calling process. -.It Li "const char *dli_sname" -The name of the nearest run-time symbol with a value less than or -equal to -.Fa addr . -When possible, the symbol name is returned as it would appear in C -source code. -.Pp -If no symbol with a suitable value is found, both this field and -.Va dli_saddr -are set to -.Dv NULL . -.It Li "void *dli_saddr" -The value of the symbol returned in -.Li dli_sname . -.El -.Pp -.Nm -is available only in dynamically linked programs. -.Sh ERRORS -If a mapped shared object containing -.Fa addr -cannot be found, -.Nm -returns 0. -In that case, a message detailing the failure can be retrieved by -calling -.Fn dlerror . -.Pp -On success, a non-zero value is returned. -.Sh SEE ALSO -.Xr dlopen 3 , -.Xr rtld 1 -.Sh HISTORY -The -.Nm -function first appeared in the Solaris operating system. -.Sh BUGS -This implementation is bug-compatible with the Solaris -implementation. In particular, the following bugs are present: -.Bl -bullet -.It -If -.Fa addr -lies in the main executable rather than in a shared library, the -pathname returned in -.Va dli_fname -may not be correct. The pathname is taken directly from -.Va argv[0] -of the calling process. When executing a program specified by its -full pathname, most shells set -.Va argv[0] -to the pathname. But this is not required of shells or guaranteed -by the operating system. -.It -If -.Fa addr -is of the form -.Va &func , -where -.Va func -is a global function, its value may be an unpleasant surprise. In -dynamically linked programs, the address of a global function is -considered to point to its program linkage table entry, rather than to -the entry point of the function itself. This causes most global -functions to appear to be defined within the main executable, rather -than in the shared libraries where the actual code resides. -.It -Returning 0 as an indication of failure goes against long-standing -Unix tradition. -.El diff --git a/lib/csu/i386/dlopen.3 b/lib/csu/i386/dlopen.3 deleted file mode 100644 index b9a987c..0000000 --- a/lib/csu/i386/dlopen.3 +++ /dev/null @@ -1,236 +0,0 @@ -.\" This source code is a product of Sun Microsystems, Inc. and is provided -.\" for unrestricted use provided that this legend is included on all tape -.\" media and as a part of the software program in whole or part. Users -.\" may copy or modify this source code without charge, but are not authorized -.\" to license or distribute it to anyone else except as part of a product or -.\" program developed by the user. -.\" -.\" THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC. -.\" SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY -.\" OF SUCH SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT -.\" EXPRESS OR IMPLIED WARRANTY OF ANY KIND. SUN MICROSYSTEMS, INC. DISCLAIMS -.\" ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN -.\" NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT, -.\" INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING -.\" FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY. -.\" -.\" This source code is provided with no support and without any obligation on -.\" the part of Sun Microsystems, Inc. to assist in its use, correction, -.\" modification or enhancement. -.\" -.\" SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE -.\" INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS -.\" SOURCE CODE OR ANY PART THEREOF. -.\" -.\" Sun Microsystems, Inc. -.\" 2550 Garcia Avenue -.\" Mountain View, California 94043 -.\" -.\" Copyright (c) 1991 Sun Microsystems, Inc. -.\" -.\" @(#) dlopen.3 1.6 90/01/31 SMI -.Dd September 24, 1989 -.Os FreeBSD -.Dt DLOPEN 3 -.Sh NAME -.Nm dlopen, dlsym, dlerror, dlclose -.Nd programmatic interface to the dynamic linker -.Sh SYNOPSIS -.Fd #include <dlfcn.h> -.Ft void * -.Fn dlopen "const char *path" "int mode" -.Ft void * -.Fn dlsym "void *handle" "const char *symbol" -.Ft const char * -.Fn dlerror "void" -.Ft int -.Fn dlclose "void *handle" -.Sh DESCRIPTION -These functions provide a simple programmatic interface to the services of the -dynamic linker. -Operations are provided to add new shared objects to a -program's address space, to obtain the address bindings of symbols -defined by such -objects, and to remove such objects when their use is no longer required. -.Pp -.Fn dlopen -provides access to the shared object in -.Fa path , -returning a descriptor that can be used for later -references to the object in calls to -.Fn dlsym -and -.Fn dlclose . -If -.Fa path -was not in the address space prior to the call to -.Fn dlopen , -it is placed in the address space. -When an object is first loaded into the address space in this way, its -function -.Fn _init , -if any, is called by the dynamic linker. -(Note that -.Ql _init -is the name as expressed in the C language. -From assembly language, the name would appear as -.Ql __init -instead.) -If -.Fa path -has already been placed in the address space in a previous call to -.Fn dlopen , -it is not added a second time, although a reference count of -.Fn dlopen -operations on -.Fa path -is maintained. -A null pointer supplied for -.Fa path -is interpreted as a reference to the main -executable of the process. -.Fa mode -controls the way in which external function references from the -loaded object are bound to their referents. -It must contains one of the following values: -.Bl -tag -width RTLD_LAZYX -.It Dv RTLD_LAZY -Each external function reference is resolved when the function is first -called. -.It Dv RTLD_NOW -All external function references are bound immediately by -.Fn dlopen . -.El -.Pp -.Dv RTLD_LAZY -is normally preferred, for reasons of efficiency. -However, -.Dv RTLD_NOW -is useful to ensure that any undefined symbols are discovered during the -call to -.Fn dlopen . -If -.Fn dlopen -fails, it returns a null pointer, and sets an error condition which may -be interrogated with -.Fn dlerror . -.Pp -.Fn dlsym -returns the address binding of the symbol described in the null-terminated -character string -.Fa symbol , -as it occurs in the shared object identified by -.Fa handle . -Note that -.Fa symbol -is the assembly language representation of the symbol name. -The assembly language representation of a C language symbol contains an -extra underscore at the beginning. -For example, the symbol -.Ql foo -in C would appear as -.Ql _foo -in assembly language, and in the -.Fa symbol -argument to -.Fn dlsym . -The symbols exported by objects added to the address space by -.Fn dlopen -can be accessed only through calls to -.Fn dlsym . -Such symbols do not supersede any definition of those symbols already present -in the address space when the object is loaded, nor are they available to -satisfy normal dynamic linking references. -A null pointer supplied as the value of -.Fa handle -is interpreted as a reference to the executable from which the call to -.Fn dlsym -is being made. Thus a shared object can reference its own symbols. -.Fn dlsym -returns a null pointer if the symbol cannot be found, and sets an error -condition which may be queried with -.Fn dlerror . -.Pp -If -.Fn dlsym -is called with the special -.Fa handle -.Dv RTLD_NEXT , -then the search for the symbol is limited to the shared objects -which were loaded after the one issuing the call to -.Fn dlsym . -Thus, if the function is called from the main program, all -the shared libraries are searched. -If it is called from a shared library, all subsequent shared -libraries are searched. -.Dv RTLD_NEXT -is useful for implementing wrappers around library functions. -For example, a wrapper function -.Fn getpid -could access the -.Dq real -.Fn getpid -with -.Li dlsym(RTLD_NEXT, \&"_getpid\&") . -.Pp -.Fn dlerror -returns a null-terminated character string describing the last error that -occurred during a call to -.Fn dlopen , -.Fn dlsym , -or -.Fn dlclose . -If no such error has occurred, -.Fn dlerror -returns a null pointer. -At each call to -.Fn dlerror , -the error indication is reset. Thus in the case of two calls -to -.Fn dlerror , -where the second call follows the first immediately, the second call -will always return a null pointer. -.Pp -.Fn dlclose -deletes a reference to the shared object referenced by -.Fa handle . -If the reference count drops to 0, the object is removed from the -address space, and -.Fa handle -is rendered invalid. -Just before removing a shared object in this way, the dynamic linker -calls the object's -.Fn _fini -function, if such a function is defined by the object. -As with -.Ql _init , -.Ql _fini -is the C language name of the function. -If -.Fn dlclose -is successful, it returns a value of 0. -Otherwise it returns -1, and sets an error condition that can be -interrogated with -.Fn dlerror . -.Pp -The object-intrinsic functions -.Fn _init -and -.Fn _fini -are called with no arguments, and are not expected to return values. -.Sh ERRORS -.Fn dlopen -and -.Fn dlsym -return the null pointer in the event of errors. -.Fn dlclose -returns 0 on success, or -1 if an error occurred. -Whenever an error has been detected, a message detailing it can be -retrieved via a call to -.Fn dlerror . -.Sh SEE ALSO -.Xr ld 1 , -.Xr rtld 1 , -.Xr link 5 - |