Skip to content

Commit 90770f5

Browse files
committed
Disable ASLR during benchmarking for target process only
1 parent 6d62d87 commit 90770f5

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

.github/workflows/test-suite.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,10 +1012,6 @@ jobs:
10121012
with:
10131013
ref: ${{ fromJson(inputs.branch).ref }}
10141014
fetch-depth: 0
1015-
# ASLR can cause a lot of noise due to missed sse opportunities for memcpy
1016-
# and other operations, so we disable it during benchmarking.
1017-
- name: Disable ASLR
1018-
run: echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
10191015
- name: apt
10201016
run: |
10211017
set -x

benchmark/benchmark.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ function runValgrindPhpCgiCommand(
109109
): array {
110110
global $phpCgi;
111111

112+
// ASLR can cause a lot of noise due to missed sse opportunities for memcpy and other operations
113+
$aslrDisable = checkPersonalityAslrDisablePermission();
114+
112115
$profileOut = __DIR__ . "/profiles/callgrind.out.$name";
113116
if ($jit) {
114117
$profileOut .= '.jit';
115118
}
116119

117120
$process = runCommand([
121+
...($aslrDisable ? ['setarch', '--addr-no-randomize'] : []),
118122
'valgrind',
119123
'--tool=callgrind',
120124
'--dump-instr=yes',

benchmark/shared.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,16 @@ function cloneRepo(string $path, string $url) {
7272
}
7373
runCommand(['git', 'clone', '-q', '--end-of-options', $url, $repo], dirname($path));
7474
}
75+
76+
function checkPersonalityAslrDisablePermission(): bool {
77+
$processResult = runCommand(['sh', '-c', 'setarch --addr-no-randomize sh -c \'cat /proc/self/personality\' || true'], null, false);
78+
79+
$n = hexdec($processResult->stdout);
80+
if (($n & 0x4_00_00) === 0) {
81+
fwrite(STDOUT, 'Unable to disable ASLR: ' . trim($processResult->stderr) . "\n");
82+
83+
return false;
84+
}
85+
86+
return true;
87+
}

0 commit comments

Comments
 (0)