Skip to content

wasi, libc: cache lib/c as libzigc.a and fix reactor exports (#130) - #136

Merged
cataggar merged 1 commit into
wazigfrom
fix/wasi-libzigc-archive-130
Nov 4, 2026
Merged

cataggar merged 1 commit into
wazigfrom
fix/wasi-libzigc-archive-130

Conversation

@cataggar

@cataggar cataggar commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Cache lib/c as libzigc.a on WASI (zigc_strat = .lib):
    • In src/Compilation.zig, use zigc_strat = .lib when target.isWasiLibC() instead of compiling all 2,157 @exports in lib/c into every user ZCU.
    • In src/link/Lld.zig (wasmLink), move libcxxabi.a, libcxx.a, and libzigc.a after user/C/ZCU objects (and right before compiler_rt), matching elfLink.
  • Fix WASI reactor builds and leaked globals:
    • In lib/c/wasi_sources.zig, change __main_argc_argv in mainVoidImpl from a strong extern fn to a weak @extern (matching wasi-libc).
    • In lib/c/internal.zig and lib/c/misc.zig, set .visibility = if (builtin.object_format == .wasm) .hidden else .default on __progname, __progname_full, program_invocation_short_name, program_invocation_name, and optarg so they do not leak into -rdynamic Wasm exports.
  • Self-hosted Wasm linker (src/link/Wasm*) archive & weak-symbol fixes:
    • Guard SymbolFlags.isIncluded (is_dynamic and !flags.visibility_hidden) with !flags.undefined so -rdynamic does not mark unreferenced undefined archive imports alive during prelink().
    • Only check module_name/name mismatches in Object.zig when gop.value_ptr.resolution == .unresolved.
    • Process nav_exports/uav_exports before resolving ZCU imports against object_function_imports/object_data_imports in Flush.zig, keep shared unresolved imports in f.function_imports/f.data_imports, and give strong ZCU exports precedence over weak archive symbols.

Closes #130

@cataggar
cataggar enabled auto-merge (squash) November 4, 2026 00:20
- Switch WASI -lc builds from zigc_strat = .zcu to .lib so lib/c is compiled
  and cached once as libzigc.a instead of compiling 2,157 @exports into
  every user ZCU.
- Place libcxxabi.a, libcxx.a, and libzigc.a after user/ZCU objects in
  Lld.wasmLink (matching elfLink) while keeping crt1-*.o before user objects.
- Declare __main_argc_argv as a weak @extern in lib/c/wasi_sources.zig
  mainVoidImpl and hide __progname* and optarg on WebAssembly targets so
  -rdynamic reactor builds do not fail or leak internal globals.
- Fix self-hosted Wasm linker (src/link/Wasm*): guard SymbolFlags.isIncluded
  with !flags.undefined for -rdynamic, skip module_name mismatch checks on
  already-resolved symbols in Object.zig, preserve shared unresolved WASI
  imports in Flush.zig, and allow strong ZCU exports to override weak
  archive symbols.

Closes #130

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@cataggar
cataggar merged commit ca181af into wazig Nov 4, 2026
2 checks passed
@cataggar
cataggar deleted the fix/wasi-libzigc-archive-130 branch November 4, 2026 00:29
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.

libzigc (lib/c): cache as libzigc.a on WASI instead of compiling 2,100+ @exports into every user ZCU, and fix reactor exports

1 participant