Skip to content

Commit f2912ef

Browse files
committed
tc_build: Enable '--conservative-instrumentation' for BOLT on Apple Silicon
When performing BOLT on Apple Silicon (such as when building in a UTM virtual machine), running clang hangs due to instrumentation between exclusive load and store instructions (see the LLVM issue linked in the comments for more information). Detect when running on Apple Silicon and enable the conservative instrumentation option to avoid hitting this issue. Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 18c0282 commit f2912ef

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tc_build/llvm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def bolt_clang(self):
7878
clang_inst,
7979
clang,
8080
]
81+
# When running an instrumented binary on certain platforms (namely
82+
# Apple Silicon), there may be hangs due to instrumentation in
83+
# between exclusive load and store instructions:
84+
# https://github.com/llvm/llvm-project/issues/153492
85+
# Enable conservative instrumentation to avoid this.
86+
if tc_build.utils.cpu_is_apple_silicon():
87+
clang_inst_cmd.append('--conservative-instrumentation')
8188
self.run_cmd(clang_inst_cmd)
8289

8390
self.bolt_builder.bolt_instrumentation = True

tc_build/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#!/usr/bin/env python3
22

3+
from pathlib import Path
34
import subprocess
45
import sys
6+
import re
57
import time
68

79

10+
def cpu_is_apple_silicon():
11+
cpuinfo = Path('/proc/cpuinfo').read_text(encoding='utf-8')
12+
if match := re.search(r"implementer\s+:\s+(\w+)", cpuinfo):
13+
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/include/asm/cputype.h?h=v6.17-rc4#n62
14+
return match.groups()[0] == '0x61'
15+
# If we cannot prove that it is Apple Silicon, we assume it is not
16+
return False
17+
18+
819
def create_gitignore(folder):
920
folder.joinpath('.gitignore').write_text('*\n', encoding='utf-8')
1021

0 commit comments

Comments
 (0)