wasi-sdk
wasi-sdk copied to clipboard
Autotools project fails to compile with -save-temps
Hello, I am trying to compile libsodium which has a shell script to build with WebAssembly support, using wasi-sdk.
The script executes correctly by default but when I try to add -save-temps
to the CFLAGS, compilation stops after a bit with the following error:
CC crypto_onetimeauth/poly1305/libsodium_la-onetimeauth_poly1305.lo
CC crypto_onetimeauth/poly1305/donna/libsodium_la-poly1305_donna.lo
CC crypto_pwhash/argon2/libsodium_la-argon2-core.lo
CC crypto_pwhash/argon2/libsodium_la-argon2-encoding.lo
CC crypto_pwhash/argon2/libsodium_la-argon2-fill-block-ref.lo
CC crypto_pwhash/argon2/libsodium_la-argon2.lo
CC crypto_pwhash/argon2/libsodium_la-blake2b-long.lo
onetimeauth_poly1305.s:15:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32, i64, i32) -> (i32)
^
onetimeauth_poly1305.s:33:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32, i64, i32) -> (i32)
^
onetimeauth_poly1305.s:49:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32) -> (i32)
^
onetimeauth_poly1305.s:66:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32, i64) -> (i32)
^
onetimeauth_poly1305.s:82:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32) -> (i32)
I have confirmed that if I remove wasi-sdk and compile without a wasm target & modified sysroot, compilation works with -save-temps
and I can see the temporary files as a result.
To illustrate, I have created 2 docker files for easy reproduction: https://gist.github.com/orestisfl/5b5b333d5da7001dc799abea719ad9cf
One patches out wasi-sdk from the script and adds -save-temps
and one that just adds the -save-temps
flag to $CFLAGS
.
$ curl https://gist.githubusercontent.com/orestisfl/5b5b333d5da7001dc799abea719ad9cf/raw/bec7b18fb231bd768b42bcef82851e103b7333b5/remove-wasi.Dockerfile | docker build -t tmp - && docker run tmp
… succeeds
$ curl https://gist.githubusercontent.com/orestisfl/5b5b333d5da7001dc799abea719ad9cf/raw/363817ee21247e68890030f4fecf1dd2480e9957/wasm32-wasi.Dockerfile | docker build -t tmp - && docker run tmp
…
CC crypto_onetimeauth/libsodium_la-crypto_onetimeauth.lo
CC crypto_onetimeauth/poly1305/libsodium_la-onetimeauth_poly1305.lo
CC crypto_onetimeauth/poly1305/donna/libsodium_la-poly1305_donna.lo
CC crypto_pwhash/argon2/libsodium_la-argon2-core.lo
CC crypto_pwhash/argon2/libsodium_la-argon2-encoding.lo
CC crypto_pwhash/argon2/libsodium_la-argon2-fill-block-ref.lo
CC crypto_pwhash/argon2/libsodium_la-argon2.lo
CC crypto_pwhash/argon2/libsodium_la-blake2b-long.lo
onetimeauth_poly1305.s:15:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32, i64, i32) -> (i32)
^
onetimeauth_poly1305.s:33:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32, i64, i32) -> (i32)
^
onetimeauth_poly1305.s:49:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32) -> (i32)
^
onetimeauth_poly1305.s:66:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32, i64) -> (i32)
^
onetimeauth_poly1305.s:82:20: error: Unexpected token in operand: (
i32.call_indirect (i32, i32) -> (i32)
^
Makefile:2512: recipe for target 'crypto_onetimeauth/poly1305/libsodium_la-onetimeauth_poly1305.lo' failed
make[3]: *** [crypto_onetimeauth/poly1305/libsodium_la-onetimeauth_poly1305.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory '/libsodium/src/libsodium'
make[2]: *** [check-recursive] Error 1
Makefile:3106: recipe for target 'check-recursive' failed
make[2]: Leaving directory '/libsodium/src/libsodium'
Makefile:400: recipe for target 'check-recursive' failed
make[1]: Leaving directory '/libsodium/src'
make[1]: *** [check-recursive] Error 1
Makefile:515: recipe for target 'check-recursive' failed
make: *** [check-recursive] Error 1
Any workaround suggestions are extremely welcome.
Thank you
I can reproduce this error with this testcase:
int foo(int (*p)(void)) {
return p();
}
compiling with -save-temps with the latest wasi-sdk release. It appears fixed on LLVM master, so it should be fixed next time we update wasi-sdk to a newer LLVM.
Compilation without -save-temps works, so one workaround would be to run the compiler twice, once with -save-temps to generate the temporary .s files, which are preserved even after the errors, and then again without -save-temps to generate a .o file.
Interesting, I hadn't realized the -save-temps
caused the MC layer not only output the assembler but also try to re-parse it. That makes full .s
file round-tripping more critical than I had previously thought.
Thank you both for your replies. I've pulled the newest LLVM here but now I get a different error:
clang -cc1as: fatal error: error in backend: symbol not found in type index space: .Ltypeindex0
Again, without -save-temps
it works.
Let me know if I can provide further information.
This is bug in the llvm itself and the .s
assembly file handling. Can you open bug at bugs.llvm.org, and if possible attach the failing input file if you could? (either input source of bitcode file).
wasi-sdk has upgraded its LLVM tree since this issue; this is likely resolved. We can reopen if it is not.