Index: ChangeLog from Gary V. Vaughan From Ahmed Masud * libltdl/ltdl.c (sys_shl_open): Return a NULL module handle for self opening. (sys_shl_close): Be careful not to close a NULL module handle. (sys_shl_sym): Allow shl_findsym() to open NULL modules, but discard the modified module address it returns. Index: libltdl/ltdl.c =================================================================== RCS file: /cvsroot/libtool/libtool/libltdl/ltdl.c,v retrieving revision 1.128 diff -u -r1.128 ltdl.c --- libltdl/ltdl.c 2001/04/05 21:32:49 1.128 +++ libltdl/ltdl.c 2001/04/05 22:02:40 @@ -687,13 +687,20 @@ lt_user_data loader_data; const char *filename; { - lt_module module = shl_load (filename, LT_BIND_FLAGS, 0L); + /* A NULL handle is used to get symbols from self and everything + else already loaded that was exported with -E compiler flag. */ + lt_module module (lt_module) 0; - if (!module) + if (filename) { - MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); - } + module = shl_load (filename, LT_BIND_FLAGS, 0L); + if (!module) + { + MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); + } + } + return module; } @@ -704,7 +711,7 @@ { int errors = 0; - if (shl_unload ((shl_t) (module)) != 0) + if (module && (shl_unload ((shl_t) (module)) != 0)) { MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); ++errors; @@ -719,20 +726,25 @@ lt_module module; const char *symbol; { - lt_ptr address; + int is_module_self = (module == (lt_module) 0); + lt_ptr address = 0; - if (module && shl_findsym ((shl_t*) &module, - symbol, TYPE_UNDEFINED, &address) == 0) + /* shl_findsym considers zero valued MODULE as an indicator to search + for a symbol among all loaded (and exported) symbols including those + in the main executable. However, it sets MODULE to a valid module + address which breaks the semantics of libltdl's module management. */ + if (shl_findsym ((shl_t*) &module, symbol, TYPE_UNDEFINED, &address) == 0) { - if (address) + if (!address) { - return address; + MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); } - - MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); } + + if (is_module_self) + module = (lt_module) 0; - return 0; + return address; } static struct lt_user_dlloader sys_shl = {