Skip to content

Commit 0dd7698

Browse files
native: fix missing symbols CaptureStackBackTrace and __debugbreak (#23765)
1 parent af3f6c1 commit 0dd7698

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

vlib/v/gen/native/pe.v

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ fn (mut g Gen) gen_pe_idata() {
635635
]
636636

637637
for symbol in g.extern_symbols {
638-
sym := symbol.all_after('C.')
638+
mut sym := symbol.all_after('C.')
639639
mut found := false
640640
for mut dll in dlls {
641641
if sym in dll.exports {
@@ -645,6 +645,21 @@ fn (mut g Gen) gen_pe_idata() {
645645
}
646646
}
647647

648+
if !found {
649+
if sym == 'CaptureStackBackTrace' {
650+
sym = 'RtlCaptureStackBackTrace'
651+
} else if sym == '__debugbreak' {
652+
sym = 'DebugBreak'
653+
}
654+
for mut dll in dlls {
655+
if sym in dll.exports {
656+
found = true
657+
dll.exports[sym] = true
658+
break
659+
}
660+
}
661+
}
662+
648663
if !found {
649664
eprintln('could not find symbol `${sym}` in ${dll_files}')
650665
}

vlib/v/gen/native/readdll.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn (mut g Gen) lookup_system_dll(dll string) !SystemDll {
4949
}
5050
}
5151
} $else {
52-
// TODO: look into librarys dirs
52+
// TODO: look into library's dirs
5353
return SystemDll{
5454
name: dll
5555
}

vlib/v/gen/native/tests/native_test.v

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn test_native() {
1515
eprintln('>> skipping testing on FreeBSD/OpenBSD for now')
1616
return
1717
}
18+
1819
mut bench := benchmark.new_benchmark()
1920
vexe := os.getenv('VEXE')
2021
vroot := os.dir(vexe)
@@ -26,12 +27,14 @@ fn test_native() {
2627
defer {
2728
os.rmdir_all(wrkdir) or {}
2829
}
30+
2931
os.chdir(wrkdir) or {}
3032
tests := files.filter(it.ends_with('.vv'))
3133
if tests.len == 0 {
3234
println('no native tests found')
3335
assert false
3436
}
37+
3538
bench.set_total_expected_steps(tests.len)
3639
for test in tests {
3740
if test == 'libc.vv' {
@@ -41,6 +44,7 @@ fn test_native() {
4144
continue
4245
}
4346
}
47+
4448
bench.step()
4549
full_test_path := os.real_path(os.join_path(dir, test))
4650
test_file_name := os.file_name(test)
@@ -64,7 +68,6 @@ fn test_native() {
6468
err := os.read_file(tmperrfile) or { panic(err) }
6569
eprintln(err)
6670
}
67-
6871
continue
6972
}
7073

@@ -95,6 +98,7 @@ fn test_native() {
9598
errstr := os.read_file(tmperrfile) or {
9699
panic('${err}: ${os.quoted_path(exe_test_path)} 2> ${os.quoted_path(tmperrfile)}')
97100
}
101+
98102
mut err_found := errstr.trim_right('\r\n').replace('\r\n', '\n')
99103
if err_expected != err_found {
100104
println(term.red('FAIL'))
@@ -107,6 +111,7 @@ fn test_native() {
107111
continue
108112
}
109113
}
114+
110115
os.rm(tmperrfile) or {}
111116
expected = expected.trim_right('\r\n').replace('\r\n', '\n')
112117
mut found := res.output.trim_right('\r\n').replace('\r\n', '\n')
@@ -123,7 +128,8 @@ fn test_native() {
123128
}
124129
bench.ok()
125130
eprintln(bench.step_message_ok('${relative_test_path:-45} , took ${compile_time_ms:4}ms to compile, ${runtime_ms:4}ms to run'))
126-
}
131+
} // for loop
132+
127133
bench.stop()
128134
eprintln(term.h_divider('-'))
129135
eprintln(bench.total_message('native'))

vlib/v/gen/native/tests/pe_test.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module tests
2+
3+
import os
4+
5+
fn test_prevent_could_not_find_symbols_regression() {
6+
res := os.execute('${os.quoted_path(@VEXE)} -b native examples/hello_world.v')
7+
assert !res.output.contains('CaptureStackBackTrace'), 'Test failed system unable to find symbol: CaptureStackBackTrace'
8+
assert !res.output.contains('__debugbreak'), 'Test failed system unable to find symbol: __debugbreak'
9+
}

0 commit comments

Comments
 (0)