mirror of
git://git.savannah.gnu.org/libtool.git
synced 2025-01-12 14:06:37 +08:00
388b7626dc
the many and varied m4 symbols accumulated by libtool over the years, considering also that modern autoconf can detect unexpanded macros even without AC in the macro name: * bootstrap: Remove libltdl/config.h from previous releases. * m4/libtool.m4, m4/ltdl.m4, doc/libtool.texi: Basically, run a giant sed transformation like this: s,AC_LIB_LTDL,LTDL_INIT,g s,AC_LIBLTDL_CONVENIENCE,LTDL_CONVENIENCE,g s,AC_LIBLTDL_INSTALLABLE,LTDL_INSTALLABLE,g s,AC_WITH_LTDL,LT_WITH_LTDL,g s,AC_LTDL_ENABLE_INSTALL,_LT_ENABLE_INSTALL,g s,AC_DEPLIBS_CHECK_METHOD,_LT_CHECK_MAGIC_METHOD,g s,AC_LIBTOOL_OBJDIR,_LT_CHECK_OBJDIR,g s,AC_LTDL_OBJDIR,_LT_CHECK_OBJDIR,g s,AC_LTDL_DLPREOPEN,_LT_CHECK_DLPREOPEN,g s,AC_LIBTOOL_SYS_MAX_CMD_LEN,LT_CMD_MAX_LEN,g s,AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE,_LT_CMD_GLOBAL_SYMBOLS,g s,AC_LIBTOOL_SYS_OLD_ARCHIVE,_LT_CMD_OLD_ARCHIVE,g s,AC_PROG_LD_RELOAD_FLAG,_LT_CMD_RELOAD,g s,AC_LIBTOOL_SYS_LIB_STRIP,_LT_CMD_STRIPLIB,g s,AC_CHECK_LIBM,LT_LIB_M,g s,AC_LTDL_DLLIB,LT_LIB_DLLOAD,g s,AC_LIBTOOL_COMPILER_OPTION,_LT_COMPILER_OPTION,g s,AC_LIBTOOL_PROG_CC_C_O,_LT_COMPILER_C_O,g s,AC_LIBTOOL_PROG_COMPILER_NO_RTTI,_LT_COMPILER_NO_RTTI,g s,AC_LIBTOOL_PROG_COMPILER_PIC,_LT_COMPILER_PIC,g s,AC_LIBTOOL_SYS_HARD_LINK_LOCKS,_LT_COMPILER_FILE_LOCKS,g s,AC_LTDL_DLSYM_USCORE,LT_FUNC_DLSYM_USCORE,g s,AC_LIBTOOL_LINKER_OPTION,_LT_LINKER_OPTION,g s,AC_LIBTOOL_PROG_LD_SHLIBS,_LT_LINKER_SHLIBS,g s,AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH,_LT_LINKER_HARDCODE_LIBPATH,g s,AC_PATH_MAGIC,_LT_PATH_MAGIC,g s,AC_PATH_TOOL_PREFIX,_LT_PATH_TOOL_PREFIX,g s,AC_PROG_LD,LT_PATH_LD,g s,AC_PROG_LD_GNU,_LT_PATH_LD_GNU,g s,AC_PROG_NM,LT_PATH_NM,g s,AC_LTDL_SYS_DLOPEN_DEPLIBS,LT_SYS_DLOPEN_DEPLIBS,g s,AC_LIBTOOL_DLOPEN_SELF,LT_SYS_DLOPEN_SELF,g s,AC_LIBTOOL_POSTDEP_PREDEP,_LT_SYS_HIDDEN_LIBDEPS,g s,AC_LTDL_SYSSEARCHPATH,LT_SYS_DLSEARCH_PATH,g s,AC_LTDL_SHLIBEXT,LT_SYS_MODULE_EXT,g s,AC_LTDL_SHLIBPATH,LT_SYS_MODULE_PATH,g s,AC_LTDL_SYMBOL_USCORE,LT_SYS_SYMBOL_USCORE,g s,AC_LIBTOOL_SYS_DYNAMIC_LINKER,_LT_SYS_DYNAMIC_LINKER,g s,_LT_AC_TAGVAR,_LT_TAGVAR,g s,_LT_AC_SYS_COMPILER,_LT_TAG_COMPILER,g s,_LT_AC_PROG_ECHO_BACKSLASH,_LT_PROG_ECHO_BACKSLASH,g s,_LT_AC_SYS_LIBPATH_AIX,_LT_SYS_MODULE_PATH_AIX,g s,_LT_AC_SHELL_INIT,_LT_SHELL_INIT,g s,_LT_AC_LOCK,_LT_ENABLE_LOCK,g s,_LT_AC_CHECK_DLFCN,_LT_HEADER_DLFCN,g s,_LT_AC_TRY_DLOPEN_SELF,_LT_TRY_DLOPEN_SELF,g s,LT_AC_PROG_EGREP,_LT_DECL_EGREP,g s,LT_AC_PROG_SED,_LT_DECL_SED,g * doc/libtool.texi (Autoconf macros): Document exported macros. * libtoolize.in: Compare ltdl.m4 serial numbers for LTDL_INIT instead of newly obsoleted AC_LIB_LTDL. (func_scan_files): Also set seen_ltdl for LTDL_INIT and LT_WITH_LTDL. * libltdl/ltdl.c (lt_dlforeachfile): LT_SYS_LIBSEARCH_PATH is not an environment variable, it is an actual path. Reported by Noah Mish <noah@cs.caltech.edu>
179 lines
4.7 KiB
C
179 lines
4.7 KiB
C
/* loader-dlopen.c -- dynamic linking with dlopen/dlsym
|
|
Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
|
|
Originally by Thomas Tanner <tanner@ffii.org>
|
|
|
|
NOTE: The canonical source of this file is maintained with the
|
|
GNU Libtool package. Report bugs to bug-libtool@gnu.org.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
As a special exception to the GNU Lesser General Public License,
|
|
if you distribute this file as part of a program or library that
|
|
is built using GNU libtool, you may include it under the same
|
|
distribution terms that you use for the rest of that program.
|
|
|
|
This library 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
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include "lt_dlloader.h"
|
|
#include "lt__private.h"
|
|
|
|
/* Use the preprocessor to rename non-static symbols to avoid namespace
|
|
collisions when the loader code is statically linked into libltdl.
|
|
Use the "<module_name>_LTX_" prefix so that the symbol addresses can
|
|
be fetched from the preloaded symbol list by lt_dlsym(): */
|
|
#define get_vtable dlopen_LTX_get_vtable
|
|
|
|
LT_SCOPE lt_dlvtable *get_vtable (lt_user_data loader_data);
|
|
|
|
|
|
/* Boilerplate code to set up the vtable for hooking this loader into
|
|
libltdl's loader list: */
|
|
static lt_module vm_open (lt_user_data loader_data, const char *filename);
|
|
static int vm_close (lt_user_data loader_data, lt_module module);
|
|
static void * vm_sym (lt_user_data loader_data, lt_module module,
|
|
const char *symbolname);
|
|
|
|
/* Return the vtable for this loader, only the name and sym_prefix
|
|
attributes (plus the virtual function implementations, obviously)
|
|
change between loaders. */
|
|
lt_dlvtable *
|
|
get_vtable (lt_user_data loader_data)
|
|
{
|
|
static lt_dlvtable *vtable = 0;
|
|
|
|
if (!vtable)
|
|
{
|
|
vtable = lt__zalloc (sizeof *vtable);
|
|
}
|
|
|
|
if (vtable && !vtable->name)
|
|
{
|
|
vtable->name = "lt_dlopen";
|
|
#if defined(DLSYM_USCORE)
|
|
vtable->sym_prefix = "_";
|
|
#endif
|
|
vtable->module_open = vm_open;
|
|
vtable->module_close = vm_close;
|
|
vtable->find_sym = vm_sym;
|
|
vtable->dlloader_data = loader_data;
|
|
vtable->priority = LT_DLLOADER_PREPEND;
|
|
}
|
|
|
|
if (vtable && (vtable->dlloader_data != loader_data))
|
|
{
|
|
LT__SETERROR (INIT_LOADER);
|
|
return 0;
|
|
}
|
|
|
|
return vtable;
|
|
}
|
|
|
|
|
|
|
|
/* --- IMPLEMENTATION --- */
|
|
|
|
|
|
#if defined(HAVE_DLFCN_H)
|
|
# include <dlfcn.h>
|
|
#endif
|
|
|
|
#if defined(HAVE_SYS_DL_H)
|
|
# include <sys/dl.h>
|
|
#endif
|
|
|
|
|
|
/* We may have to define LT_LAZY_OR_NOW in the command line if we
|
|
find out it does not work in some platform. */
|
|
#if !defined(LT_LAZY_OR_NOW)
|
|
# if defined(RTLD_LAZY)
|
|
# define LT_LAZY_OR_NOW RTLD_LAZY
|
|
# else
|
|
# if defined(DL_LAZY)
|
|
# define LT_LAZY_OR_NOW DL_LAZY
|
|
# endif
|
|
# endif /* !RTLD_LAZY */
|
|
#endif
|
|
#if !defined(LT_LAZY_OR_NOW)
|
|
# if defined(RTLD_NOW)
|
|
# define LT_LAZY_OR_NOW RTLD_NOW
|
|
# else
|
|
# if defined(DL_NOW)
|
|
# define LT_LAZY_OR_NOW DL_NOW
|
|
# endif
|
|
# endif /* !RTLD_NOW */
|
|
#endif
|
|
#if !defined(LT_LAZY_OR_NOW)
|
|
# define LT_LAZY_OR_NOW 0
|
|
#endif /* !LT_LAZY_OR_NOW */
|
|
|
|
#if defined(HAVE_DLERROR)
|
|
# define DLERROR(arg) dlerror ()
|
|
#else
|
|
# define DLERROR(arg) LT__STRERROR (arg)
|
|
#endif
|
|
|
|
#define DL__SETERROR(errorcode) \
|
|
LT__SETERRORSTR (DLERROR (errorcode))
|
|
|
|
/* A function called through the vtable to open a module with this
|
|
loader. Returns an opaque representation of the newly opened
|
|
module for processing with this loader's other vtable functions. */
|
|
static lt_module
|
|
vm_open (lt_user_data loader_data, const char *filename)
|
|
{
|
|
lt_module module = dlopen (filename, LT_LAZY_OR_NOW);
|
|
|
|
if (!module)
|
|
{
|
|
DL__SETERROR (CANNOT_OPEN);
|
|
}
|
|
|
|
return module;
|
|
}
|
|
|
|
|
|
/* A function called through the vtable when a particular module
|
|
should be unloaded. */
|
|
static int
|
|
vm_close (lt_user_data loader_data, lt_module module)
|
|
{
|
|
int errors = 0;
|
|
|
|
if (dlclose (module) != 0)
|
|
{
|
|
DL__SETERROR (CANNOT_CLOSE);
|
|
++errors;
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
|
|
/* A function called through the vtable to get the address of
|
|
a symbol loaded from a particular module. */
|
|
static void *
|
|
vm_sym (lt_user_data loader_data, lt_module module, const char *name)
|
|
{
|
|
void *address = dlsym (module, name);
|
|
|
|
if (!address)
|
|
{
|
|
DL__SETERROR (SYMBOL_NOT_FOUND);
|
|
}
|
|
|
|
return address;
|
|
}
|