Skip to content

Use linker plugin LTO for compiling rustc #101524

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use serde::Deserialize;
use crate::builder::Cargo;
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER};
use crate::config::{LlvmLibunwind, RustcLto, TargetSelection};
use crate::config::{LlvmLibunwind, TargetSelection};
use crate::dist;
use crate::native;
use crate::tool::SourceType;
Expand Down Expand Up @@ -702,7 +702,7 @@ impl Step for Rustc {
}

// cfg(bootstrap): remove if condition once the bootstrap compiler supports dylib LTO
if compiler.stage != 0 {
/*if compiler.stage != 0 {
match builder.config.rust_lto {
RustcLto::Thin | RustcLto::Fat => {
// Since using LTO for optimizing dylibs is currently experimental,
Expand All @@ -721,6 +721,22 @@ impl Step for Rustc {
}
RustcLto::ThinLocal => { /* Do nothing, this is the default */ }
}
}*/

if compiler.stage == 1 {
// let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin");
// let clang = build_bin.join("clang");
// let clang = PathBuf::from("/projects/personal/llvm-project/build/install/bin/clang");
cargo.rustflag("-Clinker-plugin-lto");
// cargo.rustflag(&format!("-Clinker={}", clang.display()));
// cargo.rustflag("-Clink-arg=-fuse-ld=lld");

// let path = builder.ensure(CrtBeginEnd {
// target
// });
// cargo.rustflag(&format!("-Clink-args=-L{}", path.display()));
// cargo.rustflag(&format!("-Clink-args=-B{}", path.display()));
// cargo.rustflag(&format!("-Clink-args=--gcc-toolchain={}", path.display()));
}

builder.info(&format!(
Expand Down
3 changes: 3 additions & 0 deletions src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ RUN curl -LS -o perf.zip https://github.com/rust-lang/rustc-perf/archive/$PERF_C
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

RUN yum install -y libgcc.x86_64 libgcc.i686

ENV PGO_HOST=x86_64-unknown-linux-gnu

ENV HOSTS=x86_64-unknown-linux-gnu
Expand All @@ -77,6 +79,7 @@ ENV RUST_CONFIGURE_ARGS \
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
--set llvm.thin-lto=true \
--set llvm.ninja=false \
--set llvm.clang=true \
--set rust.jemalloc \
--set rust.use-lld=true \
--set rust.lto=thin
Expand Down