Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readlink returns malformed path on Windows 11, perl 5.37.5 #20460

Closed
hakonhagland opened this issue Oct 30, 2022 · 6 comments
Closed

readlink returns malformed path on Windows 11, perl 5.37.5 #20460

hakonhagland opened this issue Oct 30, 2022 · 6 comments

Comments

@hakonhagland
Copy link
Contributor

hakonhagland commented Oct 30, 2022

I have built a debug version of perl 5.37.5 on Windows 11 using MinGW-w64 and gcc 11.3.0 from https://winlibs.com/ (using the MSVCRT runtime library), see #20395 for more information. When trying to install Path::Tiny using this perl I got some test failures, see dagolden/Path-Tiny#258 for more information. I reduced the problem down to this script:

use feature qw(say);
use strict;
use warnings;

my $fn = 'C:\Users\hakon\perl\debug\foo.txt';
open (my $fh, '>', $fn) or die "Could not open file '$fn': $!";
say $fh "Hello";
close $fh;
my $link = 'C:\Users\hakon\perl\debug\bar.txt';
if (-e $link) {
    unlink $link or die "Could not unlink '$link': $!";
}
symlink $fn, $link or die "Could not create symlink: $!";
my $path = readlink $link or die "Could not read symlink: $!";
say "link = $path";

The output is:

link = \??\C:\Users\hakon\perl\debug\foo.txt

Notice the leading \??\. Expected output would be:

link = C:\Users\hakon\perl\debug\foo.txt

Perl configuration

Summary of my perl5 (revision 5 version 37 subversion 5) configuration:
  Commit id: 382a56637961ef97fde5808e97df108db4e3ed8d
  Platform:
    osname=MSWin32
    osvers=10.0.22000.1098
    archname=MSWin32-x64-multi-thread
    uname=''
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='gcc'
    ccflags =' -DWIN32 -DWIN64 -DDEBUGGING -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D__USE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields'
    optimize='-g -O0'
    cppflags='-DWIN32'
    ccversion=''
    gccversion='11.3.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='long long'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++'
    ldflags ='-g -L"c:\perl-debug\lib\CORE" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\x86_64-w64-mingw32\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib\gcc\x86_64-w64-mingw32\11.3.0"'
    libpth=C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib C:\Winlibs64-Gcc11.3-msvcrt\mingw64\x86_64-w64-mingw32\lib C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib\gcc\x86_64-w64-mingw32\11.3.0
    libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=
    so=dll
    useshrplib=true
    libperl=libperl537.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-shared -g -L"c:\perl-debug\lib\CORE" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\x86_64-w64-mingw32\lib" -L"C:\Winlibs64-Gcc11.3-msvcrt\mingw64\lib\gcc\x86_64-w64-mingw32\11.3.0"'


Characteristics of this binary (from libperl):
  Compile-time options:
    DEBUGGING
    HAS_TIMES
    HAVE_INTERP_INTERN
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_IMPLICIT_SYS
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_TRACK_MEMPOOL
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under MSWin32
  Compiled at Oct 23 2022 17:00:35
  @INC:
    C:/perl-debug/site/lib
    C:/perl-debug/lib

@jkeenan
Copy link
Contributor

jkeenan commented Oct 30, 2022

Do you know whether the problem you observe with readlink occurs in any of these alternative ways of building a perl executable on Windows?

  • Earlier versions of Windows, e.g., Windows 10?
  • Different versions of gcc, e.g., gcc-10?
  • The UCRT runtime library, as opposed to MSVCRT?

@tonycoz
Copy link
Contributor

tonycoz commented Oct 31, 2022

It's possible the second commit in #20271 fixes this.

Unfortunately I couldn't find any documentation on which if the two names to use when I added Win32 readlink support, and didn't encounter the strange names you're seeing (or that I saw while re-working stat()) when I was working on readlink support.

@hakonhagland
Copy link
Contributor Author

Do you know whether the problem you observe with readlink occurs in any of these alternative ways of building a perl executable on Windows?

@jkeenan I tried with another perl 5.37.4 built with Visual C++ 2022 and nmake. I get exactly the same output here. So the problem is not specific to gcc or gmake.

@tonycoz
Copy link
Contributor

tonycoz commented Nov 1, 2022

#20271 is now merged into blead, please try giving blead a try, or wait for the next dev release.

And yes, it has nothing to do with the compiler, we implement readlink() via Win32 system calls.

@hakonhagland
Copy link
Contributor Author

#20271 is now merged into blead, please try giving blead a try

@tonycoz Yes it works! Output is now as expected. Thanks for the fix!

@tonycoz
Copy link
Contributor

tonycoz commented Nov 9, 2022

Fixed in blead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants