@@ -184,6 +184,23 @@ fn (mut p Preferences) prefer_openssl_for_bsd_tinyc() {
184184 }
185185}
186186
187+ fn (p &Preferences) needs_source_boehm_without_thread_local_alloc () bool {
188+ return p.gc_mode in [.boehm_full, .boehm_incr, .boehm_full_opt, .boehm_incr_opt, .boehm_leak]
189+ && 'no_gc_thread_local_alloc' in p.compile_defines_all
190+ && 'dynamic_boehm' ! in p.compile_defines_all
191+ }
192+
193+ fn (mut p Preferences) prefer_source_boehm_without_thread_local_alloc () {
194+ if ! p.needs_source_boehm_without_thread_local_alloc ()
195+ || 'use_bundled_libgc' in p.compile_defines_all {
196+ return
197+ }
198+ // The prebuilt bundled libgc archives are built with thread-local allocation.
199+ // Use the bundled source path instead, so builtin_d_gcboehm.c.v can omit
200+ // -DTHREAD_LOCAL_ALLOC while still keeping GC_THREADS enabled.
201+ p.parse_define ('use_bundled_libgc' )
202+ }
203+
187204// fill_with_defaults initializes unset preferences and derives build options from them.
188205pub fn (mut p Preferences) fill_with_defaults () {
189206 p.setup_os_and_arch_when_not_explicitly_set ()
@@ -273,6 +290,7 @@ pub fn (mut p Preferences) fill_with_defaults() {
273290 }
274291 p.ccompiler_type = cc_from_string (p.ccompiler)
275292 p.normalize_gc_defaults_for_resolved_ccompiler ()
293+ p.prefer_source_boehm_without_thread_local_alloc ()
276294 p.is_test = p.path.ends_with ('_test.v' ) || p.path.ends_with ('_test.vv' )
277295 || p.path.all_before_last ('.v' ).all_before_last ('.' ).ends_with ('_test' )
278296 p.is_vsh = p.path.ends_with ('.vsh' ) || p.raw_vsh_tmp_prefix != ''
@@ -449,6 +467,12 @@ fn (mut p Preferences) try_to_use_tcc_by_default() {
449467 if p.prealloc {
450468 return
451469 }
470+ // -d no_gc_thread_local_alloc forces the bundled source libgc path. The
471+ // bundled tcc cannot compile that source reliably, so use the platform C
472+ // compiler by default. An explicit -cc still wins.
473+ if p.needs_source_boehm_without_thread_local_alloc () {
474+ return
475+ }
452476 // use an optimizing compiler (i.e. gcc or clang) on -prod mode
453477 if p.is_prod {
454478 return
@@ -546,10 +570,10 @@ fn (mut p Preferences) clear_gc_options() {
546570pub fn (mut p Preferences) default_c_compiler () {
547571 // TODO: fix $if after 'string'
548572 $if windows {
549- // -prealloc and -prod intentionally avoid the bundled tcc (see
573+ // These modes intentionally avoid bundled tcc (see
550574 // try_to_use_tcc_by_default); preserve that here so the Windows fallback
551575 // does not silently re-select an incompatible compiler.
552- if p.prealloc || p.is_prod {
576+ if p.prealloc || p.is_prod || p. needs_source_boehm_without_thread_local_alloc () {
553577 p.ccompiler = 'gcc'
554578 return
555579 }
0 commit comments