dlclose reports ENOENT with simple code
Kevin Schnitzius
kometes@yahoo.com
Mon Mar 31 17:01:22 GMT 2025
On Monday, March 31, 2025 at 04:28:16 AM EDT, Corinna Vinschen via Cygwin <cygwin@cygwin.com> wrote:
> On Mar 31 11:25, Duncan Roe via Cygwin wrote:
> > On Sun, Mar 30, 2025 at 05:32:44PM +0800, cygwin wrote:
> > > Code to reproduce:
> > >
> > >
> > > #include <dlfcn.h>
> > > #include <assert.h>
> > > #include <stdio.h>
> > > #include <stdlib.h>
> > >
> > > int main() {
> > > void* handle = dlopen("/usr/bin/cygwin1.dll", RTLD_LAZY | RTLD_LOCAL);
> > > if (!handle)
> > > {
> > > printf("dlopen: %s\n", dlerror());
> > > exit(1);
> > > }
> > > int res = dlclose(handle);
> > > if (res != 0)
> > > {
> > > printf("dlclose: %s\n", dlerror());
> > > exit(1);
> > > }
> > > }
> > >
> > >
> > > The program should succeed, but now it fails with "dlclose: No such file or
> > > directory".
> > >
> > >
> > > --
> > > Problem reports: https://cygwin.com/problems.html
> > > FAQ: https://cygwin.com/faq/
> > > Documentation: https://cygwin.com/docs.html
> > > Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
> >
> > Reproduces here. uname -r reports 3.6.0-1.x86_64
>
> https://sourceware.org/pipermail/cygwin-patches/2025q1/013584.html
Further testing on 3.5.4-1.x86_64 (so likely not a regression):
// #define DLL2OPEN "/usr/bin/cygwin1.dll" // close fail ENOENT
// #define DLL2OPEN NULL // success (opens the exe)
// #define DLL2OPEN "/bin/cygwrap-0.dll" // success
// #define DLL2OPEN "/bin/cygwin1.dll" // close fail ENOENT
// #define DLL2OPEN "/cygdrive/c/Windows/System32/kernel32.dll" // open fail EINVAL
// #define DLL2OPEN "/cygdrive/c/Windows/System32/user32.dll" // close fail ENOENT
// #define DLL2OPEN "/cygdrive/c/cygwin64/bin/cygwin1.dll" // close fail ENOENT
// #define DLL2OPEN "/c/Windows/System32/ws2_32.dll" // close fail ENOENT
// #define DLL2OPEN "/cygdrive/c/Windows/System32/KernelBase.dll" // close fail ENOENT
// #define DLL2OPEN "/cygdrive/c/Windows/System32/ntdll.dll" // close fail ENOENT
// #define DLL2OPEN "/cygdrive/c/Windows/System32/wintrust.dll" // close fail ENOENT
// #define DLL2OPEN "/cygdrive/c/Windows/System32/mfc120.dll" // close fail ENOENT
#define DLL2OPEN "/cygdrive/c/Windows/twain_32.dll" // close fail ENOENT
int main() {
void* handle = dlopen(DLL2OPEN, RTLD_LAZY | RTLD_LOCAL);
...
(FYI, I don't use a prefix for mounting my drives hence "/c/Windows/System32/ws2_32.dll" works...)
Kevin
More information about the Cygwin
mailing list