Stream: wasi

Topic: clang-10 sysroot


view this post on Zulip Gabor Greif (Mar 01 2020 at 16:18):

The wasi-libc website advertises to call clang with --sysroot= to build wasm executables with wasi. I can't seem to make it work with clang-10. I am leveraging Nixpkgs, with updated packages (PRs filed). Here are the details.

I call

clang-10 --target=wasm32-wasi --sysroot /nix/store/l8fgxyx8rhcdmn7gv7kzmajrm7i23d2z-wasilibc-20200227 fak.c -v

It fails:

clang version 10.0.0
Target: wasm32-unknown-wasi
Thread model: posix
InstalledDir: /nix/store/ia3qwhkiw45b50j2ggbv1dvjhpai6rs8-clang-10.0.0rc2/bin
 "/nix/store/ia3qwhkiw45b50j2ggbv1dvjhpai6rs8-clang-10.0.0rc2/bin/clang-10" -cc1 -triple wasm32-unknown-wasi -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name fak.c -mrelocation-model static -mthread-model posix -mframe-pointer=none -fno-rounding-math -masm-verbose -mconstructor-aliases -target-cpu generic -fvisibility hidden -dwarf-column-info -debugger-tuning=gdb -target-linker-version 450.3 -v -nostdsysteminc -resource-dir /nix/store/ia3qwhkiw45b50j2ggbv1dvjhpai6rs8-clang-10.0.0rc2/lib/clang/10.0.0 -isysroot /nix/store/l8fgxyx8rhcdmn7gv7kzmajrm7i23d2z-wasilibc-20200227 -internal-isystem /nix/store/ia3qwhkiw45b50j2ggbv1dvjhpai6rs8-clang-10.0.0rc2/lib/clang/10.0.0/include -fdebug-compilation-dir /Users/ggreif/motoko -ferror-limit 19 -fmessage-length 92 -fgnuc-version=4.2.1 -fobjc-runtime=gnustep -fno-common -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/39/lr50t0q96tx5qp0mzht34r240000gn/T/fak-69da11.o -x c fak.c
clang -cc1 version 10.0.0 based upon LLVM 10.0.0git default target x86_64-apple-darwin17.7.0
#include "..." search starts here:
#include <...> search starts here:
 /nix/store/ia3qwhkiw45b50j2ggbv1dvjhpai6rs8-clang-10.0.0rc2/lib/clang/10.0.0/include
End of search list.
fak.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

It won't look inside the sysroot at all.

$ ls /nix/store/l8fgxyx8rhcdmn7gv7kzmajrm7i23d2z-wasilibc-20200227
include  lib  share

Adding -isystem /nix/store/l8fgxyx8rhcdmn7gv7kzmajrm7i23d2z-wasilibc-20200227/include makes it compile. But now lld fails:

 "/nix/store/qr74zlgry31w5zxp2jm5wrbcxy5rpc8a-lld-10.0.0rc2/bin/wasm-ld" -L/nix/store/l8fgxyx8rhcdmn7gv7kzmajrm7i23d2z-wasilibc-20200227/lib/wasm32-wasi /nix/store/l8fgxyx8rhcdmn7gv7kzmajrm7i23d2z-wasilibc-20200227/lib/wasm32-wasi/crt1.o /var/folders/39/lr50t0q96tx5qp0mzht34r240000gn/T/fak-5643da.o -lc /nix/store/ia3qwhkiw45b50j2ggbv1dvjhpai6rs8-clang-10.0.0rc2/lib/clang/10.0.0/lib/wasi/libclang_rt.builtins-wasm32.a -o a.out
wasm-ld: error: cannot open /nix/store/ia3qwhkiw45b50j2ggbv1dvjhpai6rs8-clang-10.0.0rc2/lib/clang/10.0.0/lib/wasi/libclang_rt.builtins-wasm32.a: No such file or directory
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

I am stuck at this place. Maybe somebody can give me a clue to get of this problem? I have no idea how libclang_rt.builtins-wasm32.a is supposed to be in that place.

I am getting the impression that clang-10 RC2 is not ready for wasi yet.

view this post on Zulip Dan Gohman (Mar 01 2020 at 16:45):

On the include issue, your clang -cc1 invocation has -nostdsysteminc. I don't have a nix installation handy to check with, but the clang driver on the hosts I have access to don't pass that (unless I pass -nostdinc, but you don't appear to be using that).

view this post on Zulip Dan Gohman (Mar 01 2020 at 16:46):

Is it possible that nix's clang is patched to add -nostdsysteminc?

view this post on Zulip Dan Gohman (Mar 01 2020 at 16:53):

On the libclang_rt.builtins-wasm32.a issue, that file is built from compiler-rt, which is part of LLVM. Unfortunately, LLVM's build scripts don't build compiler-rt for cross-compilation support, so generic clang installations lack it.

view this post on Zulip Dan Gohman (Mar 01 2020 at 16:54):

I'll add a note about that to wasi-libc's README.

view this post on Zulip Gabor Greif (Mar 01 2020 at 16:54):

Well, I doubt that. I did a git grep nostdsysteminc in Nixpkgs and it didn't come up with a hit. I was adding the llvm_10 support recently and I don't remember adding such a patch.

view this post on Zulip Gabor Greif (Mar 01 2020 at 16:56):

I suspected that. What are the magical incantations to add that to compiler-rt? I can fix the Nixpkgs.

view this post on Zulip Gabor Greif (Mar 01 2020 at 16:57):

I want to bring the clang wasm support on-par with cargo in Nix.

view this post on Zulip Dan Gohman (Mar 01 2020 at 16:58):

https://github.com/CraneStation/wasi-sdk/blob/master/Makefile#L60

WASI-enabled C/C++ toolchain. Contribute to CraneStation/wasi-sdk development by creating an account on GitHub.

view this post on Zulip Dan Gohman (Mar 01 2020 at 16:58):

Is how it's built in wasi-sdk

view this post on Zulip Gabor Greif (Mar 01 2020 at 17:00):

Thanks Dan! I have to run, will check back later!

view this post on Zulip Dan Gohman (Mar 01 2020 at 17:00):

On the nostdsysteminc issue, that flag is most likely the problem; the question is, who is adding it?

view this post on Zulip Dan Gohman (Mar 01 2020 at 17:01):

I can also add, neither of these issues is likely to be new in clang-10. We don't have any wasi-specific code for handling sysroots or include directories, and the libclang_rt.builtins-wasm32.a thing isn't new either.

view this post on Zulip Dan Gohman (Mar 01 2020 at 17:29):

@Gabor Greif That nostdsysteminc flag is most likely coming from Nix: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/llvm/10/clang/default.nix#L49

Nix Packages collection. Contribute to NixOS/nixpkgs development by creating an account on GitHub.

view this post on Zulip Gabor Greif (Mar 01 2020 at 22:22):

Ugh, I tried git grep systeminc. Thanks for the tip!


Last updated: Dec 23 2024 at 12:05 UTC