Skip to content

build: replace Wasmtime symbol-prefixing patch with privately_linked_cc_library - #568

Open
leonm1 wants to merge 2 commits into
proxy-wasm:mainfrom
leonm1:remove_wasmtime_symbol_prefixing
Open

leonm1 wants to merge 2 commits into
proxy-wasm:mainfrom
leonm1:remove_wasmtime_symbol_prefixing

Conversation

@leonm1

@leonm1 leonm1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Partially link wasmtime using symbol localization via privately_linked_cc_library bazel macro. Permits multiple runtimes to be compiled into the same binary without symbol renaming.

Wasmtime exposes wasm_c_api headers and symbols that collide with other wasm_c_api runtimes (such as V8/wee8) when multiple engines are linked into the same binary (--define engine=multi). Previously, we patched Wasmtime's headers and rewrote its compiled library to redefine symbols to wasmtime_wasm_*. Now, we:

  • Compile library sources against unpatched private_deps headers with linkstatic = True.
  • Partially links compiled sources and static archives from private_deps into a single relocatable object file and localizes all symbols outside public_symbols ("proxy_wasm"):
  • Wraps wasmtime-c-api-impl directly via rust_static_library in wasmtime.BUILD instead of patching out the main.rs.

TAG=agy

Signed-off-by: Matt Leon mattleon@google.com

@leonm1
leonm1 force-pushed the remove_wasmtime_symbol_prefixing branch from 08ddcb3 to 21d4363 Compare November 20, 2026 21:13
…tic-llvm

Newer host glibc headers (C23 const-preserving generic macros in <string.h>,
such as strchr/memchr) return const-qualified pointers when given const inputs,
triggering -Wincompatible-pointer-types-discards-qualifiers (promoted to an
error by -Werror) when compiling C dependencies like @boringssl//:crypto under
--config=hermetic-llvm.

TAG=agy

Signed-off-by: Matt Leon <mattleon@google.com>
…cc_library

Partially link wasmtime using symbol localization via
privately_linked_cc_library bazel macro. Permits multiple runtimes to be
compiled into the same binary without symbol renaming.

Wasmtime exposes wasm_c_api headers and symbols that collide with other
wasm_c_api runtimes (such as V8/wee8) when multiple engines are linked
into the same binary (--define engine=multi). Previously, we patched
Wasmtime's headers and rewrote its compiled library to redefine symbols
to wasmtime_wasm_*. Now, we:

- Compile library sources against unpatched private_deps headers with
  linkstatic = True.
- Partially links compiled sources and static archives from private_deps
  into a single relocatable object file and localizes all symbols
  outside public_symbols ("*proxy_wasm*"):
- Wraps wasmtime-c-api-impl directly via rust_static_library in
  wasmtime.BUILD instead of patching out the main.rs.

TAG=agy

Signed-off-by: Matt Leon <mattleon@google.com>
@leonm1
leonm1 force-pushed the remove_wasmtime_symbol_prefixing branch from 21d4363 to b8fbb96 Compare November 20, 2026 21:14
exported_symbol_flags = exported_symbol_flags,
out = out_o.path,
)
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, the branch here on macos vs. ELF leaves out Windows, even though elsewhere we still attempt to support Windows builds (e.g. BUILD lines 212-220). I think this hasn't shown up in CI since the only Windows job in CI currently builds with engine=null.

A minimal adjustment to avoid breaking Windows for single-engine builds could be to have privately_linked_cc_library select the privatized .o on Linux/macOS and fall back to the plain _unprivatized_lib on @platforms//os:windows. Or, we could gate privatization as a whole on @proxy_wasm_cpp_host//bazel:multiengine--WDYT?

])
command = """
set -e
{cc} -r -nostdlib -Wl,--whole-archive {libs} -Wl,--no-whole-archive -o {out}.tmp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This direct cc invocation omits any configured cc_toolchain flags.

# STB_GLOBAL STV_HIDDEN SHN_COMMON symbol. Demoting a SHN_COMMON
# symbol to STB_LOCAL causes ld.lld to fail with an invalid relocation
# against an absolute symbol, and ld.lld -r ignores -d.
keep_global_patterns = ctx.attr.public_symbols + ["___asan_globals_registered"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI analysis claims that the current blanket demotion of all non-matching symbols to object-file-local will cause function-local statics in inline functions in headers to be duplicated.

TBH I don't know whether there is much practical impact, but it contributes to an overall impression that these linker tricks could have subtle side effects, which might argue for limiting them to where strictly necessary (i.e. the multi-engine build), and leaving single-engine Wasmtime build as-is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants