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

cannot run the example js-hello #119

Closed
grigorijmarkelov opened this issue Apr 11, 2018 · 22 comments
Closed

cannot run the example js-hello #119

grigorijmarkelov opened this issue Apr 11, 2018 · 22 comments

Comments

@grigorijmarkelov
Copy link

I have started learning wasm-bindgen recently.And even with first example js-hello-world there was a weird problem. https://github.com/rust-lang-nursery/rust-wasm

I did as was written, set rustc to nightly, then:

rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
cargo new js-hello-world --lib

This is Cargo.toml:

[package]
name = "js-hello-world"
version = "0.1.0"
authors = ["Grigoriy Markelov <grigorijmarkelov@gmail.com>"]

[dependencies]
wasm-bindgen = "0.2.1"

[lib]
crate-type = ["cdylib"]

And lib.rs:

#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
extern crate wasm_bindgen;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern {
        fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet(name: &str) {
        alert(&format!("Hello, {}!", name));
}

Now when I build:

cargo build --target=wasm32-unknown-unknown -vv

Compilation actually hangs not consuming even cpu resources:

Fresh unicode-xid v0.1.0
Fresh serde v1.0.37
Fresh fnv v1.0.6
Fresh num-traits v0.2.2
Fresh dtoa v0.4.2
Fresh itoa v0.4.1
Fresh proc-macro2 v0.3.6
Fresh serde_json v1.0.13
Fresh quote v0.5.1
Fresh syn v0.13.1
Fresh serde_derive_internals v0.23.0
Fresh serde_derive v1.0.37
Fresh wasm-bindgen-shared v0.2.1
Fresh wasm-bindgen-backend v0.2.1
Fresh wasm-bindgen-macro v0.2.1
Fresh wasm-bindgen v0.2.1
Compiling js-hello-world v0.1.0 (file:///home/markelovg/container/js-hello-world)
Running rustc --crate-name js_hello_world src/lib.rs --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=a4ec1c36c55eb3a5 --out-dir /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/markelovg/container/js-hello-world/target/debug/deps --extern wasm_bindgen=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib

This libwasm_bingden-a2e136f9a24e6618.rlib dependency exists in my project but nothing then happens.

In task manager I have lld -flavor wasm -L ~/.rustup/toolchain/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib ~/myproject/target/wasm32-/debug/deps/longnames.rcgu.o etc and it doesn't consume cpu

@alexcrichton
Copy link
Contributor

@grigorijmarkelov hm interesting! So you've seen that lld as a process is running in the background when compilation hangs? If you kill that process, presumably compilation finishes with an error?

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 11, 2018

Alex, when I stop the process from manager there goes a big trace:

error: linking with `lld` failed: signal: 9
  |
  = note: "lld" "-flavor" "wasm" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.1y16o1qfye96o7m0.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.36ck12spbs2hdbb8.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.4xq48u46a1pwiqn7.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.8xzrsc1ux72v29j.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.98g0d9x8aw3akpe.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.c6lbtaiefvx3wya.rcgu.o" "-o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.wasm" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.crate.allocator.rcgu.o" "-L" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps" "-L" "/home/markelovg/container/js-hello-world/target/debug/deps" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-03ac0c81917aa4d9.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-c14e11707926bc0d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-900200aca44c19bf.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-f533d49de819afb6.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc_system-f37acce4a2014f2a.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-2fe945c5bf9e35c1.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-a123669918e2dfd5.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd_unicode-178cf9602d0f9abe.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-c465d6a99b92d83d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-caadd53095395037.rlib" "--threads" "--allow-undefined" "--no-entry"
  = note: 

error: aborting due to previous error

error: Could not compile `js-hello-world`.

Caused by:
  process didn't exit successfully: `rustc --crate-name js_hello_world src/lib.rs --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=a4ec1c36c55eb3a5 --out-dir /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/markelovg/container/js-hello-world/target/debug/deps --extern wasm_bindgen=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib` (exit code: 101)

@alexcrichton
Copy link
Contributor

How odd! Can you try attaching a debugger to lld to see why it's hanging?

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 12, 2018

Alex, when I stop the process from manager there goes a big trace:

error: linking with `lld` failed: signal: 9
  |
  = note: "lld" "-flavor" "wasm" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.1y16o1qfye96o7m0.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.36ck12spbs2hdbb8.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.4xq48u46a1pwiqn7.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.8xzrsc1ux72v29j.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.98g0d9x8aw3akpe.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.c6lbtaiefvx3wya.rcgu.o" "-o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.wasm" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.crate.allocator.rcgu.o" "-L" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps" "-L" "/home/markelovg/container/js-hello-world/target/debug/deps" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-03ac0c81917aa4d9.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-c14e11707926bc0d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-900200aca44c19bf.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-f533d49de819afb6.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc_system-f37acce4a2014f2a.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-2fe945c5bf9e35c1.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-a123669918e2dfd5.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd_unicode-178cf9602d0f9abe.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-c465d6a99b92d83d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-caadd53095395037.rlib" "--threads" "--allow-undefined" "--no-entry"
  = note: 

error: aborting due to previous error

error: Could not compile `js-hello-world`.

Caused by:
  process didn't exit successfully: `rustc --crate-name js_hello_world src/lib.rs --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=a4ec1c36c55eb3a5 --out-dir /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/markelovg/container/js-hello-world/target/debug/deps --extern wasm_bindgen=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib` (exit code: 101)

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 12, 2018

Sorry for dups.Alex I attached gdb to process, look:

markelovg@comp2:~/container/js-hello-world$ gdb -p 2238
GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 2238
[New LWP 2240]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
0xb7753cf9 in __kernel_vsyscall ()
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) bt
#0  0xb7753cf9 in __kernel_vsyscall ()
#1  0xb7727800 in futex_wait_cancelable (private=<optimized out>, expected=0, futex_word=0xbf817dac) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#2  __pthread_cond_wait_common (abstime=0x0, mutex=0xbf817d6c, cond=0xbf817d84) at pthread_cond_wait.c:502
#3  __pthread_cond_wait (cond=0xbf817d84, mutex=0xbf817d6c) at pthread_cond_wait.c:655
#4  0x09dec825 in __gthread_cond_wait (__mutex=<optimized out>, __cond=0xbf817d84)
    at /tmp/gcc-build/x86_64-unknown-linux-gnu/32/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr-default.h:864
#5  std::condition_variable::wait (this=0xbf817d84, __lock=...) at ../../../../../../gcc-4.8.5/libstdc++-v3/src/c++11/condition_variable.cc:52
#6  0x08308ce9 in lld::wasm::writeResult() ()
#7  0x082f8580 in (anonymous namespace)::LinkerDriver::link(llvm::ArrayRef<char const*>) [clone .constprop.291] ()
#8  0x082f8cbc in lld::wasm::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&) ()
#9  0x08093078 in main ()
(gdb) 

Actually I have weak familiarity with gdb,so tell if i need more special commands

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 12, 2018

I tried to to step from main and it waits for smth:

(gdb) frame 9
#9  0x08093078 in main ()
(gdb) next
Single stepping until exit from function __kernel_vsyscall,

which has no line number information.

@alexcrichton
Copy link
Contributor

Oh dear! I wonder if this is a race of some form in LLD? Can you try compiling with -C link-args=--no-threads and see if that fixes the issue?

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 12, 2018

Alex, again here goes the error:

markelovg@comp2:~/container/js-hello-world$ cargo rustc -- -C link-args=--no-threads --target=wasm32-unknown-unknown --verbose
   Compiling js-hello-world v0.1.0 (file:///home/markelovg/container/js-hello-world)
error[E0461]: couldn't find crate `wasm_bindgen` with expected target triple wasm32-unknown-unknown
 --> src/lib.rs:2:1
  |
2 | extern crate wasm_bindgen;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: the following crate versions were found:
          crate `wasm_bindgen`, target triple i686-unknown-linux-gnu: /home/markelovg/container/js-hello-world/target/debug/deps/libwasm_bindgen-55e57e30e5f37cac.rlib

error: aborting due to previous error

For more information about this error, try `rustc --explain E0461`.
error: Could not compile `js-hello-world`.

To learn more, run the command again with --verbose.
markelovg@comp2:~/container/js-hello-world$ 

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 12, 2018

Sorry, my dumb.Now goes:

markelovg@comp2:~/container/js-hello-world$ cargo rustc  --target=wasm32-unknown-unknown -- -C link-args=--no-threads --verbose
   Compiling js-hello-world v0.1.0 (file:///home/markelovg/container/js-hello-world)

When I attach gdb to lld, then it looks like this:

markelovg@comp2:~/container/js-hello-world$ gdb -p 3479
GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 3479
[New LWP 3480]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
0xb777fcf9 in __kernel_vsyscall ()
(gdb) bt
#0  0xb777fcf9 in __kernel_vsyscall ()
#1  0xb7753800 in futex_wait_cancelable (private=<optimized out>, expected=0, 
    futex_word=0xbfb5e8dc) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#2  __pthread_cond_wait_common (abstime=0x0, mutex=0xbfb5e89c, 
    cond=0xbfb5e8b4) at pthread_cond_wait.c:502
#3  __pthread_cond_wait (cond=0xbfb5e8b4, mutex=0xbfb5e89c)
    at pthread_cond_wait.c:655
#4  0x09dec825 in __gthread_cond_wait (__mutex=<optimized out>, 
    __cond=0xbfb5e8b4)
    at /tmp/gcc-build/x86_64-unknown-linux-gnu/32/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr-default.h:864
#5  std::condition_variable::wait (this=0xbfb5e8b4, __lock=...)
    at ../../../../../../gcc-4.8.5/libstdc++-v3/src/c++11/condition_variable.cc:52
#6  0x08308ce9 in lld::wasm::writeResult() ()
#7  0x082f8580 in (anonymous namespace)::LinkerDriver::link(llvm::ArrayRef<char const*>) [clone .constprop.291] ()
#8  0x082f8cbc in lld::wasm::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&) ()
#9  0x08093078 in main ()
(gdb) 

Seems the same?

@alexcrichton
Copy link
Contributor

Hm ok it may be that --threads --no-threads isn't working in LLD. Could you try:

  • Run with -Z print-link-args
  • Wait for the link args to be printed
  • Ctrl-c the build, killing everything
  • Copy/paste the link arguments and run them, removing --threads

And see if it hits the same issue?

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 13, 2018

Here is output with -Z print-link-args

markelovg@comp2:~/container/js-hello-world$ cargo rustc --target=wasm32-unknown-unknown -- -Z print-link-args --verbose
   Compiling js-hello-world v0.1.0 (file:///home/markelovg/container/js-hello-world)
"lld" "-flavor" "wasm" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.1y16o1qfye96o7m0.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.36ck12spbs2hdbb8.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.4xq48u46a1pwiqn7.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.8xzrsc1ux72v29j.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.98g0d9x8aw3akpe.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.c6lbtaiefvx3wya.rcgu.o" "-o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.wasm" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.crate.allocator.rcgu.o" "-L" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps" "-L" "/home/markelovg/container/js-hello-world/target/debug/deps" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-03ac0c81917aa4d9.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-c14e11707926bc0d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-900200aca44c19bf.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-f533d49de819afb6.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc_system-f37acce4a2014f2a.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-2fe945c5bf9e35c1.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-a123669918e2dfd5.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd_unicode-178cf9602d0f9abe.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-c465d6a99b92d83d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-caadd53095395037.rlib" "--threads" "--allow-undefined" "--no-entry"

Then i tried to compile with -C link-args but rustc many times errored with multiple input files:

markelovg@comp2:~/container/js-hello-world$ cargo rustc --target=wasm32-unknown-unknown -- -C link-args=/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.1y16o1qfye96o7m0.rcgu.o /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.36ck12spbs2hdbb8.rcgu.o /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.4xq48u46a1pwiqn7.rcgu.o /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.8xzrsc1ux72v29j.rcgu.o /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.98g0d9x8aw3akpe.rcgu.o /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.c6lbtaiefvx3wya.rcgu.o
   Compiling js-hello-world v0.1.0 (file:///home/markelovg/container/js-hello-world)
error: multiple input filenames provided

error: Could not compile `js-hello-world`.

To learn more, run the command again with --verbose.
markelovg@comp2:~/container/js-hello-world$ cargo rustc --target=wasm32-unknown-unknown -- -C link-args=/home/markelovg/container/js-hello-world/target/debug/deps /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-03ac0c81917aa4d9.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-c14e11707926bc0d.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-900200aca44c19bf.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-f533d49de819afb6.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc_system-f37acce4a2014f2a.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-2fe945c5bf9e35c1.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-a123669918e2dfd5.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd_unicode-178cf9602d0f9abe.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-c465d6a99b92d83d.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-caadd53095395037.rlib /home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib
   Compiling js-hello-world v0.1.0 (file:///home/markelovg/container/js-hello-world)
error: multiple input filenames provided

error: Could not compile `js-hello-world`.

Surely advice would help to me better comprehend with this.

@alexcrichton
Copy link
Contributor

@grigorijmarkelov oh sorry I didn't mean running cargo rustc but rather running the lld command directly. Basically I'm curious if invoking LLD without --threads solves the issue here, but you can't get rustc to not do that just yet so it needs to be invoked manually

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 14, 2018

I read a bit from llvm site, regarding lld and it says
Using LLD

LLD is installed as ld.lld. On Unix, linkers are invoked by compiler drivers, so you are not expected to use that command directly.

So then I tried RUSTFLAGS='-Z linker-flavor=ld.lld' cargo build --target=wasm32-unknown-unknown
and it errors:

markelovg@comp2:~/container/js-hello-world$ RUSTFLAGS='-Z linker-flavor=ld.lld' cargo build --target=wasm32-unknown-unknown --verbose
       Fresh unicode-xid v0.1.0
       Fresh fnv v1.0.6
       Fresh serde v1.0.37
       Fresh dtoa v0.4.2
       Fresh num-traits v0.2.2
       Fresh itoa v0.4.1
       Fresh proc-macro2 v0.3.6
       Fresh serde_json v1.0.13
       Fresh quote v0.5.1
       Fresh syn v0.13.1
       Fresh serde_derive_internals v0.23.0
       Fresh serde_derive v1.0.37
       Fresh wasm-bindgen-shared v0.2.1
       Fresh wasm-bindgen-backend v0.2.1
       Fresh wasm-bindgen-macro v0.2.1
       Fresh wasm-bindgen v0.2.1
   Compiling js-hello-world v0.1.0 (file:///home/markelovg/container/js-hello-world)
     Running `rustc --crate-name js_hello_world src/lib.rs --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=a4ec1c36c55eb3a5 --out-dir /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/markelovg/container/js-hello-world/target/debug/deps --extern wasm_bindgen=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib -Z linker-flavor=ld.lld`
error: linking with `lld` failed: exit code: 1
  |
  = note: "lld" "-flavor" "gnu" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.1y16o1qfye96o7m0.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.36ck12spbs2hdbb8.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.4xq48u46a1pwiqn7.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.8xzrsc1ux72v29j.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.98g0d9x8aw3akpe.rcgu.o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.c6lbtaiefvx3wya.rcgu.o" "-o" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.wasm" "--version-script=/tmp/rustc.BvEGLIcu5Z24/list" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.crate.allocator.rcgu.o" "--gc-sections" "-L" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps" "-L" "/home/markelovg/container/js-hello-world/target/debug/deps" "-L" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib" "-Bstatic" "/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-03ac0c81917aa4d9.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-c14e11707926bc0d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-900200aca44c19bf.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-f533d49de819afb6.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc_system-f37acce4a2014f2a.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-2fe945c5bf9e35c1.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-a123669918e2dfd5.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd_unicode-178cf9602d0f9abe.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-c465d6a99b92d83d.rlib" "/home/markelovg/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-caadd53095395037.rlib" "-shared" "-Bdynamic"
  = note: lld: error: /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/js_hello_world.1y16o1qfye96o7m0.rcgu.o: invalid data encoding
          

error: aborting due to previous error

error: Could not compile `js-hello-world`.

Caused by:
  process didn't exit successfully: `rustc --crate-name js_hello_world src/lib.rs --crate-type cdylib --emit=dep-info,link -C debuginfo=2 -C metadata=a4ec1c36c55eb3a5 --out-dir /home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -C incremental=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/incremental -L dependency=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/markelovg/container/js-hello-world/target/debug/deps --extern wasm_bindgen=/home/markelovg/container/js-hello-world/target/wasm32-unknown-unknown/debug/deps/libwasm_bindgen-a2e136f9a24e6618.rlib -Z linker-flavor=ld.lld` (exit code: 101)
markelovg@comp2:~/container/js-hello-world$ 

@alexcrichton
Copy link
Contributor

@grigorijmarkelov oh sorry the LLD on your system probably won't work, you'll need to use the one that comes with the Rust compiler (buried inside ~/.rustup/toolchains) which has wasm support, and that'll be invoked as lld -flavor wasm ...

@grigorijmarkelov
Copy link
Author

grigorijmarkelov commented Apr 17, 2018

Alex thanks for your patience.I tried with lld from nightly toolchains but it says it's only generic driver.

markelovg@comp2:~/.rustup/toolchains/nightly-i686-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu/bin$ ./lld
lld is a generic driver.
Invoke ld.lld (Unix), ld (macOS) or lld-link (Windows) instead.

Let bring my thought, I'm starting to realize that problem may be with my system.Started a question on SO :
https://stackoverflow.com/questions/49769034/libwasm-bindgen-a2e136f9a24e6618-rlib-hangs-and-doesnt-consume-cpu-when-compili/49810287#49810287
As there were mentioned problem with linking may arise from not compatible targets: recall, backtrace has used in frame 4 /tmp/gcc-build/x86_64-unknown-linux-gnu/32/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr-default.h which perhaps related with x86-64 target while my toolchain is i686 32bit.
One more note: when I was starting wasm examples from mdn where rust functions exports with "pub extern fn" those examples were easily compiled and run.Maybe wasm-bindgen relies on some external libs which doesn't fit with 32bit target.

@grigorijmarkelov
Copy link
Author

On the x86-64 linux-gnu os this example builds nicely.So it only problems with 32bit platform support.
Thanks .

@alexcrichton
Copy link
Contributor

Hm interesting! It turns out one of the dependencies I added recently, wasmi, doesn't compile/work on 32-bit. In that sense it's actually difficult to test master against 32-bit, but simple wasm compilations using just rustc seem to work on 32-bit.

Is there a way I could use a docker image or something like that to reproduce your results?

@alexcrichton
Copy link
Contributor

Ok I'm gonna close this for now and chalk it up to werid system oddities, but if it comes back please let me know!

@vladbat00
Copy link
Contributor

@alexcrichton, hi! I've just got the same problem on my Ubuntu VPS. I would like to help you with investigating this issue. Please, tell me, what you need.
The least I can tell about my system for now is

cat /proc/version
Linux version 2.6.32-43-pve (root@lola) (gcc version 4.7.2 (Debian 4.7.2-5) )

If that would be appropriate I could even give you access to my VPS, as I'm not sure I can give you a docker image or something like that.

That's what I get in gdb (not sure how to get the backtrace, because it doesn't crash but just hangs):

Starting program: /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/lld -flavor wasm -L /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common0-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common1-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common10-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common11-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common12-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common2-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common3-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common4-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common5-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common6-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common7-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common8-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.platformio_common9-5adf60b0a379ff4f4c7da2035b87bfe5.rs.rcgu.o -o /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.wasm /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/platformio_common.crate.allocator.rcgu.o -L /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps -L /var/www/platformio_frontend/platformio_common/target/release/deps -L /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/libstdweb-f37b92de5d2cc367.rlib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/libdiscard-858e02cc18635af1.rlib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/libfutures-6f31644f5c45c739.rlib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/libserde_json-5be275f0ee166c57.rlib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/libitoa-1229278dea9583a3.rlib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/libdtoa-50d2d39d3a49aa20.rlib /var/www/platformio_frontend/platformio_common/target/wasm32-unknown-unknown/release/deps/libserde-0955bd0a172dbe44.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libstd-838e7043667c8383.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-5e833dca3600da0d.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libunwind-563b7bfadb84cc89.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liblibc-ab07a8cc046d555c.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc_system-8f45885d6199acbc.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-97d278ffa64e66c2.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/liballoc-eebfe02b35d336be.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-c267d6f284101f75.rlib /home/mvlabat/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-17fa257ec95d4eb8.rlib --threads --allow-undefined --no-entry
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff31a5700 (LWP 1808)]

@vladbat00
Copy link
Contributor

A small update.
If running lld with --no-threads it seems to finish successfully (at least the exit code is 0). But I don't know how to make it run with no threads when calling cargo or rustc. When I pass -C link-args=--no-threads to rustc it runs lld with both --no-threads and --threads arguments which makes lld run with threads as a result.

@alexcrichton
Copy link
Contributor

@mvlabat ah ok excellent, thanks for the info! Sounds like you've confirmed --threads is indeed the issue. In that case I'll submit an upstream change to invoke lld with --no-threads, and sounds like it's not quite ready to be invoked with --threads.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 26, 2018
Upstream bug reports (rustwasm/wasm-bindgen#119) show that this may be the
culprit of odd crashes/hangs. The linker is a tiny fraction of build time anyway
right now so let's disable it and figure out how to possibly reenable it later
if necessary.
@alexcrichton
Copy link
Contributor

I've proposed that change in rust-lang/rust#50251

kennytm added a commit to kennytm/rust that referenced this issue Apr 27, 2018
rustc: Disable threads in LLD for wasm

Upstream bug reports (rustwasm/wasm-bindgen#119) show that this may be the
culprit of odd crashes/hangs. The linker is a tiny fraction of build time anyway
right now so let's disable it and figure out how to possibly reenable it later
if necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants