Skip to content

Commit

Permalink
Add BPF rustc option to reduce the optimizations to safer level (#17590
Browse files Browse the repository at this point in the history
…) (#17594)

(cherry picked from commit 831e87c)

Co-authored-by: Dmitri Makarov <dmakarov@users.noreply.github.com>
  • Loading branch information
mergify[bot] and dmakarov authored May 31, 2021
1 parent e36337a commit 3c7c6da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
22 changes: 11 additions & 11 deletions programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,19 +1269,19 @@ fn assert_instruction_count() {
#[cfg(feature = "bpf_rust")]
{
programs.extend_from_slice(&[
("solana_bpf_rust_128bit", 584),
("solana_bpf_rust_alloc", 5072),
("solana_bpf_rust_custom_heap", 367),
("solana_bpf_rust_128bit", 572),
("solana_bpf_rust_alloc", 8906),
("solana_bpf_rust_custom_heap", 539),
("solana_bpf_rust_dep_crate", 2),
("solana_bpf_rust_external_spend", 336),
("solana_bpf_rust_iter", 279),
("solana_bpf_rust_many_args", 191),
("solana_bpf_rust_mem", 1670),
("solana_bpf_rust_noop", 324),
("solana_bpf_rust_external_spend", 521),
("solana_bpf_rust_iter", 724),
("solana_bpf_rust_many_args", 237),
("solana_bpf_rust_mem", 2297),
("solana_bpf_rust_noop", 495),
("solana_bpf_rust_param_passing", 46),
("solana_bpf_rust_rand", 327),
("solana_bpf_rust_sanity", 595),
("solana_bpf_rust_sha", 22417),
("solana_bpf_rust_rand", 498),
("solana_bpf_rust_sanity", 917),
("solana_bpf_rust_sha", 29099),
]);
}

Expand Down
2 changes: 2 additions & 0 deletions sdk/bpf/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ 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="-C lto=no -C opt-level=2"
4 changes: 3 additions & 1 deletion sdk/cargo-build-bpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ 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"));

let mut rust_flags = String::from("-C lto=no");
rust_flags.push_str(" -C opt-level=2");
env::set_var("RUSTFLAGS", rust_flags);
let cargo_build = PathBuf::from("cargo");
let mut cargo_build_args = vec![
"+bpf",
Expand Down

0 comments on commit 3c7c6da

Please sign in to comment.