Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emcc and wasm-ld can't link our ui tests for wasm32-unknown-emscripten? #131666

Closed
workingjubilee opened this issue Oct 13, 2024 · 11 comments · Fixed by #131705
Closed

emcc and wasm-ld can't link our ui tests for wasm32-unknown-emscripten? #131666

workingjubilee opened this issue Oct 13, 2024 · 11 comments · Fixed by #131705
Labels
A-linkage Area: linking into static, shared libraries and binaries A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@workingjubilee
Copy link
Member

Perhaps I'm holding it wrong? About a fifth of the rustc UI test suite to fail on wasm32-unknown-emscripten when trying to run ./x.py test --target wasm32-unknown-emscripten. In all cases we get an error like this:


error: linking with `emcc` failed: exit status: 1
   |
   = note: "emcc" "-s" "EXPORTED_FUNCTIONS=[\"_main\"]" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/test/ui/array-slice-vec/vector-no-ann-2/a.vector_no_ann_2.86c223511763191d-cgu.0.rcgu.o" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/test/ui/array-slice-vec/vector-no-ann-2/a.1t3t8w654vioaffrv2c1spxg2.rcgu.o" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libstd-6499696fb99a9577.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_unwind-0c3cc3cd32c2b4b3.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libmemchr-e7a6f41ef20fcc54.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_demangle-d35e921e53f26e9e.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libstd_detect-a7a77daaad248f5e.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libhashbrown-e0e54cdb8e75fbf2.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_alloc-9f19c89c353a136f.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libminiz_oxide-ffd1c27bbffc4236.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libadler-4452dbe2564d6cb8.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libunwind-684258862f7c352d.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libcfg_if-0f4ad8f59845e58a.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/liblibc-2be890f74433405e.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-48460e2c05fc2c62.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/librustc_std_workspace_core-841075126ac27f05.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libcore-ee3c0a07d74de06f.rlib" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-c113413e38c4b290.rlib" "-l" "c" "-B/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "--target=wasm32-unknown-emscripten" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "/home/jubilee/rust/rustc/build/wasm32-unknown-emscripten/native/rust-test-helpers" "-L" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/test/ui/array-slice-vec/vector-no-ann-2/auxiliary" "-L" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/wasm32-unknown-emscripten/lib/self-contained" "-o" "/home/jubilee/rust/rustc/build/x86_64-unknown-linux-gnu/test/ui/array-slice-vec/vector-no-ann-2/a.wasm" "-O2" "-g0" "-sABORTING_MALLOC=0"
   = note: wasm-ld: error: /home/jubilee/.emscripten_cache/sysroot/lib/wasm32-emscripten/libstandalonewasm.a(__main_void.o): undefined symbol: main

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 13, 2024
@workingjubilee workingjubilee added O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 13, 2024
@jieyouxu
Copy link
Member

Does this target use some different main symbol name?

@jieyouxu
Copy link
Member

jieyouxu commented Oct 13, 2024

... do we need to pass --no-entry to lib builds? emscripten-core/emscripten#9640

@workingjubilee can you check if (some of) the failing tests are lib crates?

Actually what am I doing, I can check

@jieyouxu
Copy link
Member

I can't get past the building test helpers for this target cross-compiling from msvc host, not sure what's up with that.

@jieyouxu jieyouxu added A-testsuite Area: The testsuite used to check the correctness of rustc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Oct 13, 2024
@workingjubilee
Copy link
Member Author

Huh.

cc @juntyr Can you make it any further?

@jieyouxu
Copy link
Member

jieyouxu commented Oct 13, 2024

Also I note that wasm32-unknown-emscripten has no platform support docs and I have no clue what's needed to be able to run the tests. Because there's an open PR #131582 for this.

@jieyouxu
Copy link
Member

In the open platform support docs PR this says

This target is not extensively tested in CI for the rust-lang/rust repository.
It's recommended to test the wasm32-wasip1 target instead
for WebAssembly compatibility.

... so I don't know, is this expected failure?

@jieyouxu
Copy link
Member

jieyouxu commented Oct 14, 2024

Can you make it any further?

See #131582 (comment) I was able to get past the build helpers stage by properly acquring the toolchain and making relevant env vars available to bootstrap. Didn't bother trying to diagnose past stage 1 std and tests because there's like a chain of failures.

Notably I see

warning: dropping unsupported crate type `dylib` for target `wasm32-unknown-emscripten`

warning: `std` (lib) generated 1 warning

@hoodmane
Copy link
Contributor

hoodmane commented Oct 14, 2024

The failing link command includes:

"-o" "/some/long/path/a.wasm"

if we replace that with a.js, then it links as expected. But then it fails to run it at:

executing cd "/.../rust/build/x86_64-unknown-linux-gnu/test/ui/abi/extern/extern-pass-TwoU8s" && RUSTC="/.../rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" RUST_TEST_THREADS="20" "/.../rust/build/x86_64-unknown-linux-gnu/test/ui/abi/extern/extern-pass-TwoU8s/a.wasm"

We should invoke a.js with node.

@hoodmane
Copy link
Contributor

So I guess for starters we should do:

--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -1643,7 +1643,10 @@ fn make_exe_name(&self) -> PathBuf {
         // double the length.
         let mut f = self.output_base_dir().join("a");
         // FIXME: This is using the host architecture exe suffix, not target!
-        if self.config.target.starts_with("wasm") {
+        if self.config.target.contains("emscripten") {
+            f = f.with_extra_extension("js");
+        }
+        else if self.config.target.starts_with("wasm") {
             f = f.with_extra_extension("wasm");
         } else if self.config.target.contains("spirv") {
             f = f.with_extra_extension("spv");

@hoodmane
Copy link
Contributor

Combined with setting the runner to node this fixes most of the failing tests:

--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -612,6 +612,9 @@ pub fn from_triple(triple: &str) -> Self {
         if triple.contains("-none") || triple.contains("nvptx") || triple.contains("switch") {
             target.no_std = true;
         }
+        if triple.contains("emscripten") {
+            target.runner = Some("node".into());
+        }
         target
     }
 }

@hoodmane
Copy link
Contributor

The failures seem to be:

  • tests/ui/abi/numbers-arithmetic/return-float.rs
  • tests/ui/async-await/issue-60709.rs
  • tests/ui/backtrace/dylib-dep.rs
  • tests/ui/backtrace/line-tables-only.rs
  • tests/ui/intrinsics/intrinsic-alignment.rs
  • tests/ui/no_std/no-std-unwind-binary.rs
  • tests/ui/process/process-sigpipe.rs
  • tests/ui/structs-enums/enum-rec/issue-17431-6.rs
  • tests/ui/structs-enums/rec-align-u64.rs
  • tests/ui/test-attrs/test-passed.rs

and tests/ui/issues/issue-12699.rs seems like it hangs? process-sigpipe sounds like an xfail.

@bors bors closed this as completed in fc1ad2e Oct 15, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 15, 2024
Rollup merge of rust-lang#131705 - hoodmane:fix-emscripten-tests, r=jieyouxu

Fix most ui tests on emscripten target

To fix the linker errors, we need to set the output extension to `.js` instead of `.wasm`. Setting the output to a `.wasm` file puts Emscripten into standalone mode which is effectively a distinct target. We need to set the runner to be `node` as well.

This fixes most of the ui tests. I fixed 4 additional tests with simple problems:

- `intrinsics/intrinsic-alignment.rs` -- Two `#[cfg]` macros match for Emscripten so we got duplicate definition
- `structs-enums/rec-align-u64.rs` -- same problem
- `issues/issue-12699.rs` -- hangs so I disabled it
- `process/process-sigpipe.rs` -- Not expected to work on Emscripten so I disabled it

Resolves rust-lang#131666.

There are 7 more failing tests. I'll try to investigate more and see if I can fix them or at least understand why they happen.

- abi/numbers-arithmetic/return-float.rs (problem with [wasm treatment of noncanonical floats](https://webassembly.github.io/spec/core/exec/numerics.html#nan-propagation)?)
- async-await/issue-60709.rs -- linker error related to memcpy. Possible Emscripten bug?
- backtrace/dylib-dep.rs -- Says "Not supported"
- backtrace/line-tables-only.rs -- Says "Not supported"
- no_std/no-std-unwind-binary.rs -- compiler says `error: lang item required, but not found: eh_catch_typeinfo`
- structs-enums/enum-rec/issue-17431-6.rs -- One of the two compiler errors is missing
- test-attrs/test-passed.rs

    r?workingjubilee r?jieyouxu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants