Skip to content

Commit d69b248

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 0be38e1 commit d69b248

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

+408
-745
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
[submodule "src/dlmalloc"]
4242
path = src/dlmalloc
4343
url = https://github.com/alexcrichton/dlmalloc-rs.git
44-
[submodule "src/binaryen"]
45-
path = src/binaryen
46-
url = https://github.com/alexcrichton/binaryen.git
4744
[submodule "src/doc/rust-by-example"]
4845
path = src/doc/rust-by-example
4946
url = https://github.com/rust-lang/rust-by-example
@@ -53,3 +50,6 @@
5350
[submodule "src/stdsimd"]
5451
path = src/stdsimd
5552
url = https://github.com/rust-lang-nursery/stdsimd
53+
[submodule "src/tools/lld"]
54+
path = src/tools/lld
55+
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
@@ -67,29 +67,27 @@ environment:
6767
# 32/64 bit MSVC and GNU deployment
6868
- RUST_CONFIGURE_ARGS: >
6969
--build=x86_64-pc-windows-msvc
70-
--enable-extended
70+
--enable-full-tools
7171
--enable-profiler
72-
--enable-emscripten
7372
SCRIPT: python x.py dist
7473
DEPLOY: 1
7574
- RUST_CONFIGURE_ARGS: >
7675
--build=i686-pc-windows-msvc
7776
--target=i586-pc-windows-msvc
78-
--enable-extended
77+
--enable-full-tools
7978
--enable-profiler
80-
--enable-emscripten
8179
SCRIPT: python x.py dist
8280
DEPLOY: 1
8381
- MSYS_BITS: 32
84-
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-extended --enable-emscripten
82+
RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-full-tools
8583
SCRIPT: python x.py dist
8684
MINGW_URL: https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror
8785
MINGW_ARCHIVE: i686-6.3.0-release-posix-dwarf-rt_v5-rev2.7z
8886
MINGW_DIR: mingw32
8987
DEPLOY: 1
9088
- MSYS_BITS: 64
9189
SCRIPT: python x.py dist
92-
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-extended --enable-emscripten
90+
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-full-tools
9391
MINGW_URL: https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror
9492
MINGW_ARCHIVE: x86_64-6.3.0-release-posix-seh-rt_v5-rev2.7z
9593
MINGW_DIR: mingw64

config.toml.example

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

332+
# Indicates whether LLD will be compiled and made available in the sysroot for
333+
# rustc to execute.
334+
#lld = false
335+
332336
# =============================================================================
333337
# Options for specific targets
334338
#

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
@@ -224,7 +224,7 @@ fn main() {
224224
// flesh out rpath support more fully in the future.
225225
cmd.arg("-Z").arg("osx-rpath-install-name");
226226
Some("-Wl,-rpath,@loader_path/../lib")
227-
} else if !target.contains("windows") {
227+
} else if !target.contains("windows") && !target.contains("wasm32") {
228228
Some("-Wl,-rpath,$ORIGIN/../lib")
229229
} else {
230230
None

src/bootstrap/bootstrap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ def update_submodules(self):
641641
continue
642642
if self.get_toml('jemalloc'):
643643
continue
644+
if module.endswith("lld"):
645+
config = self.get_toml('lld')
646+
if config is None or config == 'false':
647+
continue
644648
filtered_submodules.append(module)
645649
run(["git", "submodule", "update",
646650
"--init", "--recursive"] + filtered_submodules,

src/bootstrap/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'a> Builder<'a> {
316316
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
317317
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
318318
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
319-
native::Llvm, tool::Rustfmt, tool::Miri),
319+
native::Llvm, tool::Rustfmt, tool::Miri, native::Lld),
320320
Kind::Check => describe!(check::Std, check::Test, check::Rustc),
321321
Kind::Test => describe!(test::Tidy, test::Bootstrap, test::Ui, test::RunPass,
322322
test::CompileFail, test::ParseFail, test::RunFail, test::RunPassValgrind,

0 commit comments

Comments
 (0)