mirror of
git://git.savannah.gnu.org/libtool.git
synced 2024-11-27 06:09:57 +08:00
5451db06bd
`loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
141 lines
3.9 KiB
C
141 lines
3.9 KiB
C
/* loader-dld_link.c -- dynamic linking with dld
|
|
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__private.h"
|
|
#include "lt_dlloader.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 dld_link_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_dld_link";
|
|
vtable->module_open = vm_open;
|
|
vtable->module_close = vm_close;
|
|
vtable->find_sym = vm_sym;
|
|
vtable->dlloader_data = loader_data;
|
|
vtable->priority = LT_DLLOADER_APPEND;
|
|
}
|
|
|
|
if (vtable && (vtable->dlloader_data != loader_data))
|
|
{
|
|
LT__SETERROR (INIT_LOADER);
|
|
return 0;
|
|
}
|
|
|
|
return vtable;
|
|
}
|
|
|
|
|
|
|
|
/* --- IMPLEMENTATION --- */
|
|
|
|
|
|
#if defined(HAVE_DLD_H)
|
|
# include <dld.h>
|
|
#endif
|
|
|
|
/* 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 = lt__strdup (filename);
|
|
|
|
if (dld_link (filename) != 0)
|
|
{
|
|
LT__SETERROR (CANNOT_OPEN);
|
|
FREE (module);
|
|
}
|
|
|
|
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 (dld_unlink_by_file ((char*)(module), 1) != 0)
|
|
{
|
|
LT__SETERROR (CANNOT_CLOSE);
|
|
++errors;
|
|
}
|
|
else
|
|
{
|
|
FREE (module);
|
|
}
|
|
|
|
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 = dld_get_func (name);
|
|
|
|
if (!address)
|
|
{
|
|
LT__SETERROR (SYMBOL_NOT_FOUND);
|
|
}
|
|
|
|
return address;
|
|
}
|