wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.84k stars 161 forks source link

cgo static build failed of "undefined reference to `__longjmp_chk'" #288

Open WeiZhang555 opened 3 years ago

WeiZhang555 commented 3 years ago

Describe the bug

wasmer-go is vendored in my private golang project, for removing unnecessary dependencies, I was trying to build my project with wasmer in cgo static build mode but failed, can you give me some guide how to make it work?

Steps to reproduce

  1. Download github.com/wasmerio/wasmer, cd wasmer dir, git checkout -b v2.0.0 2.0.0 switch to 2.0.0 release.
  2. run make to compile, got result as
    $ ls -l target/release/
    total 105164
    drwxrwxr-x 83 zhangwei zhangwei     4096 7月  20 12:18 build
    drwxrwxr-x  2 zhangwei zhangwei    61440 7月  20 15:06 deps
    drwxrwxr-x  2 zhangwei zhangwei     4096 7月  20 12:13 examples
    drwxrwxr-x  2 zhangwei zhangwei     4096 7月  20 12:13 incremental
    -rw-rw-r--  2 zhangwei zhangwei 65665232 7月  20 15:06 libwasmer_c_api.a
    -rw-rw-r--  1 zhangwei zhangwei    21444 7月  20 13:08 libwasmer_c_api.d
    -rw-rw-r--  2 zhangwei zhangwei  2604244 7月  20 15:06 libwasmer_c_api.rlib
    -rwxrwxr-x  2 zhangwei zhangwei 15421464 7月  20 15:06 libwasmer_c_api.so
    -rwxrwxr-x  2 zhangwei zhangwei 23861096 7月  20 15:02 wasmer
    -rw-rw-r--  1 zhangwei zhangwei    23199 7月  20 12:18 wasmer.d
  3. In my own project, "wasmer-go" master code is vendored, commit id: 72b0251581c7
  4. Compile my own code in my Makefile with command
    CGO_CFLAGS="-I/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/lib/c-api/" \
    CGO_LDFLAGS="-Wl,-rpath,/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release/ -L/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release/ -pthread -lwasmer_c_api -lm -ldl -static" \
    CC=/usr/bin/musl-gcc \
    go build -mod vendor -tags custom_wasmer_runtime -ldflags "-X xxx.GitCommit="xxx" -X xxx.Version=xxx"  -o <bin> .

Expected behavior

The compilation should succeed and binary should be compiled as static.

Actual behavior

Got compilation error:

# github.com/wasmerio/wasmer-go/wasmer
/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release//libwasmer_c_api.a(handlers.o): In function `wasmer_unwind':
handlers.c:(.text.wasmer_unwind+0xa): undefined reference to `__longjmp_chk'
/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release//libwasmer_c_api.a(std-b1047a2788193be4.std.b9wtcb8n-cgu.0.rcgu.o): In function `std::sys::unix::net::on_resolver_failure':
/rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0//library/std/src/sys/unix/net.rs:453: undefined reference to `__res_init'
collect2: error: ld returned 1 exit status
Makefile:26: recipe for target 'bin' failed
make: *** [bin] Error 2

Can you give me some tips how to make it work? Thanks in advance!

Hywan commented 3 years ago

Hello,

Thank you for the detailed bug report. Can you please provide me your platform (OS) and architecture (CPU)? I see you're using musl. Did you compile Wasmer with LIBC=musl?

soulteary commented 3 years ago

Hello,

Thank you for the detailed bug report. Can you please provide me your platform (OS) and architecture (CPU)? I see you're using musl. Did you compile Wasmer with LIBC=musl?

Do you consider providing users with a universal container environment so that everyone can reproduce the problem? @Hywan