wasmer-go icon indicating copy to clipboard operation
wasmer-go copied to clipboard

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

Open WeiZhang555 opened this issue 4 years ago β€’ 2 comments

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
  1. In my own project, "wasmer-go" master code is vendored, commit id: 72b0251581c7
  2. 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!

WeiZhang555 avatar Jul 20 '21 07:07 WeiZhang555

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?

Hywan avatar Aug 12 '21 10:08 Hywan

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

soulteary avatar Nov 21 '21 05:11 soulteary