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

Both prebuild release and manual installation crashed on Windows10 2004 caused by V panic: substr(4, 0) out of bounds (len=0) #19466

Open
cjun714 opened this issue Sep 28, 2023 · 2 comments
Labels
Bug This tag is applied to issues which reports bugs. Install/first impressions Bugs/feature requests, that are related to the first impressions that users have of V. Modules: os Bugs/feature requests, that are related to the `os` module. OS: Windows Bugs/feature requests, that are specific to Windows OS.

Comments

@cjun714
Copy link

cjun714 commented Sep 28, 2023

Describe the bug

  1. Prebuild release crashed on Windows10 2004 when in REPL to eval or build any HelloWorld code

  2. Manual installation crashed using .\make.bat

Reproduction Steps

Prebuild release:

  1. download latest release: v-weekly.2023.39.zip

  2. extract it and add to PATH, before this I cleaned all PATH on Windows

  3. run cmd.exe

  4. run v

  5. repl is opened

  6. Input "2+3" and enter

  7. crash

  8. create an empty fn main(){} source file

  9. use v . to build

  10. crash

Manual installation:

  1. I removed all PATH on Windows
  2. I downloaded newest GCC 13.2.0 (MCF)from https://winlibs.com/ (winlibs-x86_64-mcf-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64ucrt-11.0.1-r2.7z) and extract to w:/
  3. I added path of git and mingw into PATH:
    image
  4. git clone https://github.com/vlang/v
  5. cd v and run .\make.bat
  6. build failed

Expected Behavior

Prebuild release can work without crash.

Manual installation can work.

Current Behavior

Prebuild binary crashed

W:\test>v --version
V 0.4.1 12ee3fa

W:\test>v
 ____    ____
 \   \  /   /  |  Welcome to the V REPL (for help with V itself, type  exit , then run  v help ).
  \   \/   /   |  Note: the REPL is highly experimental. For best V experience, use a text editor,
   \      /    |  save your code in a  main.v  file and execute:  v run main.v
    \    /     |  V 0.4.1 12ee3fa . Use  list  to see the accumulated program so far.
     \__/      |  Use Ctrl-C or  exit  to exit, or  help  to see other available commands.

>>> 2+3
V panic: substr(4, 0) out of bounds (len=0)
v hash: 12ee3fa
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
1 : BaseThreadInitThunk        ?? : address = 0x230ab381b40
0 : RtlUserThreadStart         ?? : address = 0x230ab3819d0
>>> exit


W:\test>dir
 驱动器 W 中的卷是 RAMDISK
 卷的序列号是 BE85-CFF2

 W:\test 的目录

2023/09/29  03:27    <DIR>          .
2023/09/29  03:27    <DIR>          ..
2023/09/29  03:27                13 main.v
               1 个文件             13 字节
               2 个目录 39,380,967,424 可用字节

W:\test>v .
V panic: substr(4, 0) out of bounds (len=0)
v hash: 12ee3fa
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
SymFromAddr failure: 487 = Attempt to access invalid address (Verify that you have the .pdb file in the right folder.)
1 : BaseThreadInitThunk        ?? : address = 0x29c397f4890
0 : RtlUserThreadStart         ?? : address = 0x29c397f4930

W:\test>

Compile from source crashed

Microsoft Windows [版本 10.0.19041.1415]
(c) Microsoft Corporation。保留所有权利。

C:\Users\John>w:

W:\>git clone https://github.com/vlang/v
Cloning into 'v'...
remote: Enumerating objects: 152524, done.
remote: Counting objects: 100% (42/42), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 152524 (delta 9), reused 23 (delta 7), pack-reused 152482
Receiving objects: 100% (152524/152524), 66.17 MiB | 6.60 MiB/s, done.
Resolving deltas: 100% (108757/108757), done.
Updating files: 100% (6975/6975), done.

W:\>cd v

W:\v>.\make.bat
系统找不到指定的路径。
Bootstrapping TCC...
 > TCC not found
 > Downloading TCC64 from https://github.com/vlang/tccbin , branch "thirdparty-windows-amd64"
remote: Enumerating objects: 165, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 165 (delta 1), reused 6 (delta 0), pack-reused 145
656.00 KiB/s
Receiving objects: 100% (165/165), 988.91 KiB | 797.00 KiB/s, done.
Resolving deltas: 100% (23/23), done.
commit e90c262006324ba64affd1b47839bace5f3288f8 (HEAD -> thirdparty-windows-amd64, origin/thirdparty-windows-amd64)
Author: d3c0d3d <[email protected]>
Date:   Tue Mar 7 09:13:13 2023 -0300

    Add GetConsoleWindow to lib/kernel32.def (#32)

commit 1e6e7c6f1ba684cc8de435d169229b87777a4e38
Author: Delyan Angelov <[email protected]>
Date:   Sun Jan 8 13:31:13 2023 +0200

    add mmreg.h, mmsystem.h, strings.h from gcc

commit 41b40801eea1c7cde26eb51e50dab35a6b8de15b
Author: Delyan Angelov <[email protected]>
Date:   Wed Dec 28 16:29:41 2022 +0200

    enable compilation of mbedtls using programs with tcc

系统找不到指定的路径。
Cloning vc...
 > Cloning from remote https://github.com/vlang/vc
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 960.99 KiB | 798.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.

Building V...
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with "thirdparty/tcc/tcc.exe"
 > Compiling "./v.exe" with "./v_win_bootstrap.exe"
V panic: substr(4, 0) out of bounds (len=0)
v hash: b5f71df
print_backtrace_skipping_top_frames is not implemented
'where' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
 > Clang not found
'where' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
 > GCC not found
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with MSVC
v_win.c
vc/v_win.c(496): fatal error C1189: #error:  VERROR_MESSAGE The C compiler can not find <inttypes.h>. Please install build-essentials
In some cases, compile errors happen because of the MSVC compiler version
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30152 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

Backend compiler error

Exiting from error
ERROR: please follow the instructions in https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows

W:\v>

Possible Solution

No response

Additional Information/Context

Both prebuild and manual installation crashed,

Which I have tried:

  1. git clone https://github.com/vlang/v and build it;
  2. use weekly.2023.39 prebuild or download src and build it;
  3. use v-0.4.1_2 prebuild or download src and build it;
    None of them is available, all crashed.

All of crash caused by V panic: substr(4, 0) out of bounds (len=0)

There is another issue,
The make.bat use where to detect GCC or Clang, it caused detect GCC failed even I have already added "mingw/bin" into PATH,
So I deleted GCC detect code below, and built using GCC, still crashed, same issue:

:gcc_strap
where /q gcc
if %ERRORLEVEL% NEQ 0 (
	echo  ^> GCC not found
	if not [!compiler!] == [] goto :error
	goto :msvc_strap
)

GCC can build v_win_bootstrap.exe, after that crashed

W:\v>.\make.bat
Updating TCC
 > Syncing TCC from https://github.com/vlang/tccbin

Updating vc...
 > Sync with remote https://github.com/vlang/vc

Building V...
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with "thirdparty/tcc/tcc.exe"
 > Compiling "./v.exe" with "./v_win_bootstrap.exe"
V panic: substr(4, 0) out of bounds (len=0)
v hash: b5f71df
print_backtrace_skipping_top_frames is not implemented
'where' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
 > Clang not found
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with GCC
 > Compiling "./v.exe" with "./v_win_bootstrap.exe"
V panic: substr(4, 0) out of bounds (len=0)
v hash: b5f71df
print_backtrace_skipping_top_frames is not implemented

Backend compiler error

Exiting from error
ERROR: please follow the instructions in https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows

V version

I have tried newest code by git clone,
and also tried newest prebuild release(weekly.2023.39) and old release(0.4.1_2), try both binary or build it from source.

Environment details (OS name and version, etc.)

Windows10 2004 x64
Hardware Ryzen7 1700x

@cjun714 cjun714 added the Bug This tag is applied to issues which reports bugs. label Sep 28, 2023
@cjun714
Copy link
Author

cjun714 commented Sep 29, 2023

I think I found root cause.
The cause perhaps is V path api can't parse path on ramdisk correctly.

I use a ramdisk tool(https://sourceforge.net/projects/imdisk-toolkit/) to mount ram as virtual driver z:.
I put temporary projects on ramdisk and build them on ramdisk.
I set TEMP and TMP to z:/tmp, that leads to building failed.

When building v, some temp files will be generated on TEMP, but V path api can't handle path on ramdisk,
that caused error V panic: substr(4, 0) out of bounds (len=0)

After I reset TEMP and TMP to "c:/temp", build succeed:

E:\v>.\make.bat -tcc
Updating TCC
 > Syncing TCC from https://github.com/vlang/tccbin

Updating vc...
 > Sync with remote https://github.com/vlang/vc

Building V...
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with "thirdparty/tcc/tcc.exe"
 > Compiling "./v.exe" with "./v_win_bootstrap.exe"
> C compiler cmd: "thirdparty/tcc/tcc.exe" "@C:\Temp\tmp\v_0\v_up.exe.tmp.c.rsp"
> C compiler response file "C:\Temp\tmp\v_0\v_up.exe.tmp.c.rsp":
  -Bthirdparty/tcc -fwrapv -g -o "E:\\v\\./v_up.exe" -Wl,-stack=16777216 -Werror=implicit-function-declaration -I "E:\\v\\thirdparty\\stdatomic\\win" "C:\\Temp\\tmp\\v_0\\v_up.exe.tmp.c" -std=c99 -D_DEFAULT_SOURCE -municode -bt25 -ldbghelp -ladvapi32 -lshell32
Your `tcc` is working. Good - it is much faster at compiling C source code.
 > V built successfully
 > To add V to your PATH, run `./v.exe symlink`.

V version: V 0.4.1 b5f71df

E:\v>.\make.bat -gcc
Updating TCC
 > Syncing TCC from https://github.com/vlang/tccbin

Updating vc...
 > Sync with remote https://github.com/vlang/vc

Building V...
 > Attempting to build "./v_win_bootstrap.exe" (from v_win.c) with GCC
 > Compiling "./v.exe" with "./v_win_bootstrap.exe"
> C compiler cmd: gcc "@C:\Temp\tmp\v_0\v_up.exe.tmp.c.rsp"
> C compiler response file "C:\Temp\tmp\v_0\v_up.exe.tmp.c.rsp":
  -fwrapv -g -no-pie -o "E:\\v\\./v_up.exe" -Wl,-stack=16777216 -Werror=implicit-function-declaration -I "E:\\v\\thirdparty\\stdatomic\\win" "C:\\Temp\\tmp\\v_0\\v_up.exe.tmp.c" -std=c99 -D_DEFAULT_SOURCE -municode -ldbghelp -ladvapi32 -lshell32
Your `tcc` is working. Good - it is much faster at compiling C source code.
 > V built successfully
 > To add V to your PATH, run `./v.exe symlink`.

V version: V 0.4.1 b5f71df

E:\v>

The REPL failure and v . failure also caused by this.

If I put v project on ramdisk and build it, v . will cause an error V panic: substr(4, 0)
If I use REPL, some temporary file used by REPL will be generated on ramdisk, that will also cause error V panic: substr(4, 0) .

And this issue also cause v can't work correctly in MSYS2.

MSYS2 toolchain and Go, GCC, Clang, Python can always handle path on ramdisk correctly.
So I think this should be v implementation bug.

@ArtemkaKun ArtemkaKun added the Install/first impressions Bugs/feature requests, that are related to the first impressions that users have of V. label Sep 29, 2023
@spytheman
Copy link
Member

Good analysis, thanks for reporting it.

@spytheman spytheman added OS: Windows Bugs/feature requests, that are specific to Windows OS. Modules: os Bugs/feature requests, that are related to the `os` module. labels Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Install/first impressions Bugs/feature requests, that are related to the first impressions that users have of V. Modules: os Bugs/feature requests, that are related to the `os` module. OS: Windows Bugs/feature requests, that are specific to Windows OS.
Projects
None yet
Development

No branches or pull requests

3 participants