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

linker rust-lld not found #80721

Closed
greyltc opened this issue Jan 5, 2021 · 4 comments
Closed

linker rust-lld not found #80721

greyltc opened this issue Jan 5, 2021 · 4 comments

Comments

@greyltc
Copy link

greyltc commented Jan 5, 2021

I'm building on Arch Linux (x86_64) and I've built rust 1.49.0 with the following config.toml:

[build]
target = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
extended = true
docs = false
sanitizers = false
profiler = true
vendor = true

[rust]
channel = "stable"
rpath = false

[install]
prefix = "/usr"

[target.x86_64-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"

[target.wasm32-unknown-unknown]
llvm-config = "/usr/bin/llvm-config"
wasi-root = "/usr/lib/wasi"
profiler = false

I've actually tried building it twice. Once with the above and once without the llvm-config lines, both give me the same problem.

I'm using the latest wasm-pack, 0.9.1.

When I cd into https://github.com/rustwasm/wasm-bindgen/tree/master/examples/without-a-bundler
and run wasm-pack build --target web:

$ wasm-pack build --target web
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling wasm-bindgen-shared v0.2.69 (wasm-bindgen-0.2.69/crates/shared)
   Compiling log v0.4.11
   Compiling syn v1.0.57
   Compiling cfg-if v0.1.10
   Compiling lazy_static v1.4.0
   Compiling bumpalo v3.4.0
   Compiling wasm-bindgen v0.2.69 (wasm-bindgen-0.2.69)
   Compiling cfg-if v1.0.0
   Compiling quote v1.0.8
   Compiling wasm-bindgen-backend v0.2.69 (wasm-bindgen-0.2.69/crates/backend)
   Compiling wasm-bindgen-macro-support v0.2.69 (wasm-bindgen-0.2.69/crates/macro-support)
   Compiling wasm-bindgen-macro v0.2.69 (wasm-bindgen-0.2.69/crates/macro)
   Compiling js-sys v0.3.46 (wasm-bindgen-0.2.69/crates/js-sys)
   Compiling web-sys v0.3.46 (wasm-bindgen-0.2.69/crates/web-sys)
   Compiling without-a-bundler v0.1.0 (wasm-bindgen-0.2.69/examples/without-a-bundler)
error: linker `rust-lld` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `without-a-bundler`

To learn more, run the command again with --verbose.
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Some person here thinks this is a problem with the rust compiler: rustwasm/wasm-pack#754 (comment)

It seems like that's true, because this thread explains what the gentoo packagers did to their rust package work around this problem:
https://bugs.gentoo.org/715348
(tldr: sed -i '/linker:/ s/rust-lld/wasm-ld/' src/librustc_target/spec/wasm32_base.rs)

The only place I can find a file called rust-lld is rustc-1.49.0-src/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld after I build, but that just seems like a build artifact that never gets installed anywhere. Am I missing something special that I have to do to get rust-lld deployed/installed properly? Have I done something wrong in my config.toml file or otherwise?

Note that
RUSTFLAGS="-C linker=lld" wasm-pack build --target web
works for me but
RUSTFLAGS="-C linker=wasm-ld" wasm-pack build --target web
fails with some error about something needing to be build with -fPIC and a warning that "creating shared libraries, with -shared, is not yet stable"
Needing to override RUSTFLAGS to fix a (broken?) default linker doesn't feel like an actual solution.

@Mark-Simulacrum
Copy link
Member

I would expect you to need to add lld = true to [rust] block in config.toml.

@greyltc
Copy link
Author

greyltc commented Jan 5, 2021

Thanks! I'll give this a go!

@greyltc
Copy link
Author

greyltc commented Jan 5, 2021

That build failed after some time with:

-- Build files have been written to: /mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/build/x86_64-unknown-linux-gnu/lld/build
running: "cmake" "--build" "." "--target" "install" "--config" "Release" "--" "-j" "8"
[61/141] Building CXX object COFF/CMakeFiles/lldCOFF.dir/Writer.cpp.o
FAILED: COFF/CMakeFiles/lldCOFF.dir/Writer.cpp.o 
/usr/lib/ccache/bin/c++ -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -ICOFF -I/mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/src/llvm-project/lld/COFF -I/mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/src/llvm-project/lld/include -Iinclude -ffunction-sections -fdata-sections -fPIC -m64 -march=x86-64 -mtune=generic -pipe -fno-plt -fPIC -fvisibility-inlines-hidden -Werror=date-time -w -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -fno-exceptions -fno-rtti -std=gnu++14 -MD -MT COFF/CMakeFiles/lldCOFF.dir/Writer.cpp.o -MF COFF/CMakeFiles/lldCOFF.dir/Writer.cpp.o.d -o COFF/CMakeFiles/lldCOFF.dir/Writer.cpp.o -c /mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/src/llvm-project/lld/COFF/Writer.cpp
/mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/src/llvm-project/lld/COFF/Writer.cpp: In member function ‘void {anonymous}::Writer::fixTlsAlignment()’:
/mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/src/llvm-project/lld/COFF/Writer.cpp:2030:13: error: ‘using coff_tls_directory64 = struct llvm::object::coff_tls_directory<llvm::support::detail::packed_endian_specific_integral<long int, llvm::support::little, 1> >’ {aka ‘struct llvm::object::coff_tls_directory<llvm::support::detail::packed_endian_specific_integral<long int, llvm::support::little, 1> >’} has no member named ‘setAlignment’; did you mean ‘getAlignment’?
 2030 |     tlsDir->setAlignment(tlsAlignment);
      |             ^~~~~~~~~~~~
      |             getAlignment
/mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/src/llvm-project/lld/COFF/Writer.cpp:2034:13: error: ‘using coff_tls_directory32 = struct llvm::object::coff_tls_directory<llvm::support::detail::packed_endian_specific_integral<int, llvm::support::little, 1> >’ {aka ‘struct llvm::object::coff_tls_directory<llvm::support::detail::packed_endian_specific_integral<int, llvm::support::little, 1> >’} has no member named ‘setAlignment’; did you mean ‘getAlignment’?
 2034 |     tlsDir->setAlignment(tlsAlignment);
      |             ^~~~~~~~~~~~
      |             getAlignment
[68/141] Building CXX object COFF/CMakeFiles/lldCOFF.dir/SymbolTable.cpp.o
ninja: build stopped: subcommand failed.
thread 'main' panicked at '
command did not execute successfully, got: exit code: 1

build script failed, must exit now', /mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/vendor/cmake/src/lib.rs:885:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
	finished in 24.215 seconds
failed to run: /mnt/scratch/git/rust-wasm/src/rustc-1.49.0-src/build/bootstrap/debug/bootstrap dist -j 8
Build completed unsuccessfully in 0:07:46
==> ERROR: A failure occurred in build().

I'll try again removing the llvm-config = "/usr/bin/llvm-config" lines from my config.toml

@greyltc
Copy link
Author

greyltc commented Jan 5, 2021

Yep, lld = true in [rust] causes the install step to install /usr/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld which means my wasm linking now works out of the box, thanks!

@greyltc greyltc closed this as completed Jan 5, 2021
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

2 participants