Skip to content

Commit c2ec608

Browse files
committed
cpu_guard test: probe a libc symbol no sanitizer interposes
cargo-careful has been red on every master merge since #355. Under -Zcareful-sanitizer (ASan) `malloc` is ASan's interceptor, linked into the executable, so the can-stay-silent test's premise (`malloc` lives in libc) is false there. The guard code is unchanged; the test now probes glibc's `gnu_get_libc_version`, which no sanitizer replaces. Verified: plain build 14/14 cpu_guard tests; `cargo +nightly careful test -Zcareful-sanitizer` passes; reverting to `malloc` fails there exactly as CI does (cpu_guard.rs:712). Scratch reproduction with -Zsanitizer=address: malloc in main image true, gnu_get_libc_version false. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011BMJnDBAfzcuQh5HeT39Rh
1 parent c79ee31 commit c2ec608

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎.claude/blackboard.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2026-10-13 — `cargo-careful` red since #355: the libc probe was ASan's `malloc`
2+
3+
- **Cause:** `cpu_guard::tests::an_address_in_libc_is_not_in_the_main_executable` used `malloc` as its libc address. CI's `cargo-careful` job runs `-Zcareful-sanitizer` (AddressSanitizer), which interposes `malloc` with an interceptor linked into the executable, so the address really is in the main image there. Red on every master merge from #355 (where the test landed) through #361; green at #354.
4+
- **Change:** the test probes glibc's `gnu_get_libc_version`, which no sanitizer replaces. The guard itself is unchanged.
5+
- **Measured here:** scratch crate with `-Zsanitizer=address`: `malloc` in main image `true`, `gnu_get_libc_version` `false`, own function `true` (plain build: false/false/true). `cargo +nightly careful test -Zcareful-sanitizer`: new test passes; with `malloc` restored it fails at `cpu_guard.rs:712`, as in CI. Plain build: 14/14 `cpu_guard` tests.
6+
17
## 2026-10-13 — CI compiles both production tiers: x86-64-v4 and Sapphire Rapids
28

39
- **Change:** `tier4-avx512-check` in `ci.yaml` is now a two-entry matrix, `x86-64-v4` (`.cargo/config-v4.toml`) and `sapphirerapids` (`.cargo/config-avx512.toml`). Each entry runs both `cargo check` feature sets and the asm-only codegen witness. Neither is executed: GitHub's runners are mostly v3. `config-avx512.toml` gains `-Dwarnings`, matching `config-v4.toml`, so both entries gate warnings and the witness script (which word-splits `CARGO_ARGS`) needs no extra quoted `--config`. The job sets `CARGO_PROFILE_{DEV,TEST}_DEBUG=0`: with `--target`, build scripts take the profile's debug level.

‎src/cpu_guard.rs‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,16 @@ mod tests {
692692
assert!(guard_is_in_main_executable());
693693
}
694694

695-
/// Can-stay-silent half: an address in a loaded system library (libc's
696-
/// `malloc`) is not in the main executable. Without this the lookup
697-
/// could be `true` everywhere and the library case would never happen.
698-
/// Assumes libc is a shared object (the default dynamic linux-gnu
699-
/// build): with `+crt-static`, `malloc` is inside the executable.
695+
/// Can-stay-silent half: an address in a loaded system library (glibc's
696+
/// `gnu_get_libc_version`) is not in the main executable. Without this
697+
/// the lookup could be `true` everywhere and the library case would never
698+
/// happen. Assumes libc is a shared object (the default dynamic linux-gnu
699+
/// build): with `+crt-static`, libc is inside the executable.
700+
///
701+
/// Not `malloc`: a sanitizer interposes it with its own copy linked into
702+
/// the executable, so under `cargo careful -Zcareful-sanitizer` (ASan)
703+
/// `malloc` really is in the main image. No sanitizer replaces
704+
/// `gnu_get_libc_version`.
700705
#[cfg(all(
701706
not(miri),
702707
target_arch = "x86_64",
@@ -707,9 +712,10 @@ mod tests {
707712
#[test]
708713
fn an_address_in_libc_is_not_in_the_main_executable() {
709714
extern "C" {
710-
fn malloc(size: usize) -> *mut core::ffi::c_void;
715+
fn gnu_get_libc_version() -> *const core::ffi::c_char;
711716
}
712-
assert!(!main_image::contains(malloc as unsafe extern "C" fn(usize) -> *mut core::ffi::c_void as usize));
717+
let in_libc = gnu_get_libc_version as unsafe extern "C" fn() -> *const core::ffi::c_char as usize;
718+
assert!(!main_image::contains(in_libc));
713719
}
714720

715721
#[test]

0 commit comments

Comments
 (0)