Skip to content

Commit 0bac52a

Browse files
authored
Rollup merge of rust-lang#48125 - alexcrichton:lld, r=Mark-Simulacrum
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
2 parents e91f1c0 + ce52e0e commit 0bac52a

Some content is hidden

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

57 files changed

+453
-837
lines changed

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
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
5047
[submodule "src/llvm-emscripten"]
5148
path = src/llvm-emscripten
5249
url = https://github.com/rust-lang/llvm
50+
[submodule "src/tools/lld"]
51+
path = src/tools/lld
52+
url = https://github.com/rust-lang/lld.git

.travis.yml

+2-2
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

-3
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

+4-6
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

+4
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

-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/binaryen

-1
This file was deleted.

src/bootstrap/bin/rustc.rs

+1-1
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

+4
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

+1-1
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,

src/bootstrap/cc_detect.rs

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pub fn find(build: &mut Build) {
7979
let mut cfg = cc::Build::new();
8080
cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false)
8181
.target(&target).host(&build.build);
82+
if target.contains("msvc") {
83+
cfg.static_crt(true);
84+
}
8285

8386
let config = build.config.target_config.get(&target);
8487
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {

src/bootstrap/compile.rs

+26
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,21 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
746746
}
747747
}
748748

749+
fn copy_lld_to_sysroot(builder: &Builder,
750+
target_compiler: Compiler,
751+
lld_install_root: &Path) {
752+
let target = target_compiler.host;
753+
754+
let dst = builder.sysroot_libdir(target_compiler, target)
755+
.parent()
756+
.unwrap()
757+
.join("bin");
758+
t!(fs::create_dir_all(&dst));
759+
760+
let exe = exe("lld", &target);
761+
copy(&lld_install_root.join("bin").join(&exe), &dst.join(&exe));
762+
}
763+
749764
/// Cargo's output path for the standard library in a given stage, compiled
750765
/// by a particular compiler for the specified target.
751766
pub fn libstd_stamp(build: &Build, compiler: Compiler, target: Interned<String>) -> PathBuf {
@@ -895,6 +910,14 @@ impl Step for Assemble {
895910
}
896911
}
897912

913+
let lld_install = if build.config.lld_enabled && target_compiler.stage > 0 {
914+
Some(builder.ensure(native::Lld {
915+
target: target_compiler.host,
916+
}))
917+
} else {
918+
None
919+
};
920+
898921
let stage = target_compiler.stage;
899922
let host = target_compiler.host;
900923
println!("Assembling stage{} compiler ({})", stage, host);
@@ -914,6 +937,9 @@ impl Step for Assemble {
914937
copy_codegen_backends_to_sysroot(builder,
915938
build_compiler,
916939
target_compiler);
940+
if let Some(lld_install) = lld_install {
941+
copy_lld_to_sysroot(builder, target_compiler, &lld_install);
942+
}
917943

918944
// Link the compiler binary itself into place
919945
let out_dir = build.cargo_out(build_compiler, Mode::Librustc, host);

src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ pub struct Config {
8080
pub llvm_experimental_targets: String,
8181
pub llvm_link_jobs: Option<u32>,
8282

83+
pub lld_enabled: bool,
84+
8385
// rust codegen options
8486
pub rust_optimize: bool,
8587
pub rust_codegen_units: Option<u32>,
@@ -289,6 +291,7 @@ struct Rust {
289291
save_toolstates: Option<String>,
290292
codegen_backends: Option<Vec<String>>,
291293
wasm_syscall: Option<bool>,
294+
lld: Option<bool>,
292295
}
293296

294297
/// TOML representation of how each build target is configured.
@@ -475,6 +478,7 @@ impl Config {
475478
set(&mut config.quiet_tests, rust.quiet_tests);
476479
set(&mut config.test_miri, rust.test_miri);
477480
set(&mut config.wasm_syscall, rust.wasm_syscall);
481+
set(&mut config.lld_enabled, rust.lld);
478482
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
479483
config.rustc_default_linker = rust.default_linker.clone();
480484
config.musl_root = rust.musl_root.clone().map(PathBuf::from);

src/bootstrap/configure.py

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def v(*args):
6666
o("cargo-openssl-static", "build.openssl-static", "static openssl in cargo")
6767
o("profiler", "build.profiler", "build the profiler runtime")
6868
o("emscripten", None, "compile the emscripten backend as well as LLVM")
69+
o("full-tools", None, "enable all tools")
6970

7071
# Optimization and debugging options. These may be overridden by the release
7172
# channel, etc.
@@ -326,6 +327,10 @@ def set(key, value):
326327
set('build.target', value.split(','))
327328
elif option.name == 'emscripten':
328329
set('rust.codegen-backends', ['llvm', 'emscripten'])
330+
elif option.name == 'full-tools':
331+
set('rust.codegen-backends', ['llvm', 'emscripten'])
332+
set('rust.lld', True)
333+
set('build.extended', True)
329334
elif option.name == 'option-checking':
330335
# this was handled above
331336
pass

src/bootstrap/dist.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use build_helper::output;
2828

2929
use {Build, Compiler, Mode};
3030
use channel;
31-
use util::{cp_r, libdir, is_dylib, cp_filtered, copy, replace_in_file};
31+
use util::{cp_r, libdir, is_dylib, cp_filtered, copy, replace_in_file, exe};
3232
use builder::{Builder, RunConfig, ShouldRun, Step};
3333
use compile;
3434
use native;
@@ -443,6 +443,22 @@ impl Step for Rustc {
443443
t!(fs::create_dir_all(&backends_dst));
444444
cp_r(&backends_src, &backends_dst);
445445

446+
// Copy over lld if it's there
447+
if builder.config.lld_enabled {
448+
let exe = exe("lld", &compiler.host);
449+
let src = builder.sysroot_libdir(compiler, host)
450+
.parent()
451+
.unwrap()
452+
.join("bin")
453+
.join(&exe);
454+
let dst = image.join("lib/rustlib")
455+
.join(&*host)
456+
.join("bin")
457+
.join(&exe);
458+
t!(fs::create_dir_all(&dst.parent().unwrap()));
459+
copy(&src, &dst);
460+
}
461+
446462
// Man pages
447463
t!(fs::create_dir_all(image.join("share/man/man1")));
448464
let man_src = build.src.join("src/doc/man");

src/bootstrap/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ impl Build {
501501
self.out.join(&*target).join("llvm-emscripten")
502502
}
503503

504+
fn lld_out(&self, target: Interned<String>) -> PathBuf {
505+
self.out.join(&*target).join("lld")
506+
}
507+
504508
/// Output directory for all documentation for a target
505509
fn doc_out(&self, target: Interned<String>) -> PathBuf {
506510
self.out.join(&*target).join("doc")
@@ -685,7 +689,9 @@ impl Build {
685689
.and_then(|c| c.linker.as_ref()) {
686690
Some(linker)
687691
} else if target != self.config.build &&
688-
!target.contains("msvc") && !target.contains("emscripten") {
692+
!target.contains("msvc") &&
693+
!target.contains("emscripten") &&
694+
!target.contains("wasm32") {
689695
Some(self.cc(target))
690696
} else {
691697
None

0 commit comments

Comments
 (0)