diff --git a/Dockerfile b/Dockerfile index ac8126d..f276832 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,8 @@ # syntax=docker/dockerfile:1-labs FROM alpine AS downloader -ADD --checksum=sha256:86a88ed80ba42d581f2139bfdcf1a6debeec558e3379ef85e69297579c758241 https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz / -RUN tar xvf /libclang_rt.builtins-wasm32-wasi-16.0.tar.gz +ADD --checksum=sha256:c55b74f3109cdae97490faf089b0286d3bba926bb6ea5ed00c8c784fc53718fd https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-linux.tar.gz / +RUN tar xvf /binaryen-version_116-x86_64-linux.tar.gz -FROM "tinygo/tinygo:0.28.1" -COPY --from=downloader /lib/wasi/libclang_rt.builtins-wasm32.a /usr/local/tinygo/lib/wasi-libc/sysroot/lib/wasm32-wasi/ -COPY ./wasi.json /usr/local/tinygo/targets/wasi.json +FROM "tinygo/tinygo:0.30.0" +COPY --from=downloader binaryen-version_116/bin/wasm-opt /usr/local/tinygo/bin/wasm-opt diff --git a/Makefile b/Makefile index 9d2dfed..c5a3194 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,17 @@ -build: - docker run --rm -v ${PWD}:/src -w /src tinygo:patched tinygo build -x \ +build_0_29: + docker run --rm \ + -e GOPROXY=https://proxy.golang.org \ + -e GOSUMDB=sum.golang.org \ + -v ${PWD}:/src -w /src \ + tinygo/tinygo:0.29.0 tinygo build -x \ + -o policy.wasm \ + -target=wasi \ + -no-debug . + +build_0_30: + docker run --rm \ + -v ${PWD}:/src -w /src \ + tinygo/tinygo:0.30.0 tinygo build -x \ -o policy.wasm \ -target=wasi \ -no-debug . @@ -7,11 +19,8 @@ build: build-container: DOCKER_BUILDKIT=1 docker build . -t tinygo:patched -bug: - docker run --rm -v ${PWD}:/src -w /src tinygo/tinygo:0.27.0 tinygo build -x \ +build_patched: + docker run --rm -v ${PWD}:/src -w /src tinygo:patched tinygo build -x \ -o policy.wasm \ -target=wasi \ -no-debug . - -run: - wasmtime run policy.wasm diff --git a/README.md b/README.md index 0c11c73..9845f0f 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,50 @@ -This repository contains a small reproducer for a [this tinygo issue](https://github.com/tinygo-org/tinygo/issues/3501). +This repository contains a small reproducer for a [this tinygo issue](https://github.com/tinygo-org/tinygo/issues/4114). ## Requirements -* docker -* make +- docker +- make ## How to reproduce the issue Run the following command to reproduce the issue: ```console -make bug +make build_0_30 ``` The process will exit with an error similar to the following one: ```console -clang -mbulk-memory -mnontrapping-fptoint -msign-ext --sysroot=/usr/local/tinygo/lib/wasi-libc/sysroot -gdwarf-4 -Oz --target=wasm32-unknown-wasi -mcpu=generic -MD -MV -MTdeps -MF /tmp/tinygo4032866656/dep-2391943184.d -flto=thin -c -o /home/tinygo/.cache/tinygo/tmp-206382876.bc /usr/local/tinygo/src/internal/task/task_asyncify_wasm.S -Qunused-arguments -clang -mbulk-memory -mnontrapping-fptoint -msign-ext --sysroot=/usr/local/tinygo/lib/wasi-libc/sysroot -gdwarf-4 -Oz --target=wasm32-unknown-wasi -mcpu=generic -MD -MV -MTdeps -MF /tmp/tinygo4032866656/dep-2007613575.d -flto=thin -c -o /home/tinygo/.cache/tinygo/tmp-2933464424.bc /usr/local/tinygo/src/runtime/asm_tinygowasm.S -Qunused-arguments -wasm-ld --stack-first --no-demangle -L /usr/local/tinygo -o /tmp/tinygo4032866656/main --strip-debug --compress-relocations /tmp/tinygo4032866656/main.o /home/tinygo/.cache/tinygo/obj-0bfb1c88ecd5881542b47db010b5787164fc6a554d252cff6bd66805.bc /home/tinygo/.cache/tinygo/obj-21efc40633d7331a1c71e816bcdcc1a96f69a1f1969201b2c8be7b5f.bc /usr/local/tinygo/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a -mllvm -mcpu=generic --lto-O2 --thinlto-cache-dir=/home/tinygo/.cache/tinygo/thinlto -mllvm --rotation-max-header-size=0 -tinygo:wasm-ld: error: lto.tmp: undefined symbol: __multi3 -failed to run tool: wasm-ld -error: failed to link /tmp/tinygo4032866656/main: exit status 1 +[parse exception: invalid function index (at 0:33625)] ``` -## Dirty workaround +The error is raised by `wasm-opt`. -Build the container image that has the workaround: +The bug is currently happening with tinygo v0.30.0, which ships `wasm-opt` 114. + +I can reprodce the issue also with latest version of `wasm-opt` (v116): + +## Build with tinygo 0.29 + +The same error can be found with tinygo 0.29: ```console -make build-container +make build_0_29 ``` -This will create a container image named `tinygo:patched`. +## Use latest `wasm-opt` -Execute the following command: +Build the container based on tinygo 0.30.0 that has `wasm-opt` 116: ```console -make build +make build-container ``` -This time the build process will complete successfully. A WebAssembly module -named `policy.wasm` can be found inside of the root of the project. - -The module can be run with wasmtime: +Reproduce the issue: ```console -wasmtime run policy.wasm +make build_patched ``` + +The process will error in the same way.