+1999-02-15 Thomas Tanner <tanner@gmx.de>
+
+ * cdemo/Makefile.am: renamed *foo1 to *foo, removed $(MATH_LIB)
+ * cdemo/foo1.c: renamed to foo.c
+ * libltdl/ltdl.c: eliminated lt_dltype, in presym_open():
+ search for @PROGRAM@ if filename == 0, in lt_dlopen():
+ fixed bug for filename == 0
+ * libltdl/ltdl.h: use __P macro for lt_dlmalloc/free
+ * libtool.m4: new macro AC_LIBTOOL_DLOPEN: checks for dlopen
+ and dlopen(NULL) support
+ * ltconfig.in: added new variables dlopen and dlopen_self,
+ --enable-dlopen[-self] flags for AC_LIBTOOL_DLOPEN
+ * ltmain.in: use dlopen[_self], dlpreopen files if there's no
+ dlopen support, build lt_preloaded_symbols only if
+ -dl[pre]open was used, include program symbols if -export-dynamic
+ was specified and there's no dlopen(NULL) support
+ * mdemo/configure.in: use AC_LIBTOOL_DLOPEN
+ * mdemo/main.c: demonstrate lt_dlopen(0)
+
1999-02-15 Gary V. Vaughan <gvaughan@oranda.demon.co.uk>
* demo/dlmain.c (_WIN32): The lt_symlist structure is now const,
#
AUTOMAKE_OPTIONS = no-dependencies foreign
-INCLUDES = -I$(srcdir)/../libltdl
-
EXTRA_DIST = acinclude.m4
-noinst_LTLIBRARIES = libfoo1.la
+noinst_LTLIBRARIES = libfoo.la
-libfoo1_la_SOURCES = foo1.c
+libfoo_la_SOURCES = foo.c
noinst_HEADERS = foo.h
bin_PROGRAMS = cdemo
cdemo_SOURCES = main.c
-cdemo_LDADD = libfoo1.la $(MATHLIB)
+cdemo_LDADD = libfoo.la
if (value == HELLO_RET)
printf("hello is ok!\n");
- if (foo1 () == FOO_RET)
- printf("foo1 is ok!\n");
+ if (foo () == FOO_RET)
+ printf("foo is ok!\n");
return 0;
}
int (*lib_open) __P((lt_dlhandle handle, const char *filename));
int (*lib_close) __P((lt_dlhandle handle));
lt_ptr_t (*find_sym) __P((lt_dlhandle handle, const char *symbol));
-} lt_dltype_t, *lt_dltype;
+} lt_dltype_t;
#define LTDL_TYPE_TOP 0
last_error = no_symbols_error;
return 1;
}
- if (!filename) {
- if (!default_preloaded_symbols) {
- last_error = file_not_found_error;
- return 1;
- } else {
- handle->handle = (lt_ptr_t) default_preloaded_symbols;
- return 0;
- }
- }
+ if (!filename)
+ filename = "@PROGRAM@";
while (lists) {
const lt_dlsymlist *syms = lists->syms;
static lt_dlhandle handles = 0;
static int initialized = 0;
-static lt_dltype types = LTDL_TYPE_TOP;
+static lt_dltype_t *types = LTDL_TYPE_TOP;
#undef LTDL_TYPE_TOP
int
lt_dlinit ()
{
/* initialize libltdl */
- lt_dltype *type = &types;
+ lt_dltype_t **type = &types;
int typecount = 0;
if (initialized) { /* Initialize only at first call. */
lt_dlexit ()
{
/* shut down libltdl */
- lt_dltype type = types;
+ lt_dltype_t *type = types;
int errors;
if (!initialized) {
const char *filename;
{
lt_dlhandle cur;
- lt_dltype type = types;
+ lt_dltype_t *type = types;
const char *saved_error = last_error;
/* check whether the module was already opened */
}
handle->usage = 0;
newhandle = handle;
- if (tryall_dlopen(handle, 0) != 0) {
+ if (tryall_dlopen(&handle, 0) != 0) {
lt_dlfree(newhandle);
return 0;
}
- if (newhandle != handle)
- lt_dlfree(newhandle);
- return handle;
+ goto register_handle;
}
basename = strrchr(filename, '/');
if (basename) {
return 0;
}
}
+register_handle:
if (newhandle != handle) {
lt_dlfree(handle);
handle = newhandle;
#undef __P
#undef lt_ptr_t
#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus)
-# define __P(protos) protos
-# define lt_ptr_t void*
+# define __P(protos) protos
+# define lt_ptr_t void*
#else
-# define __P(protos) ()
-# define lt_ptr_t char*
+# define __P(protos) ()
+# define lt_ptr_t char*
#endif
#include <stdlib.h>
extern const lt_dlsymlist lt_preloaded_symbols[];
#define LTDL_SET_PRELOADED_SYMBOLS() lt_dlpreload_default(lt_preloaded_symbols)
-extern lt_ptr_t (*lt_dlmalloc)(size_t size);
-extern void (*lt_dlfree)(lt_ptr_t ptr);
+extern lt_ptr_t (*lt_dlmalloc)__P((size_t size));
+extern void (*lt_dlfree)__P((lt_ptr_t ptr));
__END_DECLS
libtool_flags=
test "$enable_shared" = no && libtool_flags="$libtool_flags --disable-shared"
test "$enable_static" = no && libtool_flags="$libtool_flags --disable-static"
+test "x$lt_cv_dlopen" = xyes && libtool_flags="$libtool_flags --enable-dlopen"
+test "x$lt_cv_dlopen_self" = xyes && libtool_flags="$libtool_flags --enable-dlopen-self"
test "$silent" = yes && libtool_flags="$libtool_flags --silent"
test "$ac_cv_prog_gcc" = yes && libtool_flags="$libtool_flags --with-gcc"
test "$ac_cv_prog_gnu_ld" = yes && libtool_flags="$libtool_flags --with-gnu-ld"
exec 5>>./config.log
])
+# AC_LIBTOOL_DLOPEN - check for dlopen support
+AC_DEFUN(AC_LIBTOOL_DLOPEN,
+[AC_CACHE_VAL(lt_cv_dlopen,
+[lt_cv_dlopen=no
+AC_CHECK_LIB(dl, dlopen, lt_cv_dlopen=yes,
+ [AC_CHECK_FUNCS(dlopen, lt_cv_dlopen=yes,
+ [AC_CHECK_LIB(dld, dld_link, lt_cv_dlopen=yes,
+ [AC_CHECK_FUNCS(shl_load, lt_cv_dlopen=yes)]
+ )]
+ )]
+)])
+
+if test "$lt_cv_dlopen" = yes; then
+ AC_REQUIRE([AC_PROG_CC])dnl
+ AC_CACHE_VAL(lt_cv_dlopen_self,
+ [AC_CACHE_CHECK([whether a program can dlopen itself], lt_cv_dlopen_self,
+ [AC_TRY_RUN([
+#include <dlfcn.h>
+#include <stdio.h>
+fnord() { int i=42;}
+main() { void *self, *ptr1, *ptr2; self=dlopen(0,RTLD_LAZY);
+ if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord");
+ if(ptr1 || ptr2) exit(0); } exit(1); }
+], lt_cv_dlopen_self=no, lt_cv_dlopen_self=yes, lt_cv_dlopen_self=no)])
+ ])
+fi
+])
+
# AC_ENABLE_SHARED - implement the --enable-shared flag
# Usage: AC_ENABLE_SHARED[(DEFAULT)]
# Where DEFAULT is either `yes' or `no'. If omitted, it defaults to
enable_shared=yes
# All known linkers require a `.a' archive for static linking.
enable_static=yes
+enable_dlopen=no
+enable_dlopen_self=no
ltmain=
silent=
srcdir=
--debug enable verbose shell tracing
--disable-shared do not build shared libraries
--disable-static do not build static libraries
+ --enable-dlopen enable dlopen support
+ --enable-dlopen-self enable support for dlopening programs
--help display this help and exit
--no-verify do not verify that HOST is a valid host type
-o, --output=FILE specify the output file [default=$default_ofile]
--disable-static) enable_static=no ;;
+ --enable-dlopen) enable_dlopen=yes ;;
+
+ --enable-dlopen-self) enable_dlopen_self=yes ;;
+
--quiet | --silent) silent=yes ;;
--srcdir) prev=srcdir ;;
# Do we need a version for libraries?
need_version=$need_version
+# Whether dlopen is supported.
+dlopen=$enable_dlopen
+
+# Whether dlopen of programs is supported.
+dlopen_self=$enable_dlopen_self
+
# Compiler flag to prevent dynamic linking.
link_static_flag=$link_static_flag
# A library object.
if test "$prev" = dlfiles; then
dlfiles="$dlfiles $arg"
- if test "$build_libtool_libs" = yes; then
+ if test "$build_libtool_libs" = yes && test "$dlopen" = yes; then
prev=
continue
else
# This library was specified with -dlopen.
if test "$prev" = dlfiles; then
dlfiles="$dlfiles $arg"
- if test -z "$dlname" || test "$build_libtool_libs" = no; then
- # If there is no dlname or we're linking statically,
+ if test -z "$dlname" || test "$dlopen" = no || test "$build_libtool_libs" = no; then
+ # If there is no dlname, no dlopen support or we're linking statically,
# we need to preload.
prev=dlprefiles
else
finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
fi
- if test "$export_dynamic" = yes || test -n "$dlfiles$dlprefiles" && test -n "$NM" && test -n "$global_symbol_pipe"; then
- dlsyms="${outputname}S.c"
- else
- dlsyms=
+ dlsyms=
+ if test -n "$dlfiles$dlprefiles"; then
+ if test -n "$NM" && test -n "$global_symbol_pipe"; then
+ dlsyms="${outputname}S.c"
+ else
+ $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2
+ fi
fi
if test -n "$dlsyms"; then
/* External symbol declarations for the compiler. */\
"
- if test "$export_dynamic" = yes; then
+ if test "$export_dynamic" = yes && test "$dlopen_self" = no; then
if test -n "$export_symbols"; then
$run eval 'sed -e "s/^\(.*\)/\1 \1/" < "$export_symbols" > "$nlist"'
else
{\
"
- # First entry is always the program itself
- echo >> "$output_objdir/$dlsyms" "\
- {\"${output}\", (lt_ptr_t) 0},"
-
- if test "$export_dynamic" = yes; then
+ if test "$export_dynamic" = yes && test "$dlopen_self" = no; then
+ # First entry is the program itself
+ echo >> "$output_objdir/$dlsyms" "\
+ {\"@PROGRAM@\", (lt_ptr_t) 0},"
if test -n "$export_symbols"; then
sed 's/^\(.*\)/ {"\1", (lt_ptr_t) \&\1},/' < "$export_symbols" >> "$output_objdir/$dlsyms"
else
# We keep going just in case the user didn't refer to
# lt_preloaded_symbols. The linker will fail if global_symbol_pipe
# really was required.
- if test -n "$dlfiles$dlprefiles"; then
- $echo "$modename: not configured to extract global symbols from dlpreopened files" 1>&2
- fi
# Nullify the symbol file.
compile_command=`$echo "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
AC_PROG_CC
AC_C_CONST
AC_EXEEXT
+AC_LIBTOOL_DLOPEN
AM_PROG_LIBTOOL
if ${CONFIG_SHELL} ./libtool --features | grep "enable static" >/dev/null; then
return 0;
}
+int
+myfunc ()
+{
+ return HELLO_RET;
+}
+
+int myvar;
+
+int
+test_dlself ()
+{
+ lt_dlhandle handle;
+ int (*pmyfunc)() = 0;
+ int *pmyvar = 0;
+
+ handle = lt_dlopen(0);
+ if (!handle) {
+ fprintf (stderr, "can't dlopen the program!\n");
+ fprintf (stderr, "error was: %s\n", lt_dlerror());
+ return 1;
+ }
+ pmyfunc = (int(*)())lt_dlsym(handle, "myfunc");
+ pmyvar = (int*)lt_dlsym(handle, "myvar");
+
+ if (pmyfunc)
+ {
+ int value = (*pmyfunc) ();
+
+ printf ("myfunc returned: %i\n", value);
+ if (value == HELLO_RET)
+ printf("myfunc is ok!\n");
+ }
+ else
+ fprintf (stderr, "did not find the `myfunc' function\n");
+
+ /* Try assigning to the variable. */
+ if (pmyvar)
+ *pmyvar = 1;
+ else
+ fprintf (stderr, "did not find the `myvar' variable\n");
+
+ lt_dlclose(handle);
+ return 0;
+}
+
int
main (argc, argv)
int argc;
if (test_dl(argv[i]))
return 1;
+ if (test_dlself())
+ return 1;
+
lt_dlexit();
return 0;
}