Skip to content

Commit e078aaa

Browse files
committed
ltdl: set the error to file-not-found when LoadLibrary failed on missing file.
Currently we have traces like these: [XLTDL] loading urbi/all [XLTDL] try_dlopen (work\urbi\all, .la) [XLTDL] try_dlopen (work\urbi\all, .dll) [XLTDL] tryall_dlopen (work\urbi\all.dll, (ALL)) [XLTDL] lt_preopen->module_open (work\urbi\all.dll) [XLTDL] fail: file not found [XLTDL] lt_loadlibrary->module_open (work\urbi\all.dll) [XLTDL] LoadLibrary (work\urbi\all.dll) [XLTDL] LoadLibrary (work\urbi\all.dll): failed with error 126: Module not found [XLTDL] fail: can't open the module [XLTDL] loading work\urbi\all: fail [XLTDL] try_dlopen (lib\urbi\all, .la) [XLTDL] loading lib\urbi\all: fail where one can see that it tries to load all.la first in `work', then it tries all.dll in `work', both fail. So it tries the next component of the file search path: `lib'. But there, it only tries `all.la', it does not even try `all.dll', which would have succeeded though. This is because the first error found during path traversal (here, Module not found, which sets the Libtool error to CANNOT_OPEN) is preserved if the file exists, so that we use it to report the error when everything failed. So it does matter to report when the file does not exist, i.e., to set the error to FILE_NOT_FOUND, instead of CANNOT_OPEN. * libltdl/loaders/loadlibrary.c (vm_open): here.
1 parent 1154553 commit e078aaa

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libltdl/loaders/loadlibrary.c

+22
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,28 @@ vm_open (lt_user_data LT__UNUSED loader_data, const char *filename,
201201
SetErrorMode(errormode);
202202
}
203203

204+
/* To provide more accurate error messages, try to see if
205+
LoadLibrary failed because the file does not exist. Beside,
206+
setting the error to FILE_NOT_FOUND is required by tryall_dlopen:
207+
as long as loading modules fails because the file does not exist,
208+
it proceeds to the next attempts; but the first failure which is
209+
not related to FILE_NOT_FOUND ends this search, so that we do not
210+
hide failure of modules that we cannot load because they are
211+
broken beneath "file not found" error messages.
212+
213+
We check this *after* having tried dlopen to give a chance to the
214+
native system walk its dlopen module path. */
215+
if (!module)
216+
{
217+
FILE *file = fopen (wpath, LT_READTEXT_MODE);
218+
if (!file)
219+
{
220+
LT__SETERROR (FILE_NOT_FOUND);
221+
return 0;
222+
}
223+
fclose (file);
224+
}
225+
204226
/* libltdl expects this function to fail if it is unable
205227
to physically load the library. Sadly, LoadLibrary
206228
will search the loaded libraries for a match and return

0 commit comments

Comments
 (0)