2 * Written 3/1/94, Robert Sanders <Robert.Sanders@linux.org>
4 * based upon the file "dl.c", which is
5 * Copyright (c) 1994, Larry Wall
7 * You may distribute under the terms of either the GNU General Public
8 * License or the Artistic License, as specified in the README file.
10 * $Date: 1994/03/07 00:21:43 $
11 * $Source: /home/rsanders/src/perl5alpha6/RCS/dld_dl.c,v $
16 * Removed implicit link against libc. 1994/09/14 William Setzer.
18 * Integrated other DynaLoader changes. 1994/06/08 Tim Bunce.
20 * rewrote dl_load_file, misc updates. 1994/09/03 William Setzer.
22 * Revision 1.4 1994/03/07 00:21:43 rsanders
23 * added min symbol count for load_libs and switched order so system libs
24 * are loaded after app-specified libs.
26 * Revision 1.3 1994/03/05 01:17:26 rsanders
27 * added path searching.
29 * Revision 1.2 1994/03/05 00:52:39 rsanders
30 * added package-specified libraries.
32 * Revision 1.1 1994/03/05 00:33:40 rsanders
42 #include <dld.h> /* GNU DLD header file */
45 #include "dlutils.c" /* for SaveError() etc */
47 static AV *dl_resolve_using = Nullav;
48 static AV *dl_require_symbols = Nullav;
54 dl_generic_private_init();
55 dl_resolve_using = perl_get_av("DynaLoader::dl_resolve_using", 0x4);
56 dl_require_symbols = perl_get_av("DynaLoader::dl_require_symbols", 0x4);
58 dlderr = dld_init("/proc/self/exe");
61 dlderr = dld_init(dld_find_executable(PL_origargv[0]));
63 char *msg = dld_strerror(dlderr);
64 SaveError("dld_init(%s) failed: %s", PL_origargv[0], msg);
65 DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "%s", LastError));
73 MODULE = DynaLoader PACKAGE = DynaLoader
76 (void)dl_private_init();
80 dl_load_file(filename, flags=0)
88 DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dl_load_file(%s,%x):\n", filename,flags));
90 croak("Can't make loaded symbols global on this platform while loading %s",filename);
91 max = AvFILL(dl_require_symbols);
92 for (x = 0; x <= max; x++) {
93 char *sym = SvPVX(*av_fetch(dl_require_symbols, x, 0));
94 DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dld_create_ref(%s)\n", sym));
95 if (dlderr = dld_create_reference(sym)) {
96 SaveError("dld_create_reference(%s): %s", sym,
97 dld_strerror(dlderr));
102 DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dld_link(%s)\n", filename));
103 if (dlderr = dld_link(filename)) {
104 SaveError("dld_link(%s): %s", filename, dld_strerror(dlderr));
108 max = AvFILL(dl_resolve_using);
109 for (x = 0; x <= max; x++) {
110 char *sym = SvPVX(*av_fetch(dl_resolve_using, x, 0));
111 DLDEBUG(1,PerlIO_printf(PerlIO_stderr(), "dld_link(%s)\n", sym));
112 if (dlderr = dld_link(sym)) {
113 SaveError("dld_link(%s): %s", sym, dld_strerror(dlderr));
117 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "libref=%s\n", RETVAL));
119 ST(0) = sv_newmortal() ;
121 sv_setiv(ST(0), (IV)RETVAL);
125 dl_find_symbol(libhandle, symbolname)
129 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "dl_find_symbol(handle=%x, symbol=%s)\n",
130 libhandle, symbolname));
131 RETVAL = (void *)dld_get_func(symbolname);
132 /* if RETVAL==NULL we should try looking for a non-function symbol */
133 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), " symbolref = %x\n", RETVAL));
134 ST(0) = sv_newmortal() ;
136 SaveError("dl_find_symbol: Unable to find '%s' symbol", symbolname) ;
138 sv_setiv(ST(0), (IV)RETVAL);
144 if (dld_undefined_sym_count) {
146 char **undef_syms = dld_list_undefined_sym();
147 EXTEND(SP, dld_undefined_sym_count);
148 for (x=0; x < dld_undefined_sym_count; x++)
149 PUSHs(sv_2mortal(newSVpv(undef_syms[x]+1, 0)));
155 # These functions should not need changing on any platform:
158 dl_install_xsub(perl_name, symref, filename="$Package")
163 DLDEBUG(2,PerlIO_printf(PerlIO_stderr(), "dl_install_xsub(name=%s, symref=%x)\n",
165 ST(0)=sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)())symref, filename)));