* libltdl/loaders/dld_link.c (vl_exit): New function, zero out ...

(vtable): ... this new file static variable split out from ...
(get_vtable): ... here.  Initialize vtable, register vl_exit as
dlloader_exit function.
* libltdl/loaders/dlopen.c: Likewise.
* libltdl/loaders/dyld.c: Likewise.
* libltdl/loaders/load_add_on.c: Likewise.
* libltdl/loaders/loadlibrary.c: Likewise.
* libltdl/loaders/shl_load.c: Likewise.
* libltdl/loaders/preopen.c: Likewise; vl_exit existed here
already.
* tests/lt_dlexit.at (lt_dlexit unloading libs): Update test.
* NEWS: Update.
Report by Andreas Schwab.
This commit is contained in:
Ralf Wildenhues 2008-03-04 21:00:19 +00:00
parent a428937f0e
commit 216d6cb930
10 changed files with 117 additions and 21 deletions

View File

@ -1,3 +1,20 @@
2008-03-04 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* libltdl/loaders/dld_link.c (vl_exit): New function, zero out ...
(vtable): ... this new file static variable split out from ...
(get_vtable): ... here. Initialize vtable, register vl_exit as
dlloader_exit function.
* libltdl/loaders/dlopen.c: Likewise.
* libltdl/loaders/dyld.c: Likewise.
* libltdl/loaders/load_add_on.c: Likewise.
* libltdl/loaders/loadlibrary.c: Likewise.
* libltdl/loaders/shl_load.c: Likewise.
* libltdl/loaders/preopen.c: Likewise; vl_exit existed here
already.
* tests/lt_dlexit.at (lt_dlexit unloading libs): Update test.
* NEWS: Update.
Report by Andreas Schwab.
2008-03-01 Gary V. Vaughan <gary@gnu.org> 2008-03-01 Gary V. Vaughan <gary@gnu.org>
* configure.ac, libltdl/configure.ac (AC_INIT): Bump version * configure.ac, libltdl/configure.ac (AC_INIT): Bump version

5
NEWS
View File

@ -2,7 +2,10 @@ NEWS - list of user-visible changes between releases of GNU Libtool
New in 2.3b: 2008-??-??: CVS version 2.3a, Libtool team: New in 2.3b: 2008-??-??: CVS version 2.3a, Libtool team:
* Nothing yet! * Bug fixes:
- Fix 2.2 regression in libltdl that causes memory corruption upon
repeated `lt_dlinit(); lt_dlexit()'.
New in 2.2: 2008-03-01; CVS version 2.1c, Libtool team: New in 2.2: 2008-03-01; CVS version 2.1c, Libtool team:

View File

@ -1,7 +1,7 @@
/* loader-dld_link.c -- dynamic linking with dld /* loader-dld_link.c -- dynamic linking with dld
Copyright (C) 1998, 1999, 2000, 2004, 2006, Copyright (C) 1998, 1999, 2000, 2004, 2006,
2007 Free Software Foundation, Inc. 2007, 2008 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998 Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the NOTE: The canonical source of this file is maintained with the
@ -45,20 +45,21 @@ LT_END_C_DECLS
/* Boilerplate code to set up the vtable for hooking this loader into /* Boilerplate code to set up the vtable for hooking this loader into
libltdl's loader list: */ libltdl's loader list: */
static int vl_exit (lt_user_data loader_data);
static lt_module vm_open (lt_user_data loader_data, const char *filename, static lt_module vm_open (lt_user_data loader_data, const char *filename,
lt_dladvise advise); lt_dladvise advise);
static int vm_close (lt_user_data loader_data, lt_module module); static int vm_close (lt_user_data loader_data, lt_module module);
static void * vm_sym (lt_user_data loader_data, lt_module module, static void * vm_sym (lt_user_data loader_data, lt_module module,
const char *symbolname); const char *symbolname);
static lt_dlvtable *vtable = 0;
/* Return the vtable for this loader, only the name and sym_prefix /* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously) attributes (plus the virtual function implementations, obviously)
change between loaders. */ change between loaders. */
lt_dlvtable * lt_dlvtable *
get_vtable (lt_user_data loader_data) get_vtable (lt_user_data loader_data)
{ {
static lt_dlvtable *vtable = 0;
if (!vtable) if (!vtable)
{ {
vtable = lt__zalloc (sizeof *vtable); vtable = lt__zalloc (sizeof *vtable);
@ -70,6 +71,7 @@ get_vtable (lt_user_data loader_data)
vtable->module_open = vm_open; vtable->module_open = vm_open;
vtable->module_close = vm_close; vtable->module_close = vm_close;
vtable->find_sym = vm_sym; vtable->find_sym = vm_sym;
vtable->dlloader_exit = vl_exit;
vtable->dlloader_data = loader_data; vtable->dlloader_data = loader_data;
vtable->priority = LT_DLLOADER_APPEND; vtable->priority = LT_DLLOADER_APPEND;
} }
@ -92,6 +94,15 @@ get_vtable (lt_user_data loader_data)
# include <dld.h> # include <dld.h>
#endif #endif
/* A function called through the vtable when this loader is no
longer needed by the application. */
static int
vl_exit (lt_user_data LT__UNUSED loader_data)
{
vtable = NULL;
return 0;
}
/* A function called through the vtable to open a module with this /* A function called through the vtable to open a module with this
loader. Returns an opaque representation of the newly opened loader. Returns an opaque representation of the newly opened
module for processing with this loader's other vtable functions. */ module for processing with this loader's other vtable functions. */

View File

@ -45,20 +45,21 @@ LT_END_C_DECLS
/* Boilerplate code to set up the vtable for hooking this loader into /* Boilerplate code to set up the vtable for hooking this loader into
libltdl's loader list: */ libltdl's loader list: */
static int vl_exit (lt_user_data loader_data);
static lt_module vm_open (lt_user_data loader_data, const char *filename, static lt_module vm_open (lt_user_data loader_data, const char *filename,
lt_dladvise advise); lt_dladvise advise);
static int vm_close (lt_user_data loader_data, lt_module module); static int vm_close (lt_user_data loader_data, lt_module module);
static void * vm_sym (lt_user_data loader_data, lt_module module, static void * vm_sym (lt_user_data loader_data, lt_module module,
const char *symbolname); const char *symbolname);
static lt_dlvtable *vtable = 0;
/* Return the vtable for this loader, only the name and sym_prefix /* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously) attributes (plus the virtual function implementations, obviously)
change between loaders. */ change between loaders. */
lt_dlvtable * lt_dlvtable *
get_vtable (lt_user_data loader_data) get_vtable (lt_user_data loader_data)
{ {
static lt_dlvtable *vtable = 0;
if (!vtable) if (!vtable)
{ {
vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable); vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
@ -73,6 +74,7 @@ get_vtable (lt_user_data loader_data)
vtable->module_open = vm_open; vtable->module_open = vm_open;
vtable->module_close = vm_close; vtable->module_close = vm_close;
vtable->find_sym = vm_sym; vtable->find_sym = vm_sym;
vtable->dlloader_exit = vl_exit;
vtable->dlloader_data = loader_data; vtable->dlloader_data = loader_data;
vtable->priority = LT_DLLOADER_PREPEND; vtable->priority = LT_DLLOADER_PREPEND;
} }
@ -146,6 +148,17 @@ get_vtable (lt_user_data loader_data)
#define DL__SETERROR(errorcode) \ #define DL__SETERROR(errorcode) \
LT__SETERRORSTR (DLERROR (errorcode)) LT__SETERRORSTR (DLERROR (errorcode))
/* A function called through the vtable when this loader is no
longer needed by the application. */
static int
vl_exit (lt_user_data LT__UNUSED loader_data)
{
vtable = NULL;
return 0;
}
/* A function called through the vtable to open a module with this /* A function called through the vtable to open a module with this
loader. Returns an opaque representation of the newly opened loader. Returns an opaque representation of the newly opened
module for processing with this loader's other vtable functions. */ module for processing with this loader's other vtable functions. */

View File

@ -1,7 +1,7 @@
/* loader-dyld.c -- dynamic linking on darwin and OS X /* loader-dyld.c -- dynamic linking on darwin and OS X
Copyright (C) 1998, 1999, 2000, 2004, 2006, Copyright (C) 1998, 1999, 2000, 2004, 2006,
2007 Free Software Foundation, Inc. 2007, 2008 Free Software Foundation, Inc.
Written by Peter O'Gorman, 1998 Written by Peter O'Gorman, 1998
NOTE: The canonical source of this file is maintained with the NOTE: The canonical source of this file is maintained with the
@ -53,14 +53,14 @@ static int vm_close (lt_user_data loader_data, lt_module module);
static void * vm_sym (lt_user_data loader_data, lt_module module, static void * vm_sym (lt_user_data loader_data, lt_module module,
const char *symbolname); const char *symbolname);
static lt_dlvtable *vtable = 0;
/* Return the vtable for this loader, only the name and sym_prefix /* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously) attributes (plus the virtual function implementations, obviously)
change between loaders. */ change between loaders. */
lt_dlvtable * lt_dlvtable *
get_vtable (lt_user_data loader_data) get_vtable (lt_user_data loader_data)
{ {
static lt_dlvtable *vtable = 0;
if (!vtable) if (!vtable)
{ {
vtable = lt__zalloc (sizeof *vtable); vtable = lt__zalloc (sizeof *vtable);
@ -74,6 +74,7 @@ get_vtable (lt_user_data loader_data)
vtable->module_open = vm_open; vtable->module_open = vm_open;
vtable->module_close = vm_close; vtable->module_close = vm_close;
vtable->find_sym = vm_sym; vtable->find_sym = vm_sym;
vtable->dlloader_exit = vl_exit;
vtable->dlloader_data = loader_data; vtable->dlloader_data = loader_data;
vtable->priority = LT_DLLOADER_APPEND; vtable->priority = LT_DLLOADER_APPEND;
} }
@ -181,6 +182,15 @@ static enum DYLD_BOOL (*lt__module_export) (NSModule module) = 0;
static int dyld_cannot_close = 0; static int dyld_cannot_close = 0;
/* A function called through the vtable when this loader is no
longer needed by the application. */
static int
vl_exit (lt_user_data LT__UNUSED loader_data)
{
vtable = NULL;
return 0;
}
/* A function called through the vtable to initialise this loader. */ /* A function called through the vtable to initialise this loader. */
static int static int
vl_init (lt_user_data loader_data) vl_init (lt_user_data loader_data)

View File

@ -1,7 +1,7 @@
/* loader-load_add_on.c -- dynamic linking for BeOS /* loader-load_add_on.c -- dynamic linking for BeOS
Copyright (C) 1998, 1999, 2000, 2004, 2006, Copyright (C) 1998, 1999, 2000, 2004, 2006,
2007 Free Software Foundation, Inc. 2007, 2008 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998 Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the NOTE: The canonical source of this file is maintained with the
@ -45,20 +45,21 @@ LT_END_C_DECLS
/* Boilerplate code to set up the vtable for hooking this loader into /* Boilerplate code to set up the vtable for hooking this loader into
libltdl's loader list: */ libltdl's loader list: */
static int vl_exit (lt_user_data loader_data);
static lt_module vm_open (lt_user_data loader_data, const char *filename, static lt_module vm_open (lt_user_data loader_data, const char *filename,
lt_dladvise advise); lt_dladvise advise);
static int vm_close (lt_user_data loader_data, lt_module module); static int vm_close (lt_user_data loader_data, lt_module module);
static void * vm_sym (lt_user_data loader_data, lt_module module, static void * vm_sym (lt_user_data loader_data, lt_module module,
const char *symbolname); const char *symbolname);
static lt_dlvtable *vtable = 0;
/* Return the vtable for this loader, only the name and sym_prefix /* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously) attributes (plus the virtual function implementations, obviously)
change between loaders. */ change between loaders. */
lt_dlvtable * lt_dlvtable *
get_vtable (lt_user_data loader_data) get_vtable (lt_user_data loader_data)
{ {
static lt_dlvtable *vtable = 0;
if (!vtable) if (!vtable)
{ {
vtable = lt__zalloc (sizeof *vtable); vtable = lt__zalloc (sizeof *vtable);
@ -70,6 +71,7 @@ get_vtable (lt_user_data loader_data)
vtable->module_open = vm_open; vtable->module_open = vm_open;
vtable->module_close = vm_close; vtable->module_close = vm_close;
vtable->find_sym = vm_sym; vtable->find_sym = vm_sym;
vtable->dlloader_exit = vl_exit;
vtable->dlloader_data = loader_data; vtable->dlloader_data = loader_data;
vtable->priority = LT_DLLOADER_APPEND; vtable->priority = LT_DLLOADER_APPEND;
} }
@ -90,6 +92,15 @@ get_vtable (lt_user_data loader_data)
#include <kernel/image.h> #include <kernel/image.h>
/* A function called through the vtable when this loader is no
longer needed by the application. */
static int
vl_exit (lt_user_data LT__UNUSED loader_data)
{
vtable = NULL;
return 0;
}
/* A function called through the vtable to open a module with this /* A function called through the vtable to open a module with this
loader. Returns an opaque representation of the newly opened loader. Returns an opaque representation of the newly opened
module for processing with this loader's other vtable functions. */ module for processing with this loader's other vtable functions. */

View File

@ -1,7 +1,7 @@
/* loader-loadlibrary.c -- dynamic linking for Win32 /* loader-loadlibrary.c -- dynamic linking for Win32
Copyright (C) 1998, 1999, 2000, 2004, 2005, 2006, Copyright (C) 1998, 1999, 2000, 2004, 2005, 2006,
2007 Free Software Foundation, Inc. 2007, 2008 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998 Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the NOTE: The canonical source of this file is maintained with the
@ -49,6 +49,7 @@ LT_END_C_DECLS
/* Boilerplate code to set up the vtable for hooking this loader into /* Boilerplate code to set up the vtable for hooking this loader into
libltdl's loader list: */ libltdl's loader list: */
static int vl_exit (lt_user_data loader_data);
static lt_module vm_open (lt_user_data loader_data, const char *filename, static lt_module vm_open (lt_user_data loader_data, const char *filename,
lt_dladvise advise); lt_dladvise advise);
static int vm_close (lt_user_data loader_data, lt_module module); static int vm_close (lt_user_data loader_data, lt_module module);
@ -56,6 +57,7 @@ static void * vm_sym (lt_user_data loader_data, lt_module module,
const char *symbolname); const char *symbolname);
static lt_dlinterface_id iface_id = 0; static lt_dlinterface_id iface_id = 0;
static lt_dlvtable *vtable = 0;
/* Return the vtable for this loader, only the name and sym_prefix /* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously) attributes (plus the virtual function implementations, obviously)
@ -63,8 +65,6 @@ static lt_dlinterface_id iface_id = 0;
lt_dlvtable * lt_dlvtable *
get_vtable (lt_user_data loader_data) get_vtable (lt_user_data loader_data)
{ {
static lt_dlvtable *vtable = 0;
if (!vtable) if (!vtable)
{ {
vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable); vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
@ -77,6 +77,7 @@ get_vtable (lt_user_data loader_data)
vtable->module_open = vm_open; vtable->module_open = vm_open;
vtable->module_close = vm_close; vtable->module_close = vm_close;
vtable->find_sym = vm_sym; vtable->find_sym = vm_sym;
vtable->dlloader_exit = vl_exit;
vtable->dlloader_data = loader_data; vtable->dlloader_data = loader_data;
vtable->priority = LT_DLLOADER_APPEND; vtable->priority = LT_DLLOADER_APPEND;
} }
@ -97,6 +98,15 @@ get_vtable (lt_user_data loader_data)
#include <windows.h> #include <windows.h>
/* A function called through the vtable when this loader is no
longer needed by the application. */
static int
vl_exit (lt_user_data LT__UNUSED loader_data)
{
vtable = NULL;
return 0;
}
/* A function called through the vtable to open a module with this /* A function called through the vtable to open a module with this
loader. Returns an opaque representation of the newly opened loader. Returns an opaque representation of the newly opened
module for processing with this loader's other vtable functions. */ module for processing with this loader's other vtable functions. */

View File

@ -1,7 +1,7 @@
/* loader-preopen.c -- emulate dynamic linking using preloaded_symbols /* loader-preopen.c -- emulate dynamic linking using preloaded_symbols
Copyright (C) 1998, 1999, 2000, 2004, 2006, Copyright (C) 1998, 1999, 2000, 2004, 2006,
2007 Free Software Foundation, Inc. 2007, 2008 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998 Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the NOTE: The canonical source of this file is maintained with the
@ -53,14 +53,14 @@ static int vm_close (lt_user_data loader_data, lt_module module);
static void * vm_sym (lt_user_data loader_data, lt_module module, static void * vm_sym (lt_user_data loader_data, lt_module module,
const char *symbolname); const char *symbolname);
static lt_dlvtable *vtable = 0;
/* Return the vtable for this loader, only the name and sym_prefix /* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously) attributes (plus the virtual function implementations, obviously)
change between loaders. */ change between loaders. */
lt_dlvtable * lt_dlvtable *
get_vtable (lt_user_data loader_data) get_vtable (lt_user_data loader_data)
{ {
static lt_dlvtable *vtable = 0;
if (!vtable) if (!vtable)
{ {
vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable); vtable = (lt_dlvtable *) lt__zalloc (sizeof *vtable);
@ -132,6 +132,7 @@ vl_init (lt_user_data LT__UNUSED loader_data)
static int static int
vl_exit (lt_user_data LT__UNUSED loader_data) vl_exit (lt_user_data LT__UNUSED loader_data)
{ {
vtable = NULL;
free_symlists (); free_symlists ();
return 0; return 0;
} }

View File

@ -1,7 +1,7 @@
/* loader-shl_load.c -- dynamic linking with shl_load (HP-UX) /* loader-shl_load.c -- dynamic linking with shl_load (HP-UX)
Copyright (C) 1998, 1999, 2000, 2004, 2006, Copyright (C) 1998, 1999, 2000, 2004, 2006,
2007 Free Software Foundation, Inc. 2007, 2008 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998 Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the NOTE: The canonical source of this file is maintained with the
@ -45,20 +45,21 @@ LT_END_C_DECLS
/* Boilerplate code to set up the vtable for hooking this loader into /* Boilerplate code to set up the vtable for hooking this loader into
libltdl's loader list: */ libltdl's loader list: */
static int vl_exit (lt_user_data loader_data);
static lt_module vm_open (lt_user_data loader_data, const char *filename, static lt_module vm_open (lt_user_data loader_data, const char *filename,
lt_dladvise advise); lt_dladvise advise);
static int vm_close (lt_user_data loader_data, lt_module module); static int vm_close (lt_user_data loader_data, lt_module module);
static void * vm_sym (lt_user_data loader_data, lt_module module, static void * vm_sym (lt_user_data loader_data, lt_module module,
const char *symbolname); const char *symbolname);
static lt_dlvtable *vtable = 0;
/* Return the vtable for this loader, only the name and sym_prefix /* Return the vtable for this loader, only the name and sym_prefix
attributes (plus the virtual function implementations, obviously) attributes (plus the virtual function implementations, obviously)
change between loaders. */ change between loaders. */
lt_dlvtable * lt_dlvtable *
get_vtable (lt_user_data loader_data) get_vtable (lt_user_data loader_data)
{ {
static lt_dlvtable *vtable = 0;
if (!vtable) if (!vtable)
{ {
vtable = lt__zalloc (sizeof *vtable); vtable = lt__zalloc (sizeof *vtable);
@ -70,6 +71,7 @@ get_vtable (lt_user_data loader_data)
vtable->module_open = vm_open; vtable->module_open = vm_open;
vtable->module_close = vm_close; vtable->module_close = vm_close;
vtable->find_sym = vm_sym; vtable->find_sym = vm_sym;
vtable->dlloader_exit = vl_exit;
vtable->dlloader_data = loader_data; vtable->dlloader_data = loader_data;
vtable->priority = LT_DLLOADER_APPEND; vtable->priority = LT_DLLOADER_APPEND;
} }
@ -133,6 +135,15 @@ get_vtable (lt_user_data loader_data)
#define LT_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH) #define LT_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH)
/* A function called through the vtable when this loader is no
longer needed by the application. */
static int
vl_exit (lt_user_data LT__UNUSED loader_data)
{
vtable = NULL;
return 0;
}
/* A function called through the vtable to open a module with this /* A function called through the vtable to open a module with this
loader. Returns an opaque representation of the newly opened loader. Returns an opaque representation of the newly opened
module for processing with this loader's other vtable functions. */ module for processing with this loader's other vtable functions. */

View File

@ -32,6 +32,7 @@ AT_KEYWORDS([libltdl])
# Test for # Test for
# http://lists.gnu.org/archive/html/bug-libtool/2007-01/msg00014.html # http://lists.gnu.org/archive/html/bug-libtool/2007-01/msg00014.html
# http://lists.gnu.org/archive/html/bug-libtool/2008-03/msg00013.html
AT_DATA([main.c], AT_DATA([main.c],
[[#include <ltdl.h> [[#include <ltdl.h>
@ -80,6 +81,14 @@ main (void)
fprintf (stderr, "error during initialization: %s\n", lt_dlerror()); fprintf (stderr, "error during initialization: %s\n", lt_dlerror());
return 1; return 1;
} }
if (lt_dlexit() != 0) {
fprintf (stderr, "error during first lt_dlexit: %s\n", lt_dlerror());
return 1;
}
if (lt_dlinit() != 0) {
fprintf (stderr, "error during second initialization: %s\n", lt_dlerror());
return 1;
}
if (!(b1 = xdlopen ("modb1.la"))) return 1; if (!(b1 = xdlopen ("modb1.la"))) return 1;
if (xdlsymtest (b1, "fb1", "vb1")) return 1; if (xdlsymtest (b1, "fb1", "vb1")) return 1;
/* do not lt_dlclose here on purpose. */ /* do not lt_dlclose here on purpose. */