Skip to content

Commit 50642c8

Browse files
committed
rust: Import LLD for linking wasm objects
This commit imports the LLD project from LLVM to serve as the default linker for the `wasm32-unknown-unknown` target. The `binaryen` submoule is consequently removed along with "binaryen linker" support in rustc. Moving to LLD brings with it a number of benefits for wasm code: * LLD is itself an actual linker, so there's no need to compile all wasm code with LTO any more. As a result builds should be *much* speedier as LTO is no longer forcibly enabled for all builds of the wasm target. * LLD is quickly becoming an "official solution" for linking wasm code together. This, I believe at least, is intended to be the main supported linker for native code and wasm moving forward. Picking up support early on should help ensure that we can help LLD identify bugs and otherwise prove that it works great for all our use cases! * Improvements to the wasm toolchain are currently primarily focused around LLVM and LLD (from what I can tell at least), so it's in general much better to be on this bandwagon for bugfixes and new features. * Historical "hacks" like `wasm-gc` will soon no longer be necessary, LLD will [natively implement][gc] `--gc-sections` (better than `wasm-gc`!) which means a postprocessor is no longer needed to show off Rust's "small wasm binary size". LLD is added in a pretty standard way to rustc right now. A new rustbuild target was defined for building LLD, and this is executed when a compiler's sysroot is being assembled. LLD is compiled against the LLVM that we've got in tree, which means we're currently on the `release_60` branch, but this may get upgraded in the near future! LLD is placed into rustc's sysroot in a `bin` directory. This is similar to where `gcc.exe` can be found on Windows. This directory is automatically added to `PATH` whenever rustc executes the linker, allowing us to define a `WasmLd` linker which implements the interface that `wasm-ld`, LLD's frontend, expects. Like Emscripten the LLD target is currently only enabled for Tier 1 platforms, notably OSX/Windows/Linux, and will need to be installed manually for compiling to wasm on other platforms. LLD is by default turned off in rustbuild, and requires a `config.toml` option to be enabled to turn it on. Finally the unstable `#![wasm_import_memory]` attribute was also removed as LLD has a native option for controlling this. [gc]: https://reviews.llvm.org/D42511
1 parent 45fba43 commit 50642c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+402
-741
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
[submodule "src/dlmalloc"]
4646
path = src/dlmalloc
4747
url = https://github.com/alexcrichton/dlmalloc-rs.git
48-
[submodule "src/binaryen"]
49-
path = src/binaryen
50-
url = https://github.com/alexcrichton/binaryen.git
5148
[submodule "src/doc/rust-by-example"]
5249
path = src/doc/rust-by-example
5350
url = https://github.com/rust-lang/rust-by-example
5451
[submodule "src/llvm-emscripten"]
5552
path = src/llvm-emscripten
5653
url = https://github.com/rust-lang/llvm
54+
[submodule "src/tools/lld"]
55+
path = src/tools/lld
56+
url = https://github.com/rust-lang/lld.git

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ matrix:
8181
# OSX 10.7 and `xcode7` is the latest Xcode able to compile LLVM for 10.7.
8282
- env: >
8383
RUST_CHECK_TARGET=dist
84-
RUST_CONFIGURE_ARGS="--build=i686-apple-darwin --enable-extended --enable-profiler --enable-emscripten"
84+
RUST_CONFIGURE_ARGS="--build=i686-apple-darwin --enable-full-tools --enable-profiler"
8585
SRC=.
8686
DEPLOY=1
8787
RUSTC_RETRY_LINKER_ON_SEGFAULT=1
@@ -95,7 +95,7 @@ matrix:
9595
9696
- env: >
9797
RUST_CHECK_TARGET=dist
98-
RUST_CONFIGURE_ARGS="--target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-extended --enable-sanitizers --enable-profiler --enable-emscripten"
98+
RUST_CONFIGURE_ARGS="--target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler"
9999
SRC=.
100100
DEPLOY=1
101101
RUSTC_RETRY_LINKER_ON_SEGFAULT=1

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.
129129
python x.py build
130130
```
131131

132-
If you are seeing build failure when compiling `rustc_binaryen`, make sure the path
133-
length of the rust folder is not longer than 22 characters.
134-
135132
#### Specifying an ABI
136133
[specifying-an-abi]: #specifying-an-abi
137134

appveyor.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,27 @@ environment:
6161
# 32/64 bit MSVC and GNU deployment
6262
- RUST_CONFIGURE_ARGS: >
6363
--build=x86_64-pc-windows-msvc
64-
--enable-extended
64+
--enable-full-tools
6565
--enable-profiler
66-
--enable-emscripten
6766
SCRIPT: python x.py dist
6867
DEPLOY: 1
6968
- RUST_CONFIGURE_ARGS: >
7069
--build=i686-pc-windows-msvc
7170
--target=i586-pc-windows-msvc
72-
--enable-extended
71+
--enable-full-tools
7372
--enable-profiler
74-
--enable-emscripten
7573
SCRIPT: python x.py dist
7674
DEPLOY: 1
7775
- MSYS_BITS: 32
78-
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-extended --enable-emscripten
76+
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-full-tools
7977
SCRIPT: python x.py dist
8078
MINGW_URL: https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror
8179
MINGW_ARCHIVE: i686-6.3.0-release-posix-dwarf-rt_v5-rev2.7z
8280
MINGW_DIR: mingw32
8381
DEPLOY: 1
8482
- MSYS_BITS: 64
8583
SCRIPT: python x.py dist
86-
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-extended --enable-emscripten
84+
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-full-tools
8785
MINGW_URL: https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror
8886
MINGW_ARCHIVE: x86_64-6.3.0-release-posix-seh-rt_v5-rev2.7z
8987
MINGW_DIR: mingw64

config.toml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@
326326
# target, as without this option the test output will not be captured.
327327
#wasm-syscall = false
328328

329+
# Indicates whether LLD will be compiled and made available in the sysroot for
330+
# rustc to execute.
331+
#lld = false
332+
329333
# =============================================================================
330334
# Options for specific targets
331335
#

src/Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/binaryen

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/bootstrap/bin/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn main() {
219219
// flesh out rpath support more fully in the future.
220220
cmd.arg("-Z").arg("osx-rpath-install-name");
221221
Some("-Wl,-rpath,@loader_path/../lib")
222-
} else if !target.contains("windows") {
222+
} else if !target.contains("windows") && !target.contains("wasm32") {
223223
Some("-Wl,-rpath,$ORIGIN/../lib")
224224
} else {
225225
None

src/bootstrap/bootstrap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ def update_submodules(self):
654654
continue
655655
if self.get_toml('jemalloc'):
656656
continue
657+
if module.endswith("lld"):
658+
config = self.get_toml('lld')
659+
if config is None or config == 'false':
660+
continue
657661
filtered_submodules.append(module)
658662
run(["git", "submodule", "update",
659663
"--init", "--recursive"] + filtered_submodules,

src/bootstrap/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<'a> Builder<'a> {
252252
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
253253
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
254254
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
255-
native::Llvm, tool::Rustfmt, tool::Miri),
255+
native::Llvm, tool::Rustfmt, tool::Miri, native::Lld),
256256
Kind::Check => describe!(check::Std, check::Test, check::Rustc),
257257
Kind::Test => describe!(test::Tidy, test::Bootstrap, test::DefaultCompiletest,
258258
test::HostCompiletest, test::Crate, test::CrateLibrustc, test::Rustdoc,

0 commit comments

Comments
 (0)