Skip to content

Commit 2b80888

Browse files
authored
builtin, toml: enable ALL_INTERIOR_POINTERS for bundled libgc; drop toml.ast_to_any GC wrap (#27007)
1 parent f36bff1 commit 2b80888

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

thirdparty/libgc/gc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
* file).
3232
*/
3333

34+
/*
35+
* V note: the bundled libgc must be compiled with `-DALL_INTERIOR_POINTERS=1`
36+
* (set in `vlib/builtin/builtin_d_gcboehm.c.v`). Without it, the conservative
37+
* collector misses interior pointers into GC-allocated buffers — sumtype
38+
* payloads referenced via offset (e.g. `toml.ast_to_any`, `yaml.Any.to_json`)
39+
* get reclaimed mid-walk and `-gc boehm` builds crash with `signal 11`.
40+
* Keep this requirement in sync when re-amalgamating from bdwgc.
41+
*/
42+
3443
#define GC_SINGLE_OBJ_BUILD
3544

3645
#ifndef __cplusplus

vlib/builtin/builtin_d_gcboehm.c.v

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $if !no_gc_threads ? {
77
$if use_bundled_libgc ? {
88
#flag -DGC_BUILTIN_ATOMIC=1
99
#flag -I @VEXEROOT/thirdparty/libgc/include
10+
#flag -DALL_INTERIOR_POINTERS=1
1011
#flag @VEXEROOT/thirdparty/libgc/gc.o
1112
}
1213

@@ -23,6 +24,7 @@ $if dynamic_boehm ? {
2324
#flag -DGC_WIN32_THREADS=1
2425
#flag -DGC_BUILTIN_ATOMIC=1
2526
#flag -I @VEXEROOT/thirdparty/libgc/include
27+
#flag -DALL_INTERIOR_POINTERS=1
2628
#flag @VEXEROOT/thirdparty/libgc/gc.o
2729
}
2830
} $else {
@@ -48,6 +50,7 @@ $if dynamic_boehm ? {
4850
#flag -I @VEXEROOT/thirdparty/libgc/include
4951
$if (prod && !tinyc && !debug) || !(amd64 || arm64 || i386 || arm32 || rv64) {
5052
// TODO: replace the architecture check with a `!$exists("@VEXEROOT/thirdparty/tcc/lib/libgc.a")` comptime call
53+
#flag -DALL_INTERIOR_POINTERS=1
5154
#flag @VEXEROOT/thirdparty/libgc/gc.o
5255
} $else {
5356
$if !use_bundled_libgc ? {
@@ -95,6 +98,7 @@ $if dynamic_boehm ? {
9598
#flag -DGC_BUILTIN_ATOMIC=1
9699
$if !tinyc {
97100
#flag -I @VEXEROOT/thirdparty/libgc/include
101+
#flag -DALL_INTERIOR_POINTERS=1
98102
#flag @VEXEROOT/thirdparty/libgc/gc.o
99103
}
100104
$if tinyc {
@@ -123,10 +127,12 @@ $if dynamic_boehm ? {
123127
#flag -I @VEXEROOT/thirdparty/libatomic_ops
124128

125129
#flag -I @VEXEROOT/thirdparty/libgc/include
130+
#flag -DALL_INTERIOR_POINTERS=1
126131
#flag @VEXEROOT/thirdparty/libgc/gc.o
127132
} $else {
128133
#flag -DGC_BUILTIN_ATOMIC=1
129134
#flag -I @VEXEROOT/thirdparty/libgc/include
135+
#flag -DALL_INTERIOR_POINTERS=1
130136
#flag @VEXEROOT/thirdparty/libgc/gc.o
131137
}
132138
} $else $if $pkgconfig('bdw-gc') {
@@ -180,7 +186,7 @@ fn C.GC_set_no_dls(i32)
180186
// protect memory block from being freed before this call
181187
fn C.GC_reachable_here(voidptr)
182188

183-
// gc_is_enabled() returns true, if the GC is enabled at runtime.
189+
// gc_is_enabled returns true, if the GC is enabled at runtime.
184190
// See also gc_disable() and gc_enable().
185191
pub fn gc_is_enabled() bool {
186192
return 0 == C.GC_is_disabled()

vlib/toml/toml.v

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,6 @@ fn (d Doc) value_(value ast.Value, key []string) Any {
518518

519519
// ast_to_any converts `from` ast.Value to toml.Any value.
520520
pub fn ast_to_any(value ast.Value) Any {
521-
gc_disable()
522-
defer {
523-
gc_enable()
524-
}
525521
return ast_to_any_(value)
526522
}
527523

0 commit comments

Comments
 (0)