mirror of
git://git.savannah.gnu.org/libtool.git
synced 2025-01-12 14:06:37 +08:00
* 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)
This commit is contained in:
parent
b5f5cb9c41
commit
c361d1cfeb
19
ChangeLog
19
ChangeLog
@ -1,3 +1,22 @@
|
||||
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,
|
||||
|
@ -2,17 +2,15 @@
|
||||
#
|
||||
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
|
||||
|
@ -36,8 +36,8 @@ main (argc,argv)
|
||||
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;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ typedef struct lt_dltype_t {
|
||||
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
|
||||
|
||||
@ -619,15 +619,8 @@ presym_open (handle, filename)
|
||||
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;
|
||||
|
||||
@ -681,14 +674,14 @@ static char *user_search_path = 0;
|
||||
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. */
|
||||
@ -739,7 +732,7 @@ int
|
||||
lt_dlexit ()
|
||||
{
|
||||
/* shut down libltdl */
|
||||
lt_dltype type = types;
|
||||
lt_dltype_t *type = types;
|
||||
int errors;
|
||||
|
||||
if (!initialized) {
|
||||
@ -772,7 +765,7 @@ tryall_dlopen (handle, filename)
|
||||
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 */
|
||||
@ -1055,13 +1048,11 @@ lt_dlopen (filename)
|
||||
}
|
||||
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) {
|
||||
@ -1221,6 +1212,7 @@ lt_dlopen (filename)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
register_handle:
|
||||
if (newhandle != handle) {
|
||||
lt_dlfree(handle);
|
||||
handle = newhandle;
|
||||
|
@ -41,11 +41,11 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#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>
|
||||
@ -78,8 +78,8 @@ extern const char *lt_dlgetsearchpath __P((void));
|
||||
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
|
||||
|
||||
|
30
libtool.m4
vendored
30
libtool.m4
vendored
@ -44,6 +44,8 @@ AC_SUBST(LIBTOOL)dnl
|
||||
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"
|
||||
@ -116,6 +118,34 @@ LIBTOOL_DEPS="$ac_aux_dir/ltconfig $ac_aux_dir/ltmain.sh"
|
||||
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
|
||||
|
14
ltconfig.in
14
ltconfig.in
@ -173,6 +173,8 @@ can_build_shared=yes
|
||||
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=
|
||||
@ -225,6 +227,8 @@ Generate a system-specific libtool script.
|
||||
--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]
|
||||
@ -253,6 +257,10 @@ EOM
|
||||
|
||||
--disable-static) enable_static=no ;;
|
||||
|
||||
--enable-dlopen) enable_dlopen=yes ;;
|
||||
|
||||
--enable-dlopen-self) enable_dlopen_self=yes ;;
|
||||
|
||||
--quiet | --silent) silent=yes ;;
|
||||
|
||||
--srcdir) prev=srcdir ;;
|
||||
@ -2062,6 +2070,12 @@ need_lib_prefix=$need_lib_prefix
|
||||
# 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
|
||||
|
||||
|
31
ltmain.in
31
ltmain.in
@ -939,7 +939,7 @@ compiler."
|
||||
# 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
|
||||
@ -1031,8 +1031,8 @@ compiler."
|
||||
# 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
|
||||
@ -2088,10 +2088,13 @@ EOF
|
||||
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
|
||||
@ -2130,7 +2133,7 @@ extern \"C\" {
|
||||
/* 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
|
||||
@ -2189,11 +2192,10 @@ lt_preloaded_symbols[] =
|
||||
{\
|
||||
"
|
||||
|
||||
# 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
|
||||
@ -2261,9 +2263,6 @@ static const void *lt_preloaded_setup() {
|
||||
# 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@%%"`
|
||||
|
@ -5,6 +5,7 @@ AM_INIT_AUTOMAKE(mdemo,0.1)
|
||||
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
|
||||
|
48
mdemo/main.c
48
mdemo/main.c
@ -78,6 +78,51 @@ test_dl (filename)
|
||||
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;
|
||||
@ -101,6 +146,9 @@ main (argc, argv)
|
||||
if (test_dl(argv[i]))
|
||||
return 1;
|
||||
|
||||
if (test_dlself())
|
||||
return 1;
|
||||
|
||||
lt_dlexit();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user