Skip to content

Commit e2c9bc3

Browse files
authored
Failure when CFLAGS provides -O3 (#900)
* Failure when CFLAGS provides -O3 * Ensure jitter entropy compiled w/o optimizations
1 parent cea4296 commit e2c9bc3

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

.github/workflows/tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,23 @@ jobs:
603603
- name: Run cargo test
604604
working-directory: "path has spaces/aws-lc-rs"
605605
run: cargo test --tests -p aws-lc-rs --features bindgen
606+
607+
hostile-environment:
608+
if: github.repository_owner == 'aws'
609+
name: Hostile environment
610+
strategy:
611+
fail-fast: false
612+
matrix:
613+
os: [ ubuntu-latest, macos-latest ]
614+
env:
615+
CFLAGS: '-O3'
616+
runs-on: ubuntu-latest
617+
steps:
618+
- uses: actions/checkout@v4
619+
with:
620+
submodules: 'recursive'
621+
- uses: dtolnay/rust-toolchain@stable
622+
- name: Run tests
623+
run: cargo test -p aws-lc-rs --all-targets
624+
- name: Run tests w/ FIPS
625+
run: cargo test -p aws-lc-rs --all-targets --features fips

aws-lc-sys/builder/cc_builder.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ mod x86_64_unknown_linux_musl;
1616

1717
use crate::{
1818
cargo_env, effective_target, emit_warning, env_var_to_bool, execute_command, get_crate_cflags,
19-
is_no_asm, optional_env_optional_crate_target, out_dir, requested_c_std, set_env_for_target,
20-
target, target_arch, target_env, target_os, CStdRequested, OutputLibType,
19+
is_no_asm, optional_env_optional_crate_target, optional_env_target, out_dir, requested_c_std,
20+
set_env_for_target, target, target_arch, target_env, target_os, CStdRequested, OutputLibType,
2121
};
2222
use std::cell::Cell;
2323
use std::collections::HashMap;
@@ -373,7 +373,19 @@ impl CcBuilder {
373373
option.apply_cc(&mut je_builder);
374374
}
375375

376-
let compiler = je_builder.get_compiler();
376+
let compiler = if let Some(original_cflags) = optional_env_target("CFLAGS") {
377+
let mut new_cflags = original_cflags.clone();
378+
new_cflags.push_str(" -O0");
379+
set_env_for_target("CFLAGS", &new_cflags);
380+
// cc-rs currently prioritizes flags provided by CFLAGS over the flags provided by the build script.
381+
// The environment variables used by the compiler are set when `get_compiler` is called.
382+
let compiler = je_builder.get_compiler();
383+
set_env_for_target("CFLAGS", &original_cflags);
384+
compiler
385+
} else {
386+
je_builder.get_compiler()
387+
};
388+
377389
je_builder.define("AWSLC", "1");
378390
je_builder.pic(true);
379391
if target_os() == "windows" && compiler.is_like_msvc() {
@@ -391,6 +403,7 @@ impl CcBuilder {
391403
.flag("-Wextra")
392404
.flag("-Wall")
393405
.flag("-pedantic")
406+
// Compilation will fail if optimizations are enabled.
394407
.flag("-O0")
395408
.flag("-fwrapv")
396409
.flag("-Wconversion");

0 commit comments

Comments
 (0)