Skip to content

wasm-ld: duplicate symbol: wasi_thread_start #22096

@MichaelBelousov

Description

@MichaelBelousov

Zig Version

0.14.0-dev.2293+6d781e095

Steps to Reproduce and Observed Behavior

build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    const web_target_query = std.Target.Query{
        .cpu_arch = .wasm32,
        .os_tag = .wasi,
        .cpu_features_add = std.Target.wasm.featureSet(&.{
            .atomics,
            .multivalue,
            .bulk_memory,
        }),
    };
    const optimize = b.standardOptimizeOption(.{});
    const lib = b.addStaticLibrary(.{
        .name = "zig-cxx-wasi-lib",
        .root_source_file = b.path("src/lib.zig"),
        .target = b.resolveTargetQuery(web_target_query),
        .optimize = optimize,
        .single_threaded = false,
    });
    lib.linkLibCpp();
    b.installArtifact(lib);

    const mod = b.addModule("lib-mod", .{
        .root_source_file = b.path("src/mod.zig"),
        .target = b.resolveTargetQuery(web_target_query),
        .optimize = optimize,
        .single_threaded = false,
    });
    mod.linkLibrary(lib);

    const exe = b.addExecutable(.{
        .name = "zig-cxx-wasi-exe",
        .root_source_file = b.path("src/main.zig"),
        .target = b.resolveTargetQuery(web_target_query),
        .optimize = optimize,
        .single_threaded = false,
    });
    exe.root_module.addImport("mod", mod);

    b.installArtifact(exe);
}

src/lib.zig

pub export fn add(a: i32, b: i32) i32 {
    return a + b;
}

src/mod.zig

pub extern fn add(i32, i32) i32;

src/main.zig

const mod = @import("mod");
pub fn main() u8 {
    return @intCast(mod.add(1, 2));
}

assemble the above files and then run zig build in the directory you assembled them in.

This will output an error like:

error: wasm-ld: duplicate symbol: wasi_thread_start
    note: defined in /home/mike/mvrs/zig-cxx-wasi/.zig-cache/o/a66544b7097a736565165b8f9d7ebcea/libzig-cxx-wasi-lib.a(/home/mike/mvrs/zig-cxx-wasi/.zig-cache/o/a66544b7097a736565165b8f9d7ebcea/libzig-cxx-wasi-lib.a.o)
    note: defined in /home/mike/mvrs/zig-cxx-wasi/.zig-cache/o/7233252840d82cbad150a05f118d4272/zig-cxx-wasi-exe.wasm.o

Expected Behavior

For the program to link with only one copy of wasm_thread_start... I think...

I'm not completely sure on the expected semantics but I'm building a lib and linking it to a module in one project, then depending upon that module in an exe in another project. But as seen here that fails.

There may be a separate problem where libcxx doesn't build for wasm32-wasm without all the threading options I've added, but it seems on my machine I can actually remove all extra wasm features and single_threading=false and you still get this error if your target is wasi

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasm32-bit and 64-bit WebAssemblybugObserved behavior contradicts documented or intended behavioros-wasiWebAssembly System Interface

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions