home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sun4nl!cwi.nl!guido
- From: guido@cwi.nl (Guido van Rossum)
- Newsgroups: alt.sources
- Subject: dl-dld 1.1 (dynamic loading interface)
- Message-ID: <8476@charon.cwi.nl>
- Date: 29 Dec 92 13:03:37 GMT
- Sender: news@cwi.nl
- Lines: 915
-
- Archive-name: dl-dld/part01
- Submitted-by: Guido.van.Rossum@cwi.nl
- Version: 1.1
-
- Almost a year ago I posted version 1.0 of this little library, which
- mimics the interface of Jack Jansen's "dl" package (dynamic loading
- for the SGI) on top of Wilson Ho's (GNU) dynamic loading package
- "dld", version 3.2.3 (dynamic loading for several other systems).
-
- Version 1.1 adds two features that are new in Jack's dl:
- dl_setmessage() and dl_loadlod_mult(). I'd like to thank Martin-D.
- Lacasse for the latter contribution.
-
- (If you don't know where to get dld, try anonymous ftp to
- wuarchive.wustl.edu:/mirrors2/gnu/dld-3.2.3.tar.Z. Jack's dld can be
- found at ftp.cwi.nl:/pub/dl-1.5.tar.Z.)
-
- --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: MANIFEST Makefile README dl.h dl_error.c dl_findlibs.c
- # dl_getbinary.c dl_loadmod.c strerror.c test test/Makefile
- # test/sub.c test/sub.libs test/sub2.c test/test.c
- # Wrapped by guido@voorn.cwi.nl on Tue Dec 29 13:52:21 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(810 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1 This shipping list
- X Makefile 1 Build recipe
- X README 1 Explanation of what this is
- X dl.h 1 Interface header file
- X dl_error.c 1 Error interface
- X dl_findlibs.c 1 Function to read a ".libs" file
- X dl_getbinary.c 1 Function to turn argv[0] into a pathname
- X dl_loadmod.c 1 The main function
- X strerror.c 1 A PD re-implementation of ANSI C strerror()
- X test 1 Test program subdirectory
- X test/Makefile 1
- X test/sub.c 1
- X test/sub.libs 1
- X test/sub2.c 1
- X test/test.c 1
- END_OF_FILE
- if test 810 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(429 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# You may have to change this definition of where dld is...
- XDLD= ../dld-3.2.3
- XOBJS= dl_loadmod.o dl_getbinary.o dl_findlibs.o dl_error.o strerror.o
- XCFLAGS= -g -I$(DLD)
- XCC= gcc
- X
- Xlibdl.a: $(OBJS)
- X ar crv libdl.a $(OBJS)
- X ranlib libdl.a
- X
- X$(OBJS): dl.h
- Xdl_loadmod.o: $(DLD)/dld.h
- X
- Xclean::
- X -rm -f *.o core [,#@]* *~ *.orig *.old *.bak *.BAK \
- X nohup.out Part??
- X
- Xclobber:: clean
- X -rm -f lib*.a tags TAGS
- X
- Xkit::
- X makekit -m
- END_OF_FILE
- if test 429 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(1601 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XThis is dl-dld, a dynamic linking interface, version 1.1.
- X
- XDl-dld is a re-implementation of the high-level *interface* of Jack
- XJansen's "dl" dynamic loading package, on top of the *implementation*
- Xof Wilson Ho's (GNU) dynamic loading package "dld" (version 3.2.3).
- X
- XThis makes it possible to write programs with simple dynamic loading
- Xrequirements (just load a module and call a function from it; no
- Xunloading facilities) to run without source changes (using the dl
- Xinterface) on a larger number of platforms: using the original dl on
- XSGI MIPS machines (Irix 4.0), and using dl-dld on DEC VAX (Ultrix),
- XSun 3 (SunOS 3.4 and 4.0), Sparc (SunOS 4.0), Sequent Symmetry (Dynix)
- Xand Atari ST.
- X
- XVersion 1.1 adds the function dl_loadmod_mult(), which was added to dl,
- Xand fixes a tiny memory leak -- thanks to Martin-D. Lacasse for this
- Xcontribution.
- X
- XTo build dl-dld, edit the DLD path definition in the Makefile and type
- Xmake.
- X
- XTo use dl-dld, you must link with both ./libdl.a and (...)/libdld.a.
- XYou must also avoid sing shared libraries, as dld doesn't (yet)
- Xunderstand them. This is a price you have to pay to use dynamic
- Xloading. On SunOS, this boils down to linking with -Bstatic unless
- Xyou use gcc, since gcc also doesn't understand shared libraries.
- X
- XOf course, the low-level interface of Jack's dl package is not
- Ximplemented in dl-dld.
- X
- X(If you don't know where to get dld, try anonymous ftp to
- Xwuarchive.wustl.edu:/mirrors2/gnu/dld-3.2.3.tar.Z. Jack's dld can be
- Xfound at ftp.cwi.nl:/pub/dl-<version>.tar.Z, where <version> is
- Xcurrently 1.5.)
- X
- X--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
- END_OF_FILE
- if test 1601 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'dl.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dl.h'\"
- else
- echo shar: Extracting \"'dl.h'\" \(1979 characters\)
- sed "s/^X//" >'dl.h' <<'END_OF_FILE'
- X/***********************************************************
- XCopyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
- XNetherlands.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation, and that the names of Stichting Mathematisch
- XCentrum or CWI not be used in advertising or publicity pertaining to
- Xdistribution of the software without specific, written prior permission.
- X
- XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
- XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
- XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X/*
- X** Definitions of dl library modules.
- X*/
- X
- X#ifdef __STDC__
- X#define _PROTO(x) x
- X#else
- X#define _PROTO(x) ()
- X#endif
- X
- Xtypedef void dl_errortype _PROTO((char *));
- Xtypedef void (*dl_funcptr) _PROTO((void));
- X
- Xdl_funcptr dl_loadmod _PROTO((char *, char *, char *));
- Xvoid dl_error(); /* _PROTO((char *, int)); /* XXX Should use varargs/starg */
- Xvoid dl_message(); /* _PROTO((char *, int)); /* XXX Should use varargs/starg */
- Xextern dl_errortype dl_defaulterror; /* These are functions! */
- Xextern dl_errortype dl_defaultmessage;
- Xextern dl_errortype dl_nomessage;
- Xvoid dl_setmessage _PROTO((dl_errortype *));
- Xvoid dl_seterror _PROTO((dl_errortype *));
- X
- X/* Internal */
- Xchar *dl_findlibs _PROTO((char *));
- Xchar *dl_getbinaryname _PROTO((char *));
- X
- X#undef _PROTO
- END_OF_FILE
- if test 1979 -ne `wc -c <'dl.h'`; then
- echo shar: \"'dl.h'\" unpacked with wrong size!
- fi
- # end of 'dl.h'
- fi
- if test -f 'dl_error.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dl_error.c'\"
- else
- echo shar: Extracting \"'dl_error.c'\" \(2247 characters\)
- sed "s/^X//" >'dl_error.c' <<'END_OF_FILE'
- X/***********************************************************
- XCopyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
- XNetherlands.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation, and that the names of Stichting Mathematisch
- XCentrum or CWI not be used in advertising or publicity pertaining to
- Xdistribution of the software without specific, written prior permission.
- X
- XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
- XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
- XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X/*
- X** dl_error - dl error handling.
- X*/
- X
- X#include "dl.h"
- X#include <stdio.h>
- X
- Xdl_errortype *dl_ehptr = dl_defaulterror;
- Xdl_errortype *dl_mhptr = dl_defaultmessage;
- X
- Xvoid
- Xdl_seterror(eh)
- X dl_errortype *eh;
- X{
- X if ( eh == 0 )
- X dl_ehptr = dl_defaulterror;
- X else
- X dl_ehptr = eh;
- X}
- X
- Xvoid
- Xdl_defaulterror(str)
- X char *str;
- X{
- X fprintf(stderr, "%s\n", str);
- X}
- X
- Xvoid
- Xdl_error(fmt, arg)
- X char *fmt;
- X int arg;
- X{
- X char errbuf[512];
- X extern int errno;
- X
- X if ( fmt ) {
- X sprintf(errbuf, fmt, arg);
- X } else {
- X sprintf(errbuf, "libdl: %s: %s", arg, strerror(errno));
- X }
- X (*dl_ehptr)(errbuf);
- X}
- X
- Xvoid
- Xdl_setmessage(eh)
- X dl_errortype *eh;
- X{
- X if ( eh == 0 )
- X dl_ehptr = dl_defaultmessage;
- X else
- X dl_ehptr = eh;
- X}
- X
- Xvoid
- Xdl_defaultmessage(str)
- X char *str;
- X{
- X fprintf(stderr, "%s\n", str);
- X}
- X
- Xvoid
- Xdl_message(fmt, arg)
- X char *fmt;
- X int arg;
- X{
- X char msgbuf[512];
- X
- X sprintf(msgbuf, fmt, arg);
- X (*dl_mhptr)(msgbuf);
- X}
- X
- Xvoid
- Xdl_nomessage(str)
- X char *str;
- X{
- X}
- END_OF_FILE
- if test 2247 -ne `wc -c <'dl_error.c'`; then
- echo shar: \"'dl_error.c'\" unpacked with wrong size!
- fi
- # end of 'dl_error.c'
- fi
- if test -f 'dl_findlibs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dl_findlibs.c'\"
- else
- echo shar: Extracting \"'dl_findlibs.c'\" \(1813 characters\)
- sed "s/^X//" >'dl_findlibs.c' <<'END_OF_FILE'
- X/***********************************************************
- XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
- XNetherlands.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation, and that the names of Stichting Mathematisch
- XCentrum or CWI not be used in advertising or publicity pertaining to
- Xdistribution of the software without specific, written prior permission.
- X
- XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
- XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
- XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X/*
- X** dl_findlibs - Find optional ld libraries for module.
- X*/
- X#include "dl.h"
- X
- Xstatic char flbuf[1030];
- X
- Xchar *
- Xdl_findlibs(obj)
- X char *obj;
- X{
- X int fd, n;
- X
- X strncpy(flbuf, obj, 1024);
- X flbuf[1024] = 0;
- X if ( strncmp(flbuf+strlen(flbuf)-2, ".o", 2) == 0)
- X flbuf[strlen(flbuf)-2] = 0;
- X strcat(flbuf, ".libs");
- X if ((fd=open(flbuf, 0)) < 0 ) {
- X flbuf[0] = 0;
- X return flbuf;
- X }
- X n = read(fd, flbuf, 1024);
- X close(fd);
- X if ( n < 0 || n == 1024 )
- X return 0;
- X n--;
- X if ( flbuf[n] = '\n' )
- X n--;
- X flbuf[n+1] = 0;
- X return flbuf;
- X}
- X
- END_OF_FILE
- if test 1813 -ne `wc -c <'dl_findlibs.c'`; then
- echo shar: \"'dl_findlibs.c'\" unpacked with wrong size!
- fi
- # end of 'dl_findlibs.c'
- fi
- if test -f 'dl_getbinary.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dl_getbinary.c'\"
- else
- echo shar: Extracting \"'dl_getbinary.c'\" \(2270 characters\)
- sed "s/^X//" >'dl_getbinary.c' <<'END_OF_FILE'
- X/***********************************************************
- XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
- XNetherlands.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation, and that the names of Stichting Mathematisch
- XCentrum or CWI not be used in advertising or publicity pertaining to
- Xdistribution of the software without specific, written prior permission.
- X
- XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
- XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
- XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X/*
- X** dl_getbinaryname - Convert program name to full pathname.
- X*/
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X
- X#include "dl.h"
- X
- X#ifdef DEBUG
- X#define D(x) (x)
- X#else
- X#define D(x)
- X#endif
- X
- X/* Default path from sh(1) in Irix 4.0.1 */
- X#define DEF_PATH ":/usr/sbin:/usr/bsd:/bin:/usr/bin:/usr/bin/X11"
- X
- Xchar *
- Xdl_getbinaryname(argv0)
- X char *argv0;
- X{
- X char *p, *q;
- X char *path;
- X static char buf[1028];
- X int i;
- X struct stat st;
- X char *getenv();
- X
- X if (strchr(argv0, '/') != NULL) {
- X D(printf("binary includes slash: %s\n", argv0));
- X return argv0;
- X }
- X path = getenv("PATH");
- X if (path == NULL)
- X path = DEF_PATH;
- X p = q = path;
- X for (;;) {
- X while (*q && *q != ':')
- X q++;
- X i = q-p;
- X strncpy(buf, p, i);
- X if (q > p && q[-1] != '/')
- X buf[i++] = '/';
- X strcpy(buf+i, argv0);
- X if (stat(buf, &st) >= 0) {
- X if (S_ISREG(st.st_mode) &&
- X (st.st_mode & 0111)) {
- X D(printf("found binary: %s\n", buf));
- X return buf;
- X }
- X }
- X if (!*q)
- X break;
- X p = ++q;
- X }
- X D(printf("can't find binary: %s\n", argv0));
- X return argv0;
- X}
- END_OF_FILE
- if test 2270 -ne `wc -c <'dl_getbinary.c'`; then
- echo shar: \"'dl_getbinary.c'\" unpacked with wrong size!
- fi
- # end of 'dl_getbinary.c'
- fi
- if test -f 'dl_loadmod.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'dl_loadmod.c'\"
- else
- echo shar: Extracting \"'dl_loadmod.c'\" \(4978 characters\)
- sed "s/^X//" >'dl_loadmod.c' <<'END_OF_FILE'
- X/***********************************************************
- XCopyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
- XNetherlands.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation, and that the names of Stichting Mathematisch
- XCentrum or CWI not be used in advertising or publicity pertaining to
- Xdistribution of the software without specific, written prior permission.
- X
- XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
- XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
- XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X/*
- X** An emulation of Jack's dld interface on top of GNU's dld.
- X** This only works if the calling program is linked with -Bstatic (or gcc)!!!
- X*/
- X
- X#include "dl.h"
- X#include "dld.h"
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <nlist.h>
- X
- X#define D(x)
- X
- Xstatic int inited;
- X
- Xdl_funcptr
- Xdl_loadmod(thisfile, loadfile, entrypoint)
- X char *thisfile, *loadfile, *entrypoint;
- X{
- X int err;
- X char *libs;
- X dl_funcptr func;
- X
- X if (!inited) {
- X err = dld_init(dl_getbinaryname(thisfile));
- X if (err) {
- X dld_perror("Internal error");
- X dl_error("dl_loadmod: dld_init of %s failed", thisfile);
- X return 0;
- X }
- X inited = 1;
- X }
- X
- X D(fprintf(stderr, "calling dld_link(%s)\n", loadfile));
- X err = dld_link(loadfile);
- X if (err) {
- X dld_perror("Internal error");
- X dl_error("dl_loadmod: dld_link of %s failed", loadfile);
- X return 0;
- X }
- X
- X libs = dl_findlibs(loadfile);
- X if (libs) {
- X char *p, *q;
- X int i;
- X char buf[1024];
- X D(fprintf(stderr, "libs: '%s'\n", libs));
- X p = libs;
- X for (;;) {
- X while (*p && isspace(*p))
- X p++;
- X if (!*p)
- X break;
- X q = p;
- X while (*q && !isspace(*q))
- X q++;
- X i = q-p;
- X strncpy(buf, p, i);
- X buf[i] = '\0';
- X D(fprintf(stderr, "calling dld_link(%s)\n", buf));
- X err = dld_link(buf);
- X if (err && err != DLD_EUNDEFSYM) {
- X dld_perror("Internal error");
- X dl_error("dl_loadmod: dld_link of library %s failed", buf);
- X }
- X p = q;
- X }
- X }
- X
- X if (dld_undefined_sym_count) {
- X int i;
- X char **pp;
- X pp = dld_list_undefined_sym();
- X for (i = 0; i < dld_undefined_sym_count; i++) {
- X fprintf(stderr, "\t%s\n", pp[i]);
- X }
- X free(pp);
- X dl_error("dl_loadmod: %d undefined symbols remain",
- X dld_undefined_sym_count);
- X return 0;
- X }
- X
- X if (!dld_function_executable_p(entrypoint)) {
- X dl_error("dl_loadmod: function %s not executable", entrypoint);
- X }
- X
- X D(fprintf(stderr, "call dld_get_func(%s)\n", entrypoint));
- X func = (dl_funcptr) dld_get_func(entrypoint);
- X if (func == 0)
- X dl_error("dl_loadmod: function %s not found", entrypoint);
- X
- X return func;
- X}
- X
- Xint
- Xdl_loadmod_mult(thisfile, loadfile, nl)
- X char *thisfile, *loadfile;
- X struct nlist nl[];
- X{
- X int err, i, n;
- X char *libs;
- X dl_funcptr func;
- X
- X if (!inited) {
- X err = dld_init(dl_getbinaryname(thisfile));
- X if (err) {
- X dld_perror("Internal error");
- X dl_error("dl_loadmod_mult: dld_init of %s failed",
- X thisfile);
- X return 0;
- X }
- X inited = 1;
- X }
- X
- X D(fprintf(stderr, "calling dld_link(%s)\n", loadfile));
- X err = dld_link(loadfile);
- X if (err) {
- X dld_perror("Internal error");
- X dl_error("dl_loadmod_mult: dld_link of %s failed", loadfile);
- X return 0;
- X }
- X
- X libs = dl_findlibs(loadfile);
- X if (libs) {
- X char *p, *q;
- X int i;
- X char buf[1024];
- X D(fprintf(stderr, "libs: '%s'\n", libs));
- X p = libs;
- X for (;;) {
- X while (*p && isspace(*p))
- X p++;
- X if (!*p)
- X break;
- X q = p;
- X while (*q && !isspace(*q))
- X q++;
- X i = q-p;
- X strncpy(buf, p, i);
- X buf[i] = '\0';
- X D(fprintf(stderr, "calling dld_link(%s)\n", buf));
- X err = dld_link(buf);
- X if (err && err != DLD_EUNDEFSYM) {
- X dld_perror("Internal error");
- X dl_error("dl_loadmod_mult: dld_link of library %s failed", buf);
- X }
- X p = q;
- X }
- X }
- X
- X if (dld_undefined_sym_count) {
- X int i;
- X char **pp;
- X pp = dld_list_undefined_sym();
- X for (i = 0; i < dld_undefined_sym_count; i++) {
- X fprintf(stderr, "\t%s\n", pp[i]);
- X }
- X free(pp);
- X dl_error("dl_loadmod_mult: %d undefined symbols remain",
- X dld_undefined_sym_count);
- X return 0;
- X }
- X
- X for (i = n = 0; nl[i].n_name != 0; i++) {
- X if (!dld_function_executable_p(nl[i].n_name)) {
- X nl[i].n_value = 0;
- X nl[i].n_type = 0;
- X continue;
- X }
- X
- X D(fprintf(stderr, "call dld_get_func(%s)\n", nl[i].n_name));
- X nl[i].n_value = (unsigned long) dld_get_func(nl[i].n_name);
- X nl[i].n_type = 1;
- X n += (nl[i].n_value != 0);
- X }
- X return n;
- X}
- END_OF_FILE
- if test 4978 -ne `wc -c <'dl_loadmod.c'`; then
- echo shar: \"'dl_loadmod.c'\" unpacked with wrong size!
- fi
- # end of 'dl_loadmod.c'
- fi
- if test -f 'strerror.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'strerror.c'\"
- else
- echo shar: Extracting \"'strerror.c'\" \(1672 characters\)
- sed "s/^X//" >'strerror.c' <<'END_OF_FILE'
- X/***********************************************************
- XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
- XNetherlands.
- X
- X All Rights Reserved
- X
- XPermission to use, copy, modify, and distribute this software and its
- Xdocumentation for any purpose and without fee is hereby granted,
- Xprovided that the above copyright notice appear in all copies and that
- Xboth that copyright notice and this permission notice appear in
- Xsupporting documentation, and that the names of Stichting Mathematisch
- XCentrum or CWI not be used in advertising or publicity pertaining to
- Xdistribution of the software without specific, written prior permission.
- X
- XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
- XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
- XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
- XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X
- X******************************************************************/
- X
- X/* PD implementation of strerror() for systems that don't have it.
- X Author: Guido van Rossum, CWI Amsterdam, Oct. 1990, <guido@cwi.nl>. */
- X
- X#include <stdio.h>
- X
- Xextern int sys_nerr;
- Xextern char *sys_errlist[];
- X
- Xchar *
- Xstrerror(err)
- X int err;
- X{
- X static char buf[20];
- X if (err >= 0 && err < sys_nerr)
- X return sys_errlist[err];
- X sprintf(buf, "Unknown errno %d", err);
- X return buf;
- X}
- X
- X#ifdef THINK_C
- Xint sys_nerr = 0;
- Xchar *sys_errlist[1] = 0;
- X#endif
- END_OF_FILE
- if test 1672 -ne `wc -c <'strerror.c'`; then
- echo shar: \"'strerror.c'\" unpacked with wrong size!
- fi
- # end of 'strerror.c'
- fi
- if test ! -d 'test' ; then
- echo shar: Creating directory \"'test'\"
- mkdir 'test'
- fi
- if test -f 'test/Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'test/Makefile'\"
- else
- echo shar: Extracting \"'test/Makefile'\" \(508 characters\)
- sed "s/^X//" >'test/Makefile' <<'END_OF_FILE'
- X# You may have to change this definition of where dld is...
- XDLD= ../../dld-3.2.3
- XDL= ..
- XCFLAGS= -g -I$(DL)
- XLIBS= $(DL)/libdl.a $(DLD)/libdld.a
- XCC= gcc
- X
- Xtest: test.o $(LIBS) sub.o sub2.o
- X $(CC) test.o $(LIBS) -o test
- X
- Xsub.o: sub.c
- X $(CC) -c sub.c -o sub.o
- X
- Xsub2.o: sub2.c
- X $(CC) -c sub2.c -o sub2.o
- X
- X$(DL)/libdl.a::
- X (cd $(DL); make)
- X
- X$(DLD)/libdld.a::
- X (cd $(DLD); make)
- X
- Xclean::
- X -rm -f *.o core [,#@]* *~ *.orig *.old *.bak *.BAK \
- X nohup.out Part?? *.ld
- X
- Xclobber:: clean
- X -rm -f lib*.a tags TAGS test
- END_OF_FILE
- if test 508 -ne `wc -c <'test/Makefile'`; then
- echo shar: \"'test/Makefile'\" unpacked with wrong size!
- fi
- # end of 'test/Makefile'
- fi
- if test -f 'test/sub.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'test/sub.c'\"
- else
- echo shar: Extracting \"'test/sub.c'\" \(308 characters\)
- sed "s/^X//" >'test/sub.c' <<'END_OF_FILE'
- X
- Xint i;
- Xint j = 2;
- X
- Xsub1() {
- X printf("sub1: called %f\n", 0.123);
- X}
- X
- Xsub2() {
- X printf("sub2: calling mainsub\n");
- X submain();
- X printf("sub2: returngin\n");
- X}
- X
- Xsub3() {
- X double sin();
- X
- X printf("Sub3: called. Attempt sin(3.1415):\n");
- X printf("sin(%f) = %f\n", 3.1415, sin(3.1415));
- X}
- END_OF_FILE
- if test 308 -ne `wc -c <'test/sub.c'`; then
- echo shar: \"'test/sub.c'\" unpacked with wrong size!
- fi
- # end of 'test/sub.c'
- fi
- if test -f 'test/sub.libs' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'test/sub.libs'\"
- else
- echo shar: Extracting \"'test/sub.libs'\" \(32 characters\)
- sed "s/^X//" >'test/sub.libs' <<'END_OF_FILE'
- X/usr/lib/libm.a /usr/lib/libc.a
- END_OF_FILE
- if test 32 -ne `wc -c <'test/sub.libs'`; then
- echo shar: \"'test/sub.libs'\" unpacked with wrong size!
- fi
- # end of 'test/sub.libs'
- fi
- if test -f 'test/sub2.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'test/sub2.c'\"
- else
- echo shar: Extracting \"'test/sub2.c'\" \(185 characters\)
- sed "s/^X//" >'test/sub2.c' <<'END_OF_FILE'
- X
- Xint i;
- Xint j = 2;
- X
- Xsub1() {
- X printf("sub2-sub1: called %f\n", 0.456);
- X}
- X
- Xsub2() {
- X printf("sub2-sub2: calling mainsub\n");
- X submain();
- X printf("sub2-sub2: returning\n");
- X}
- END_OF_FILE
- if test 185 -ne `wc -c <'test/sub2.c'`; then
- echo shar: \"'test/sub2.c'\" unpacked with wrong size!
- fi
- # end of 'test/sub2.c'
- fi
- if test -f 'test/test.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'test/test.c'\"
- else
- echo shar: Extracting \"'test/test.c'\" \(721 characters\)
- sed "s/^X//" >'test/test.c' <<'END_OF_FILE'
- X/*
- X** Test.c - Test shared library
- X*/
- X#include <stdio.h>
- X
- X#include "dl.h"
- X
- Xmain(argc, argv)
- X int argc;
- X char **argv;
- X{
- X dl_funcptr sub1, sub2;
- X
- X printf("main: load function %s from %s\n", argv[2], argv[1]);
- X sub1 = dl_loadmod(argv[0], argv[1], argv[2]);
- X if ( sub1 == 0 ) {
- X exit(1);
- X }
- X if ( argc >= 5 ) {
- X printf("main: load function %s from %s\n", argv[4], argv[3]);
- X sub2 = dl_loadmod(argv[0], argv[3], argv[4]);
- X if ( sub2 == 0 ) {
- X exit(1);
- X }
- X }
- X printf("main: calling %s\n", argv[2]);
- X (*sub1)();
- X if ( argc == 5 ) {
- X printf("main: calling %s\n", argv[4]);
- X (*sub2)();
- X }
- X printf("main: all done\n");
- X}
- X
- Xsubmain() {
- X printf("submain: called\n");
- X}
- END_OF_FILE
- if test 721 -ne `wc -c <'test/test.c'`; then
- echo shar: \"'test/test.c'\" unpacked with wrong size!
- fi
- # end of 'test/test.c'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-