Skip to content

Commit a0579bc

Browse files
committed
tc_build: tools: Check for multicall binary in find_host_cc()
There are two minor problems with find_host_cc() when using a multicall binary setup. The first is calling .resolve() on a multicall binary, which breaks the multicall setup because the symlink is how the multicall binary works in the first place. Avoid calling .resolve() in the case of multicall binaries. The second is clang-<ver> is not present in a multicall setup, so a versioned binary from elsewhere in PATH can be chosen before a multicall binary because plain clang is checked after the versioned binaries. Check if the first clang in PATH is a multicall binary and use it if so. Otherwise, fallback to looking at versioned binaries first then the unversioned clang so that newer versions of clang, such as those from apt.llvm.org, are chosen first. While in the area, use an else branch for the for loop that looks for compilers, saving a couple lines and a cc check. Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 25bb27e commit a0579bc

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tc_build/tools.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def __init__(self):
2828
self.merge_fdata = None
2929
self.perf2bolt = None
3030

31+
def cc_is_multicall(self, cc):
32+
return Path(cc).resolve().name == 'llvm'
33+
3134
def find_host_ar(self):
3235
# GNU ar is the default, no need for llvm-ar if using GCC
3336
if not self.cc_is_clang:
@@ -40,16 +43,26 @@ def find_host_ar(self):
4043

4144
def find_host_cc(self):
4245
# resolve() is called here and below to get /usr/lib/llvm-#/bin/... for
43-
# versioned LLVM binaries on Debian and Ubuntu.
46+
# versioned LLVM binaries on Debian and Ubuntu. We do not want to
47+
# resolve a multicall binary though, as the symlink is how it works
48+
# properly.
4449
if (cc := self.from_env('CC')):
45-
return cc.resolve()
50+
return cc if self.cc_is_multicall(cc) else cc.resolve()
51+
52+
# As a special case, see if the first clang command in PATH is a
53+
# multicall binary, as there will be no clang-<ver> binary or symlink,
54+
# so the versioned binary logic below may result in a clang-<ver>
55+
# binary from PATH "overriding" the clang symlink to llvm. We generally
56+
# want clang-<ver> to override clang though because clang-<ver> may be
57+
# newer than a plain clang binary (such as when using apt.llvm.org).
58+
if (clang := shutil.which('clang')) and self.cc_is_multicall(clang):
59+
return Path(clang)
4660

4761
possible_c_compilers = [*self.generate_versioned_binaries(), 'clang', 'gcc']
4862
for compiler in possible_c_compilers:
4963
if (cc := shutil.which(compiler)):
5064
break
51-
52-
if not cc:
65+
else:
5366
raise RuntimeError('Neither clang nor gcc could be found on your system?')
5467

5568
return Path(cc).resolve() # resolve() for Debian/Ubuntu variants

0 commit comments

Comments
 (0)