Skip to content

Commit 55aaf63

Browse files
bootstrap: Build LLVM with ThinLTO on Linux64.
1 parent b447ad7 commit 55aaf63

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/bootstrap/compile.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use util::{exe, libdir, is_dylib, CiEnv};
3535
use {Compiler, Mode};
3636
use native;
3737
use tool;
38-
3938
use cache::{INTERNER, Interned};
4039
use builder::{Step, RunConfig, ShouldRun, Builder};
4140

@@ -635,20 +634,28 @@ impl Step for CodegenBackend {
635634
return;
636635
}
637636

638-
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "build");
637+
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "rustc");
639638
let mut features = builder.rustc_features().to_string();
640639
cargo.arg("--manifest-path")
641640
.arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
642641
rustc_cargo_env(builder, &mut cargo);
643642

644643
features += &build_codegen_backend(&builder, &mut cargo, &compiler, target, backend);
644+
cargo.arg("--features").arg(features);
645645

646646
let tmp_stamp = builder.cargo_out(compiler, Mode::Librustc, target)
647647
.join(".tmp.stamp");
648648

649+
if builder.config.llvm_thin_lto {
650+
cargo.deferred_arg("--")
651+
.deferred_arg("-Clink-arg=-fuse-ld=lld")
652+
.deferred_arg("-Clink-arg=-flto=thin")
653+
.deferred_arg("-Clink-arg=-O2");
654+
}
655+
649656
let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
650657
let files = run_cargo(builder,
651-
cargo.arg("--features").arg(features),
658+
&mut cargo,
652659
&tmp_stamp,
653660
false);
654661
if builder.config.dry_run {

src/bootstrap/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub struct Config {
7979
pub llvm_assertions: bool,
8080
pub llvm_optimize: bool,
8181
pub llvm_release_debuginfo: bool,
82+
pub llvm_thin_lto: bool,
8283
pub llvm_version_check: bool,
8384
pub llvm_static_stdcpp: bool,
8485
pub llvm_link_shared: bool,
@@ -246,6 +247,7 @@ struct Llvm {
246247
assertions: Option<bool>,
247248
optimize: Option<bool>,
248249
release_debuginfo: Option<bool>,
250+
thin_lto: Option<bool>,
249251
version_check: Option<bool>,
250252
static_libstdcpp: Option<bool>,
251253
targets: Option<String>,
@@ -501,6 +503,7 @@ impl Config {
501503
llvm_assertions = llvm.assertions;
502504
set(&mut config.llvm_optimize, llvm.optimize);
503505
set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
506+
set(&mut config.llvm_thin_lto, llvm.thin_lto);
504507
set(&mut config.llvm_version_check, llvm.version_check);
505508
set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
506509
set(&mut config.llvm_link_shared, llvm.link_shared);

src/bootstrap/native.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ impl Step for Llvm {
154154
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
155155
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);
156156

157+
if builder.config.llvm_thin_lto {
158+
cfg.define("LLVM_ENABLE_LTO", "Thin")
159+
.define("LLVM_ENABLE_LLD", "ON");
160+
}
161+
157162
// By default, LLVM will automatically find OCaml and, if it finds it,
158163
// install the LLVM bindings in LLVM_OCAML_INSTALL_PATH, which defaults
159164
// to /usr/bin/ocaml.

src/ci/docker/dist-x86_64-linux/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ ENV RUST_CONFIGURE_ARGS \
9393
--enable-sanitizers \
9494
--enable-profiler \
9595
--enable-compiler-docs \
96-
--set target.x86_64-unknown-linux-gnu.linker=clang
96+
--set target.x86_64-unknown-linux-gnu.linker=clang \
97+
--set target.x86_64-unknown-linux-gnu.ar=/rustroot/bin/llvm-ar \
98+
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib
9799
ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS
98100
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
99101

0 commit comments

Comments
 (0)