Skip to content

Commit

Permalink
Re-enable LTO (solana-labs#22287)
Browse files Browse the repository at this point in the history
LTO seems to work fine now. It was possibly fixed by either the LLVM13 upgrade
or by alessandrod/rust@b2ed47a,
which fixed a LTO issue with tests.
  • Loading branch information
alessandrod authored Jan 5, 2022
1 parent bb3a1b6 commit 959ea26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
2 changes: 0 additions & 2 deletions sdk/bpf/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ export CC="$bpf_sdk/dependencies/bpf-tools/llvm/bin/clang"
export AR="$bpf_sdk/dependencies/bpf-tools/llvm/bin/llvm-ar"
export OBJDUMP="$bpf_sdk/dependencies/bpf-tools/llvm/bin/llvm-objdump"
export OBJCOPY="$bpf_sdk/dependencies/bpf-tools/llvm/bin/llvm-objcopy"

export RUSTFLAGS="${RUSTFLAGS} -C lto=no"
29 changes: 12 additions & 17 deletions sdk/cargo-build-bpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,25 +515,20 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m
env::set_var("AR", llvm_bin.join("llvm-ar"));
env::set_var("OBJDUMP", llvm_bin.join("llvm-objdump"));
env::set_var("OBJCOPY", llvm_bin.join("llvm-objcopy"));
const RF_LTO: &str = "-C lto=no";
let mut rustflags = match env::var("RUSTFLAGS") {
Ok(rf) => {
if rf.contains(&RF_LTO) {
rf
} else {
format!("{} {}", rf, RF_LTO)
}

if let Ok(mut rustflags) = env::var("RUSTFLAGS") {
if cfg!(windows) && !rustflags.contains("-C linker=") {
let ld_path = llvm_bin.join("ld.lld");
rustflags = format!("{} -C linker={}", rustflags, ld_path.display());
}

if config.verbose {
println!("RUSTFLAGS={}", rustflags);
}
_ => RF_LTO.to_string(),

env::set_var("RUSTFLAGS", rustflags);
};
if cfg!(windows) && !rustflags.contains("-C linker=") {
let ld_path = llvm_bin.join("ld.lld");
rustflags = format!("{} -C linker={}", rustflags, ld_path.display());
}
if config.verbose {
println!("RUSTFLAGS={}", rustflags);
}
env::set_var("RUSTFLAGS", rustflags);

let cargo_build = PathBuf::from("cargo");
let mut cargo_build_args = vec![
"+bpf",
Expand Down

0 comments on commit 959ea26

Please sign in to comment.