Skip to content

Commit 9204901

Browse files
committed
Disable ASLR when running runtime benchmarks
1 parent 4b6d196 commit 9204901

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

collector/src/runtime.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,37 @@ pub fn bench_runtime(rustc: &str, id: Option<&str>, benchmark_dir: PathBuf) -> a
1818
for binary in binaries {
1919
let name = binary.path.file_name().and_then(|s| s.to_str()).unwrap();
2020

21-
let result = Command::new(&binary.path).arg("benchmark").output()?;
22-
if !result.status.success() {
23-
anyhow::bail!(
24-
"Failed to run runtime benchmark {name}\n{}\n{}",
25-
String::from_utf8_lossy(&result.stdout),
26-
String::from_utf8_lossy(&result.stderr)
27-
);
28-
} else {
29-
log::info!("Successfully ran runtime benchmark {name}",);
30-
31-
let data: Vec<BenchmarkResult> = serde_json::from_slice(&result.stdout)?;
32-
// TODO: do something with the result
33-
println!("{name}: {:?}", data);
34-
}
21+
let data: Vec<BenchmarkResult> = execute_runtime_binary(&binary.path, name)?;
22+
// TODO: do something with the result
23+
println!("{name}: {:?}", data);
3524
}
3625

3726
Ok(())
3827
}
3928

29+
fn execute_runtime_binary(binary: &Path, name: &str) -> anyhow::Result<Vec<BenchmarkResult>> {
30+
// Turn off ASLR
31+
let mut command = Command::new("setarch");
32+
command.arg(std::env::consts::ARCH);
33+
command.arg("-R");
34+
command.arg(binary);
35+
command.arg("benchmark");
36+
37+
let result = command.output()?;
38+
39+
if !result.status.success() {
40+
return Err(anyhow::anyhow!(
41+
"Failed to run runtime benchmark {name}\n{}\n{}",
42+
String::from_utf8_lossy(&result.stdout),
43+
String::from_utf8_lossy(&result.stderr)
44+
));
45+
}
46+
47+
log::info!("Successfully ran runtime benchmark {name}");
48+
49+
Ok(serde_json::from_slice(&result.stdout)?)
50+
}
51+
4052
/// Compiles all runtime benchmarks and returns the stdout output of Cargo.
4153
fn compile_runtime_benchmarks(toolchain: &LocalToolchain, dir: &Path) -> anyhow::Result<Vec<u8>> {
4254
let result = Command::new(&toolchain.cargo)

0 commit comments

Comments
 (0)