Closed flavio closed 1 year ago
We bundle compiler-rt for TinyGo. Normally it's as simple as this:
--- a/targets/wasi.json
+++ b/targets/wasi.json
@@ -6,6 +6,7 @@
"goos": "linux",
"goarch": "arm",
"linker": "wasm-ld",
+ "rtlib": "compiler-rt",
"libc": "wasi-libc",
"scheduler": "asyncify",
"default-stack-size": 16384,
...but not this time, because wasm-ld needs a symbol table in the archive file and our archive creation code doesn't support that yet. So it needs some additions to builder/ar.go.
Just hit this myself while testing:
~/go/src/github.com/RoaringBitmap/roaring $ tinygo test -tags="purego" -target=wasi
tinygo:wasm-ld: error: lto.tmp: undefined symbol: __multi3
failed to run tool: wasm-ld
FAIL github.com/RoaringBitmap/roaring 0.000s
error: failed to link /var/folders/5b/_hr1d1fd3qn4t9vtfx5p61wm0000gp/T/tinygo3620564764/main: exit status 1
Also just recently hit this bug. Not much context to be added compared to whats already here. Happened in a currently private repo.
If someone would like to fix this bug, this is what needs to be done:
"rtlib": "compiler-rt"
to targets/wasi.json.tinygo clean
followed by tinygo build
or tinygo run
.Closing since this is part of release 0.29.0 thanks!
I ran into this linker issue when trying to build some Go code:
This happens with tinygo version 0.27.0, using the official container image. I can reproduce it also with tinygo built from the
dev
branch.Root cause
The
__multi3
symbol is provided by thelibclang_rt.builtins-wasm32.a
library, which, from what I understand, is not built by default bywasi-libc
.Quoting the official
README
:Each wasi-sdk release includes the pre-built library as one of its release artifacts.
Dirty workaround
Starting from the tinygo official container image, I added the
libclang_rt.builtins-wasm32.a
library provided by thewasi-sdk-16
release. This is the version of wasi-sdk used by tinygo 0.27.0.Then I patched the linker section of the
wasi.json
target to make use of this library:I couldn't find a way to avoid this change. I tried using different CGO environment variables, but none of them was being used.
Reproducer
I created this repository that contains:
Dockerfile
used to build the "patched" tinygo container imagewasi.json
target file