v icon indicating copy to clipboard operation
v copied to clipboard

Hot reload not working on Windows with MSVC

Open MangelMaxime opened this issue 4 years ago • 12 comments

V version: V 0.1.29 9fbf38c OS: Windows 10

What did you do?

I run the following program with v -live run message.v

module main

import time

[live]
fn print_message() {
	println('Hello! Modify this message while the program is running.')
}

fn main() {
	for {
		print_message()
		time.sleep_ms(500)
	}
}

What did you expect to see?

Program should start with hot reload support.

What did you see instead?

$ ./message.exe 
>       compilation cmd: C:\Users\Maxime\Workspaces\Github\vlang\v\v.exe -cc msvc  -sharedlive -shared -o C:\\Users\\Maxime\\.cache/tmp.1.message message.v
compilation took: 855ms
> compile_and_reload_shared_lib compiled: C:\\Users\\Maxime\\.cache/tmp.1.message.dll
live mutex locking...
live mutex locked
> load_lib OK, new live_lib: 00007FFB6A340000
live mutex unlocking...
live mutex unlocked
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
Segmentation fault

There is another issue labeled "Hot reload on windows" https://github.com/vlang/v/issues/3548 but as I don't have the same error I created a new one.

MangelMaxime avatar Nov 24 '20 13:11 MangelMaxime

I get a different error with latest V:

PS D:\> v -live run foo.v
>       compilation cmd: D:\git\v\v.exe   -sharedlive -shared -o C:\\Users\\jalon\\.cache/tmp.1.foo foo.v
compilation took: 1534ms
new_lib_path: C:\\Users\\jalon\\.cache/tmp.1.foo.dll does not exist
errors while compiling foo.v
PS D:\>

JalonSolov avatar Nov 24 '20 16:11 JalonSolov

Those paths look completely off

larpon avatar Nov 24 '20 19:11 larpon

The errors in Jalon's example seem to be caused by gcc/tcc building incorrect shared library on windows(.so instead of .dll), which have since been fixed, see https://github.com/vlang/v/issues/6940. I am not sure what caused the segfault though, could you verify on the latest build?

heronwr avatar Nov 25 '20 23:11 heronwr

Correct. It runs fine for me now, with latest V 0.1.29 e03ae19 using this gcc:

gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 10.2.0

JalonSolov avatar Nov 26 '20 00:11 JalonSolov

Hello @heronwr , I just upgraded to the latest version of v using v up and I have the same result:

PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> v version
V 0.1.29 e03ae19
PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> v -live run .\message.v
>       compilation cmd: C:\Users\Maxime\Documents\Workspace\Github\vlang\v\v.exe -cc msvc  -sharedlive -shared -o C:\\Users\\Maxime\\.cache/tmp.1.message .\message.v
compilation took: 653ms
> compile_and_reload_shared_lib compiled: C:\\Users\\Maxime\\.cache/tmp.1.message.dll
live mutex locking...
live mutex locked
> load_lib OK, new live_lib: 00007FFE24990000
live mutex unlocking...
live mutex unlocked
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live>

MangelMaxime avatar Nov 26 '20 08:11 MangelMaxime

I also tested -live using gcc

PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> gcc --version
gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 10.2.0

Live is working with -cc gcc with a a small bug, there is no newline added at the end of each messages:

PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> v -live -cc gcc run .\message.v
>       compilation cmd: C:\Users\Maxime\Documents\Workspace\Github\vlang\v\v.exe   -sharedlive -shared -o C:\\Users\\Maxime\\.cache/tmp.1.message .\message.v
compilation took: 2099ms
> compile_and_reload_shared_lib compiled: C:\\Users\\Maxime\\.cache/tmp.1.message.dll
live mutex locking...
live mutex locked
> load_lib OK, new live_lib: 0000000068100000
live mutex unlocking...
live mutex unlocked
Hello! Modify this message while the program is running.Hello! Modify this message while the program is running.Hello! Modify this message while the program is running.^C

If I run the v -cc gcc run message.v it does add the new lines.

In summary:

  • Hot reload using msvc does not work for me
  • Hot reload using gcc works but doesn't add the new line

MangelMaxime avatar Nov 26 '20 08:11 MangelMaxime

➜  v git:(master) ✗ v -cc msvc -live run main.v
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames

danieldaeschle avatar Jul 21 '21 22:07 danieldaeschle

I confirm, the hot reload does not work

v from master:

  1. v -cc mscv -live run .\examples\hot_reload\message.v produce: Unhandled Exception 0xC0000005 / C.CaptureStackBackTrace returned less than 2 frames

  2. v -cc gcc -live run .\examples\hot_reload\message.v produce: TCC/BCHECK: Error: function '__bt_init()' not found in executable. (Need -bt or -b for linking the exe.)

andorxornot avatar Aug 10 '21 13:08 andorxornot

still the same

andorxornot avatar Nov 23 '21 06:11 andorxornot

update in 2023: gcc works:

D:\github\v_test>v -g -cc gcc -live run src\main.v Please Modify this message while the program is running. Please Modify this message while the program is running. Please Modify this message while the program is running. Please Modify this message while the program is running.

msvc does not work:

D:\github\v_test>v -g -cc msvc -live run src\main.v Unhandled Exception 0xC0000005 C.CaptureStackBackTrace returned less than 2 frames signal 11: segmentation fault 6 : v_segmentation_fault_handler D:\github\v\vlib\builtin\builtin.c.v:26 5 : seh_filter_exe ?? : address = 0x21f44fbb350 4 : __scrt_common_main_seh'::1'::filt$0 D:\a_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304 3 : _C_specific_handler ?? : address = 0x21f44fbb620 2 : _chkstk ?? : address = 0x21f44fbbdf0 1 : RtlFindCharInUnicodeString ?? : address = 0x21f44fbaef0 0 : KiUserExceptionDispatcher ?? : address = 0x21f44fbb800

building v from git source

felixf4xu avatar Jun 16 '23 04:06 felixf4xu

I am seeing the same for msvc

> v -cg -cc msvc -live run .\src\main.v
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
signal 11: segmentation fault
6 : v_segmentation_fault_handler  c:\users\phcre\appdata\local\temp\v_0\main.7911469902052297126.tmp.c:8056
5 : seh_filter_exe             ?? : address = 0x1e4d7f3cdc0
4 : `__scrt_common_main_seh'::`1'::filt$0  d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304
3 : _C_specific_handler        ?? : address = 0x1e4d7f3c410
2 : _chkstk                    ?? : address = 0x1e4d7f3c690
1 : RtlRaiseException          ?? : address = 0x1e4d7f3c550
0 : KiUserExceptionDispatcher  ?? : address = 0x1e4d7f3d130

gcc here doesn't work on Windows 10

> gcc --version
gcc.exe (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) 13.1.0
> v -cg -cc gcc -live run .\src\main.v
...
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/phcre/AppData/Local/Temp/v_0/main.14353135948662305038.tmp.c:21248: undefined reference to `GC_init'
collect2.exe: error: ld returned 1 exit status
builder error:
==================
C error. This should never happen.
...

does -live not work with tcc?

phcreery avatar Jul 08 '23 03:07 phcreery

confirm on latest master

command: v -cc msvc -live run .\examples\hot_reload\message.v

produce:

Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
signal 11: segmentation fault
6 : print_backtrace_skipping_top_frames  ?? : address = 0x2473a022140
5 : seh_filter_exe             ?? : address = 0x2473a0220f0
4 : `__scrt_common_main_seh'::`1'::filt$0  D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304
3 : _C_specific_handler        ?? : address = 0x2473a021ed0
2 : _chkstk                    ?? : address = 0x2473a021f20
1 : RtlRaiseException          ?? : address = 0x2473a022190
0 : KiUserExceptionDispatcher  ?? : address = 0x2473a021f30

andorxornot avatar Feb 23 '24 14:02 andorxornot