Index: Emacs/src/Makefile.in diff -u Emacs/src/Makefile.in:1.1.1.12 Emacs/src/Makefile.in:1.16 --- Emacs/src/Makefile.in:1.1.1.12 Wed May 12 14:13:10 1999 +++ Emacs/src/Makefile.in Wed May 12 20:45:05 1999 @@ -382,6 +382,13 @@ #endif /* not HAVE_X11 */ #endif /* not HAVE_X_WINDOWS */ + +#ifdef HAVE_DYNAMIC_LOADER +#ifndef NO_LIBDL /* don't have libdl.*, but have dlopen */ +LIBDL = -ldl +#endif +#endif + #ifndef ORDINARY_LINK /* Fix linking if compiled with GCC. */ #ifdef __GNUC__ @@ -402,8 +409,23 @@ ask GCC explicitly where to find libgcc.a. */ #ifndef LINKER +#ifdef HAVE_DYNAMIC_LOADER +prefix=@prefix@ +exec_prefix=@exec_prefix@ +version=@version@ +configuration="@configuration@" + +libexecdir=${exec_prefix}/libexec +archlibdir=${libexecdir}/emacs/${version}/${configuration} +#ifdef __FreeBSD__ +#define LINKER $(CC) -nostdlib -Wl,-R${archlibdir} +#else +#define LINKER $(CC) -nostdlib -rdynamic -Wl,-rpath,${archlibdir} +#endif +#else #define LINKER $(CC) -nostdlib #endif +#endif #ifndef LIB_GCC /* Ask GCC where to find libgcc.a. */ @@ -506,6 +528,11 @@ #define MSDOS_OBJ #endif +#ifdef HAVE_DYNAMIC_LOADER +#define DYNL_OBJ dynl.o +#else +#define DYNL_OBJ +#endif /* lastfile must follow all files whose initialized data areas should be dumped as pure by dump-emacs. */ @@ -521,7 +548,7 @@ abbrev.o syntax.o UNEXEC mocklisp.o bytecode.o \ process.o callproc.o \ region-cache.o \ - doprnt.o strftime.o MKTIME_OBJ GETLOADAVG_OBJ MSDOS_OBJ + doprnt.o strftime.o MKTIME_OBJ GETLOADAVG_OBJ MSDOS_OBJ DYNL_OBJ /* Object files used on some machine or other. These go in the DOC file on all machines @@ -786,7 +813,7 @@ Note that SunOS needs -lm to come before -lc; otherwise, you get duplicated symbols. If the standard libraries were compiled with GCC, we might need gnulib again after them. */ -LIBES = $(LOADLIBES) $(LDLIBS) $(LIBX) LIBS_SYSTEM LIBS_MACHINE LIBS_TERMCAP \ +LIBES = $(LOADLIBES) $(LDLIBS) $(LIBX) $(LIBDL) LIBS_SYSTEM LIBS_MACHINE LIBS_TERMCAP \ LIBS_DEBUG $(GNULIB_VAR) LIB_MATH LIB_STANDARD $(GNULIB_VAR) /* Enable recompilation of certain other files depending on system type. */ Index: Emacs/src/dynl-dl.c diff -u /dev/null Emacs/src/dynl-dl.c:1.1.2.2 --- /dev/null Thu Sep 16 00:21:08 1999 +++ Emacs/src/dynl-dl.c Wed Aug 25 16:27:19 1999 @@ -0,0 +1,114 @@ +/* dynl-dl.c - dynamic linking for dlopen/dlsym + * + * Copyright (C) 1990-1997 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + * As a special exception, the Free Software Foundation gives permission + * for additional uses of the text contained in its release of GUILE. + * + * The exception is that, if you link the GUILE library with other files + * to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the GUILE library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the + * Free Software Foundation under the name GUILE. If you copy + * code from other Free Software Foundation releases into a copy of + * GUILE, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for GUILE, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + */ + +/* "dynl.c" dynamically link&load object files. + Author: Aubrey Jaffer + Modified for libguile by Marius Vollmer */ + +#include + +#ifdef RTLD_LAZY /* Solaris 2. */ +# define DLOPEN_MODE RTLD_LAZY +#else +# define DLOPEN_MODE 1 /* Thats what it says in the man page. */ +#endif + +static void * +sysdep_dynl_link (fname, subr) + char *fname; + char *subr; +{ + void *handle = dlopen (fname, DLOPEN_MODE); + if (NULL == handle) + scm_misc_error (subr, (char *)dlerror (), SCM_EOL); + return handle; +} + +static void +sysdep_dynl_unlink (handle, subr) + void *handle; + char *subr; +{ + int status; + + SCM_DEFER_INTS; + status = dlclose (handle); + SCM_ALLOW_INTS; + if(status) + scm_misc_error (subr, (char *)dlerror (), SCM_EOL); +} + +static void * +sysdep_dynl_func (symb, handle, subr) + char *symb; + void *handle; + char *subr; +{ + void *fptr; + char *err; +#if defined(NEEDS_USCORE) + char *usymb; +#endif + + SCM_DEFER_INTS; +#if defined(NEEDS_USCORE) + usymb = (char *) malloc (strlen (symb) + 2); + *usymb = '_'; + strcpy (usymb + 1, symb); + fptr = dlsym (handle, usymb); + free (usymb); +#else + fptr = dlsym (handle, symb); +#endif + err = (char *)dlerror (); + SCM_ALLOW_INTS; + + if (!fptr) + scm_misc_error (subr, err? err : "symbol has NULL address", SCM_EOL); + return fptr; +} + +static void +sysdep_dynl_init () +{ +} Index: Emacs/src/dynl-dld.c diff -u /dev/null Emacs/src/dynl-dld.c:1.1.2.1 --- /dev/null Thu Sep 16 00:21:08 1999 +++ Emacs/src/dynl-dld.c Mon Apr 6 04:11:10 1998 @@ -0,0 +1,128 @@ +/* dynl-dld.c - dynamic linking with dld + * + * Copyright (C) 1990-1997 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + * As a special exception, the Free Software Foundation gives permission + * for additional uses of the text contained in its release of GUILE. + * + * The exception is that, if you link the GUILE library with other files + * to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the GUILE library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the + * Free Software Foundation under the name GUILE. If you copy + * code from other Free Software Foundation releases into a copy of + * GUILE, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for GUILE, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + */ + +/* "dynl.c" dynamically link&load object files. + Author: Aubrey Jaffer + Modified for libguile by Marius Vollmer */ + +#include "dld.h" + +static void listundef SCM_P ((void)); + +static void +listundefs () +{ + int i; + char **undefs = dld_list_undefined_sym(); + puts(" undefs:"); + for(i = dld_undefined_sym_count;i--;) { + putc('"', stdout); + fputs(undefs[i], stdout); + puts("\""); + } + free(undefs); +} + +static void * +sysdep_dynl_link (fname, subr) + char *fname; + char *subr; +{ + int status; + + status = dld_link (fname); + if (status) + scm_misc_error (subr, dld_strerror (status), SCM_EOL); + return fname; +} + +static void +sysdep_dynl_unlink (handle, subr) + void *handle; + char *subr; +{ + int status; + + SCM_DEFER_INTS; + status = dld_unlink_by_file ((char *)fname, 1); + SCM_ALLOW_INTS; + if (status) + scm_misc_error (s_dynamic_unlink, dld_strerror (status), SCM_EOL); +} + +static void * +sysdep_dynl_func (symb, handle, subr) + char *symb; + void *handle; + char *subr; +{ + void *func; + + SCM_DEFER_INTS; + func = (void *) dld_get_func (func); + if (func == 0) + scm_misc_error (subr, dld_strerror (dld_errno), SCM_EOL); + if (!dld_function_executable_p (func)) { + listundefs (); + scm_misc_error (subr, "unresolved symbols remain", SCM_EOL); + } + SCM_ALLOW_INTS; + return func; +} + +static void +sysdep_dynl_init () +{ +#ifndef RTL + if (!execpath) + execpath = dld_find_executable (SCM_CHARS (SCM_CAR (progargs))); + if (dld_init (SCM_CHARS (SCM_CAR (progargs)))) { + dld_perror("DLD"); + return; + } +#endif + +#ifdef DLD_DYNCM /* XXX - what's this? */ + add_feature("dld:dyncm"); +#endif +} Index: Emacs/src/dynl.c diff -u /dev/null Emacs/src/dynl.c:1.1.2.1 --- /dev/null Thu Sep 16 00:21:09 1999 +++ Emacs/src/dynl.c Mon Apr 6 04:11:12 1998 @@ -0,0 +1,177 @@ +/* Simple implementation of C object dynamic link + + Modified: Take Guile's approach which is done by: + Author: Aubrey Jaffer + Modified for libguile by Marius Vollmer + + TODO: implement (argc, argv) call + */ + +#include +#include +#include +#include +#include +#include +#include "lisp.h" + +#define MAX_DL 256 +static void *handle_table[MAX_DL]; +static int current_dls; + +#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) +#undef __P +#define __P(args) args +#else /* Not C++ or ANSI C. */ +#undef __P +#define __P(args) () +#endif /* C++ or ANSI C. */ + +static void *sysdep_dynl_link __P ((char *__fname, char *__errmsg)); +static void *sysdep_dynl_func __P ((char *__fname, void * __handle, char *__errmsg)); +static void sysdep_dynl_unlink __P ((void * __handle, char *__errmsg)); + +#define scm_misc_error error +#define SCM_EOL "\n" +#define SCM_DEFER_INTS do {} while(0) +#define SCM_ALLOW_INTS do {} while(0) +#define SCM_P __P + +#ifdef HAVE_LIBDL +#include "dynl-dl.c" +#else +#ifdef HAVE_SHL_LOAD +#include "dynl-shl.c" +#else +#ifdef HAVE_DLD +#include "dynl-dld.c" +#else + +/* no dynamic linking available, throw errors. */ + +static void +sysdep_dynl_init () +{ +} + +static void +no_dynl_error (errmsg) + char *errmsg; +{ + error (errmsg, "dynamic linking not available"); +} + +static void * +sysdep_dynl_link (filename, errmsg) + char *filename; + char *errmsg; +{ + no_dynl_error (errmsg); + return NULL; +} + +static void +sysdep_dynl_unlink (handle, errmsg) + void *handle; + char *errmsg; +{ + no_dynl_error (errmsg); +} + +static void * +sysdep_dynl_func (symbol, handle, errmsg) + char *symbol; + void *handle; + char *errmsg; +{ + no_dynl_error (errmsg); + return NULL; +} +#endif +#endif +#endif + + +DEFUN ("dynamic-link", Fdynamic_link, Sdynamic_link, 1, 1, 0, + "Dynamic link the code.") + (name) + Lisp_Object name; +{ + Lisp_Object h; + void *handle; + int i; + + if (current_dls > MAX_DL) + error ("Too many dynamic libraries."); + + CHECK_STRING (name, 0); + handle = sysdep_dynl_link (XSTRING (name)->data, "dynamic-link"); + + current_dls++; + for (i=0; i < MAX_DL; i++) + if (handle_table[i] == NULL) + { + handle_table[i] = handle; + break; + } + + XSETFASTINT (h, i); + return h; +} + +DEFUN ("dynamic-call", Fdynamic_call, Sdynamic_call, 2, 2, 0, + "Dynamic call for FUNCTION which is referenced by HANDLE with no argument.") + (f, h) + Lisp_Object f, h; +{ + void *handle; + char *func_name; + int i; + void (*fptr)(); + + CHECK_STRING (f, 0); + func_name = XSTRING (f)->data; + CHECK_NUMBER (h, 1); + i = XFASTINT (h); + handle = handle_table[i]; + + fptr = (void (*)())sysdep_dynl_func (func_name, handle, "dynamic-call"); + (*fptr) (); + return Qnil; +} + +DEFUN ("dynamic-unlink", Fdynamic_unlink, Sdynamic_unlink, 1, 1, 0, + "Dynamic unlink the code.") + (h) + Lisp_Object h; +{ + void *handle; + int i; + + CHECK_NUMBER (h, 0); + i = XFASTINT (h); + handle = handle_table[i]; + + sysdep_dynl_unlink (handle, "dynamic-unlink"); + current_dls--; + handle_table[i] = NULL; + return Qnil; +} + +void +undefsubr (sname) + struct Lisp_Subr *sname; +{ + Lisp_Object sym; + sym = intern (sname->symbol_name); + XSYMBOL (sym)->function = Qunbound; +} + +void +syms_of_dynl () +{ + defsubr (&Sdynamic_link); + defsubr (&Sdynamic_call); + defsubr (&Sdynamic_unlink); + sysdep_dynl_init (); +} Index: Emacs/src/emacs.c diff -u Emacs/src/emacs.c:1.1.1.16 Emacs/src/emacs.c:1.18 --- Emacs/src/emacs.c:1.1.1.16 Mon Jul 19 14:05:17 1999 +++ Emacs/src/emacs.c Mon Jul 19 17:13:44 1999 @@ -1247,6 +1247,10 @@ SYMS_MACHINE; #endif +#ifdef HAVE_DYNAMIC_LOADER + syms_of_dynl (); +#endif + keys_of_casefiddle (); keys_of_cmds (); keys_of_buffer (); Index: Emacs/src/s/bsdos4.h diff -u Emacs/src/s/bsdos4.h:1.1.1.1 Emacs/src/s/bsdos4.h:1.1.2.2 --- Emacs/src/s/bsdos4.h:1.1.1.1 Wed Dec 2 22:19:04 1998 +++ Emacs/src/s/bsdos4.h Wed Sep 15 22:56:36 1999 @@ -14,4 +14,7 @@ #undef LIB_GCC #define LIB_GCC +#define HAVE_DYNAMIC_LOADER +#define HAVE_LIBDL + #endif /* not __ELF__ */ Index: Emacs/src/s/freebsd.h diff -u Emacs/src/s/freebsd.h:1.1.1.3 Emacs/src/s/freebsd.h:1.3 --- Emacs/src/s/freebsd.h:1.1.1.3 Wed May 12 14:13:19 1999 +++ Emacs/src/s/freebsd.h Wed May 12 20:45:08 1999 @@ -111,6 +111,12 @@ #define BSD_SYSTEM 199506 #endif +#if __FreeBSD__ >= 2 +#define HAVE_DYNAMIC_LOADER +#define NO_LIBDL /* FreeBSD doesn't have libdl.* */ +#define HAVE_LIBDL /* But has dlopen */ +#endif /* __FreeBSD__ >= 2 */ + #define WAITTYPE int /* get this since it won't be included if WAITTYPE is defined */ #ifdef emacs Index: Emacs/src/s/gnu-linux.h diff -u Emacs/src/s/gnu-linux.h:1.1.1.4 Emacs/src/s/gnu-linux.h:1.7 --- Emacs/src/s/gnu-linux.h:1.1.1.4 Wed Jan 6 22:50:04 1999 +++ Emacs/src/s/gnu-linux.h Tue Jan 12 03:00:12 1999 @@ -168,6 +168,9 @@ #else #define LD_SWITCH_SYSTEM LD_SWITCH_X_SITE_AUX #endif /* __mips__ */ + +#define HAVE_DYNAMIC_LOADER +#define HAVE_LIBDL #endif /* __ELF__ */ /* As of version 1.1.51, Linux did not actually implement SIGIO. Index: Emacs/src/s/netbsd.h diff -u Emacs/src/s/netbsd.h:1.1.1.2 Emacs/src/s/netbsd.h:1.3 --- Emacs/src/s/netbsd.h:1.1.1.2 Sun Apr 26 03:59:30 1998 +++ Emacs/src/s/netbsd.h Wed Aug 25 16:27:33 1999 @@ -79,3 +79,8 @@ this problem, and will also work on earlier NetBSD releases */ #define LINKER $(CC) -nostartfiles + +#define HAVE_DYNAMIC_LOADER +#define NO_LIBDL +#define HAVE_LIBDL +#define NEEDS_USCORE Index: Emacs/src/s/sol2-5.h diff -u Emacs/src/s/sol2-5.h:1.1.1.3 Emacs/src/s/sol2-5.h:1.4 --- Emacs/src/s/sol2-5.h:1.1.1.3 Wed Apr 8 23:10:24 1998 +++ Emacs/src/s/sol2-5.h Wed Apr 28 21:21:56 1999 @@ -12,6 +12,9 @@ after deleting a frame. */ #define SYSTEM_MALLOC +#define HAVE_DYNAMIC_LOADER +#define HAVE_LIBDL + #if 0 /* A recent patch in unexelf.c should eliminate the need for this. */ /* Don't use the shared libraries for -lXt and -lXaw, to work around a linker bug in Solaris 2.5. Index: Emacs/src/s/sunos4shr.h diff -u Emacs/src/s/sunos4shr.h:1.1.1.2 Emacs/src/s/sunos4shr.h:1.5 --- Emacs/src/s/sunos4shr.h:1.1.1.2 Thu May 7 23:17:41 1998 +++ Emacs/src/s/sunos4shr.h Mon May 11 20:56:02 1998 @@ -46,6 +46,9 @@ #undef USE_DL_STUBS +#define HAVE_DYNAMIC_LOADER +#define HAVE_LIBDL + #ifndef HAVE_X11R6 /* With X11R5 it was reported that linking -lXmu dynamically did not work. With X11R6, it does work; and since normally