Description
Hi there, I’m not sure if I should report this here or in rust-lang/rust, so please let me know if I need to move this report elsewhere.
When investigating issues with the Nixpkgs rustc
build, we discovered that when enabling the wasm32-unknown-unknown
target on Linux, the libcompiler_builtins-*.rlib
built for that platform contained object files for the architecture the compiler is being built for, rather than WASM ones. These correspond to the C‐based compiler-rt intrinsics.
I spent hours assuming this was purely a bug with our build environment until I looked at what rustup
is shipping for wasm32-unknown-unknown
:
45c91108d938afe8-cmpti2.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
I can’t seem to induce Rust to try and link with these – whenever I do something that ought to use one of the intrinsics it just open‐codes it into the output WASM – but this seems kind of bad? When this crate is built with a Clang‐based environment, it passes --target
and they’re built for the right platform, but it will also happily use a single‐target GCC and build for the entirely wrong platform. (It’s also not entirely clear to me how the Clang‐based build is meant to work, as the compiler-rt C files depend on libc
headers despite the platform being freestanding; it seems to at least work by coincidence on our Clang‐based Darwin build, but fail in exciting ways if we try to use Clang on Linux.)
If these C‐based intrinsics are never used on wasm32-unknown-unknown
, then they should probably not get compiled in the first place, but if they matter then it seems like they’re currently broken on GCC‐based environments.