diff --git a/ChangeLog b/ChangeLog index ca8161bd..19dd17eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2008-03-04 Ralf Wildenhues + + * 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 * configure.ac, libltdl/configure.ac (AC_INIT): Bump version diff --git a/NEWS b/NEWS index 7413ee2b..8d490f7f 100644 --- a/NEWS +++ b/NEWS @@ -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: -* 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: diff --git a/libltdl/loaders/dld_link.c b/libltdl/loaders/dld_link.c index 189ee3b0..7e882c9e 100644 --- a/libltdl/loaders/dld_link.c +++ b/libltdl/loaders/dld_link.c @@ -1,7 +1,7 @@ /* loader-dld_link.c -- dynamic linking with dld Copyright (C) 1998, 1999, 2000, 2004, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. Written by Thomas Tanner, 1998 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 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, lt_dladvise advise); 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); +static lt_dlvtable *vtable = 0; + /* 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); @@ -70,6 +71,7 @@ get_vtable (lt_user_data loader_data) vtable->module_open = vm_open; vtable->module_close = vm_close; vtable->find_sym = vm_sym; + vtable->dlloader_exit = vl_exit; vtable->dlloader_data = loader_data; vtable->priority = LT_DLLOADER_APPEND; } @@ -92,6 +94,15 @@ get_vtable (lt_user_data loader_data) # include #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 loader. Returns an opaque representation of the newly opened module for processing with this loader's other vtable functions. */ diff --git a/libltdl/loaders/dlopen.c b/libltdl/loaders/dlopen.c index d8bc45b3..94680c5a 100644 --- a/libltdl/loaders/dlopen.c +++ b/libltdl/loaders/dlopen.c @@ -45,20 +45,21 @@ LT_END_C_DECLS /* Boilerplate code to set up the vtable for hooking this loader into 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, lt_dladvise advise); 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); +static lt_dlvtable *vtable = 0; + /* 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_dlvtable *) lt__zalloc (sizeof *vtable); @@ -73,6 +74,7 @@ get_vtable (lt_user_data loader_data) vtable->module_open = vm_open; vtable->module_close = vm_close; vtable->find_sym = vm_sym; + vtable->dlloader_exit = vl_exit; vtable->dlloader_data = loader_data; vtable->priority = LT_DLLOADER_PREPEND; } @@ -146,6 +148,17 @@ get_vtable (lt_user_data loader_data) #define DL__SETERROR(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 loader. Returns an opaque representation of the newly opened module for processing with this loader's other vtable functions. */ diff --git a/libltdl/loaders/dyld.c b/libltdl/loaders/dyld.c index b6ee9436..b139d6c4 100644 --- a/libltdl/loaders/dyld.c +++ b/libltdl/loaders/dyld.c @@ -1,7 +1,7 @@ /* loader-dyld.c -- dynamic linking on darwin and OS X Copyright (C) 1998, 1999, 2000, 2004, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. Written by Peter O'Gorman, 1998 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, const char *symbolname); +static lt_dlvtable *vtable = 0; + /* 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); @@ -74,6 +74,7 @@ get_vtable (lt_user_data loader_data) vtable->module_open = vm_open; vtable->module_close = vm_close; vtable->find_sym = vm_sym; + vtable->dlloader_exit = vl_exit; vtable->dlloader_data = loader_data; 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; +/* 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. */ static int vl_init (lt_user_data loader_data) diff --git a/libltdl/loaders/load_add_on.c b/libltdl/loaders/load_add_on.c index f79604ff..379f9ba1 100644 --- a/libltdl/loaders/load_add_on.c +++ b/libltdl/loaders/load_add_on.c @@ -1,7 +1,7 @@ /* loader-load_add_on.c -- dynamic linking for BeOS Copyright (C) 1998, 1999, 2000, 2004, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. Written by Thomas Tanner, 1998 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 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, lt_dladvise advise); 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); +static lt_dlvtable *vtable = 0; + /* 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); @@ -70,6 +71,7 @@ get_vtable (lt_user_data loader_data) vtable->module_open = vm_open; vtable->module_close = vm_close; vtable->find_sym = vm_sym; + vtable->dlloader_exit = vl_exit; vtable->dlloader_data = loader_data; vtable->priority = LT_DLLOADER_APPEND; } @@ -90,6 +92,15 @@ get_vtable (lt_user_data loader_data) #include +/* 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 loader. Returns an opaque representation of the newly opened module for processing with this loader's other vtable functions. */ diff --git a/libltdl/loaders/loadlibrary.c b/libltdl/loaders/loadlibrary.c index 71f90c71..de5eee81 100644 --- a/libltdl/loaders/loadlibrary.c +++ b/libltdl/loaders/loadlibrary.c @@ -1,7 +1,7 @@ /* loader-loadlibrary.c -- dynamic linking for Win32 Copyright (C) 1998, 1999, 2000, 2004, 2005, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. Written by Thomas Tanner, 1998 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 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, lt_dladvise advise); 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); static lt_dlinterface_id iface_id = 0; +static lt_dlvtable *vtable = 0; /* Return the vtable for this loader, only the name and sym_prefix attributes (plus the virtual function implementations, obviously) @@ -63,8 +65,6 @@ static lt_dlinterface_id iface_id = 0; lt_dlvtable * get_vtable (lt_user_data loader_data) { - static lt_dlvtable *vtable = 0; - if (!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_close = vm_close; vtable->find_sym = vm_sym; + vtable->dlloader_exit = vl_exit; vtable->dlloader_data = loader_data; vtable->priority = LT_DLLOADER_APPEND; } @@ -97,6 +98,15 @@ get_vtable (lt_user_data loader_data) #include +/* 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 loader. Returns an opaque representation of the newly opened module for processing with this loader's other vtable functions. */ diff --git a/libltdl/loaders/preopen.c b/libltdl/loaders/preopen.c index 009ce4ea..7149287d 100644 --- a/libltdl/loaders/preopen.c +++ b/libltdl/loaders/preopen.c @@ -1,7 +1,7 @@ /* loader-preopen.c -- emulate dynamic linking using preloaded_symbols Copyright (C) 1998, 1999, 2000, 2004, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. Written by Thomas Tanner, 1998 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, const char *symbolname); +static lt_dlvtable *vtable = 0; + /* 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_dlvtable *) lt__zalloc (sizeof *vtable); @@ -132,6 +132,7 @@ vl_init (lt_user_data LT__UNUSED loader_data) static int vl_exit (lt_user_data LT__UNUSED loader_data) { + vtable = NULL; free_symlists (); return 0; } diff --git a/libltdl/loaders/shl_load.c b/libltdl/loaders/shl_load.c index 15f00bdf..5a09d872 100644 --- a/libltdl/loaders/shl_load.c +++ b/libltdl/loaders/shl_load.c @@ -1,7 +1,7 @@ /* loader-shl_load.c -- dynamic linking with shl_load (HP-UX) Copyright (C) 1998, 1999, 2000, 2004, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. Written by Thomas Tanner, 1998 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 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, lt_dladvise advise); 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); +static lt_dlvtable *vtable = 0; + /* 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); @@ -70,6 +71,7 @@ get_vtable (lt_user_data loader_data) vtable->module_open = vm_open; vtable->module_close = vm_close; vtable->find_sym = vm_sym; + vtable->dlloader_exit = vl_exit; vtable->dlloader_data = loader_data; 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) +/* 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 loader. Returns an opaque representation of the newly opened module for processing with this loader's other vtable functions. */ diff --git a/tests/lt_dlexit.at b/tests/lt_dlexit.at index 667ca796..e9de5c6c 100644 --- a/tests/lt_dlexit.at +++ b/tests/lt_dlexit.at @@ -32,6 +32,7 @@ AT_KEYWORDS([libltdl]) # Test for # 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], [[#include @@ -80,6 +81,14 @@ main (void) fprintf (stderr, "error during initialization: %s\n", lt_dlerror()); 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 (xdlsymtest (b1, "fb1", "vb1")) return 1; /* do not lt_dlclose here on purpose. */