From 2b808880f73948e12d8321e107bcab07cd438601 Mon Sep 17 00:00:00 2001 From: David Legrand Date: Tue, 28 Apr 2026 15:30:29 +0200 Subject: [PATCH] builtin, toml: enable ALL_INTERIOR_POINTERS for bundled libgc; drop toml.ast_to_any GC wrap (#27007) --- thirdparty/libgc/gc.c | 9 +++++++++ vlib/builtin/builtin_d_gcboehm.c.v | 8 +++++++- vlib/toml/toml.v | 4 ---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/thirdparty/libgc/gc.c b/thirdparty/libgc/gc.c index 6d5e87acd..27b3c1d84 100644 --- a/thirdparty/libgc/gc.c +++ b/thirdparty/libgc/gc.c @@ -31,6 +31,15 @@ * file). */ +/* + * V note: the bundled libgc must be compiled with `-DALL_INTERIOR_POINTERS=1` + * (set in `vlib/builtin/builtin_d_gcboehm.c.v`). Without it, the conservative + * collector misses interior pointers into GC-allocated buffers — sumtype + * payloads referenced via offset (e.g. `toml.ast_to_any`, `yaml.Any.to_json`) + * get reclaimed mid-walk and `-gc boehm` builds crash with `signal 11`. + * Keep this requirement in sync when re-amalgamating from bdwgc. + */ + #define GC_SINGLE_OBJ_BUILD #ifndef __cplusplus diff --git a/vlib/builtin/builtin_d_gcboehm.c.v b/vlib/builtin/builtin_d_gcboehm.c.v index 549825d13..6ecb775b2 100644 --- a/vlib/builtin/builtin_d_gcboehm.c.v +++ b/vlib/builtin/builtin_d_gcboehm.c.v @@ -7,6 +7,7 @@ $if !no_gc_threads ? { $if use_bundled_libgc ? { #flag -DGC_BUILTIN_ATOMIC=1 #flag -I @VEXEROOT/thirdparty/libgc/include + #flag -DALL_INTERIOR_POINTERS=1 #flag @VEXEROOT/thirdparty/libgc/gc.o } @@ -23,6 +24,7 @@ $if dynamic_boehm ? { #flag -DGC_WIN32_THREADS=1 #flag -DGC_BUILTIN_ATOMIC=1 #flag -I @VEXEROOT/thirdparty/libgc/include + #flag -DALL_INTERIOR_POINTERS=1 #flag @VEXEROOT/thirdparty/libgc/gc.o } } $else { @@ -48,6 +50,7 @@ $if dynamic_boehm ? { #flag -I @VEXEROOT/thirdparty/libgc/include $if (prod && !tinyc && !debug) || !(amd64 || arm64 || i386 || arm32 || rv64) { // TODO: replace the architecture check with a `!$exists("@VEXEROOT/thirdparty/tcc/lib/libgc.a")` comptime call + #flag -DALL_INTERIOR_POINTERS=1 #flag @VEXEROOT/thirdparty/libgc/gc.o } $else { $if !use_bundled_libgc ? { @@ -95,6 +98,7 @@ $if dynamic_boehm ? { #flag -DGC_BUILTIN_ATOMIC=1 $if !tinyc { #flag -I @VEXEROOT/thirdparty/libgc/include + #flag -DALL_INTERIOR_POINTERS=1 #flag @VEXEROOT/thirdparty/libgc/gc.o } $if tinyc { @@ -123,10 +127,12 @@ $if dynamic_boehm ? { #flag -I @VEXEROOT/thirdparty/libatomic_ops #flag -I @VEXEROOT/thirdparty/libgc/include + #flag -DALL_INTERIOR_POINTERS=1 #flag @VEXEROOT/thirdparty/libgc/gc.o } $else { #flag -DGC_BUILTIN_ATOMIC=1 #flag -I @VEXEROOT/thirdparty/libgc/include + #flag -DALL_INTERIOR_POINTERS=1 #flag @VEXEROOT/thirdparty/libgc/gc.o } } $else $if $pkgconfig('bdw-gc') { @@ -180,7 +186,7 @@ fn C.GC_set_no_dls(i32) // protect memory block from being freed before this call fn C.GC_reachable_here(voidptr) -// gc_is_enabled() returns true, if the GC is enabled at runtime. +// gc_is_enabled returns true, if the GC is enabled at runtime. // See also gc_disable() and gc_enable(). pub fn gc_is_enabled() bool { return 0 == C.GC_is_disabled() diff --git a/vlib/toml/toml.v b/vlib/toml/toml.v index 1876119e3..c87f7c9dc 100644 --- a/vlib/toml/toml.v +++ b/vlib/toml/toml.v @@ -518,10 +518,6 @@ fn (d Doc) value_(value ast.Value, key []string) Any { // ast_to_any converts `from` ast.Value to toml.Any value. pub fn ast_to_any(value ast.Value) Any { - gc_disable() - defer { - gc_enable() - } return ast_to_any_(value) } -- 2.39.5