From da01952b3bb960d76c1b70594ad7487392e3658e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 24 Oct 2022 14:10:44 +0200 Subject: [PATCH] Use linker plugin LTO for compiling `rustc` --- src/bootstrap/compile.rs | 20 +++++++++++++++++-- .../host-x86_64/dist-x86_64-linux/Dockerfile | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index e02a10b816408..098e08ddfbb91 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -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; @@ -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, @@ -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!( diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile index 423aba06ccaff..25488ccd5c6e5 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile @@ -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 @@ -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