From ebc55063c0136d545cecdc1c2f3ed385076c236a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 27 May 2026 21:59:36 +0300 Subject: [PATCH] builder: cc fixes --- vlib/v/builder/cc.v | 6 +++++ vlib/v/builder/cc_test.v | 26 +++++++++++++++++++ .../v/tests/shared_library_system_link_test.v | 6 ++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index cc6a2f0bb..c4c990f1b 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -793,6 +793,12 @@ fn (mut v Builder) setup_ccompiler_options(ccompiler string) { // This avoids cross-DSO symbol interposition between multiple V binaries // in one process (for example, host executable + loaded V plugin). ccoptions.linker_flags << '-Wl,-Bsymbolic' + if ccoptions.cc != .tcc { + // Do not leak symbols from the statically linked libgc archive into + // the shared library ABI. Only functions explicitly tagged with + // @[export] should be visible. + ccoptions.linker_flags << '-Wl,--exclude-libs,ALL' + } } } if v.pref.is_bare && v.pref.os != .wasm32 { diff --git a/vlib/v/builder/cc_test.v b/vlib/v/builder/cc_test.v index 464b0ccfd..fe3ee5fed 100644 --- a/vlib/v/builder/cc_test.v +++ b/vlib/v/builder/cc_test.v @@ -481,6 +481,32 @@ fn test_shared_tcc_compile_args_skip_bt25_after_late_compiler_resolution() { assert !builder.get_compile_args().contains('-bt25') } +fn test_linux_shared_boehm_linker_args_hide_static_gc_archive_symbols() { + linker_args := builder_linker_args_with_cc([ + '-os', + 'linux', + '-shared', + '-gc', + 'boehm', + hello_world_example(), + ], .gcc) + assert linker_args.contains('-Wl,-Bsymbolic') + assert linker_args.contains('-Wl,--exclude-libs,ALL') +} + +fn test_linux_shared_boehm_tcc_linker_args_skip_gnu_exclude_libs() { + linker_args := builder_linker_args_with_cc([ + '-os', + 'linux', + '-shared', + '-gc', + 'boehm', + hello_world_example(), + ], .tcc) + assert linker_args.contains('-Wl,-Bsymbolic') + assert !linker_args.contains('-Wl,--exclude-libs,ALL') +} + fn test_should_use_rsp_for_linux_by_default() { builder := new_test_builder([hello_world_example()]) assert builder.should_use_rsp(['-o', builder.out_name_c]) diff --git a/vlib/v/tests/shared_library_system_link_test.v b/vlib/v/tests/shared_library_system_link_test.v index 03795b2fb..0a1b87bf3 100644 --- a/vlib/v/tests/shared_library_system_link_test.v +++ b/vlib/v/tests/shared_library_system_link_test.v @@ -55,9 +55,9 @@ fn test_shared_library_only_exports_tagged_symbols() { if uos !in ['linux', 'macos'] { return } - // tcc on macOS does not honor `-fvisibility=hidden`, so the symbol-set check - // would be noisy there; rely on Linux + a `-cc clang` path on macOS. - cc_flag := if uos == 'macos' { '-cc clang' } else { '' } + // tcc does not honor `-fvisibility=hidden`, so the symbol-set check would be + // noisy there; use a system compiler for Linux and clang on macOS. + cc_flag := if uos == 'macos' { '-cc clang' } else { '-cc cc' } workdir := os.join_path(os.vtmp_dir(), 'v_shared_visibility_${rand.ulid()}') os.mkdir_all(workdir) or { panic(err) } defer { -- 2.39.5