@@ -37,13 +37,16 @@ def __init__(self, arch):
3737 self .toolchain_version = ()
3838
3939 def build (self ):
40+ bin_folder = Path (self .toolchain_prefix , 'bin' )
4041 if self .bolt_instrumentation :
41- self .make_variables ['CC' ] = Path (self . toolchain_prefix , 'bin/ clang.inst' )
42+ self .make_variables ['CC' ] = Path (bin_folder , 'clang.inst' )
4243 # The user may have configured clang without the host target, in which
4344 # case we need to use GCC for compiling the host utilities.
4445 if self .can_use_clang_as_hostcc ():
4546 if 'CC' in self .make_variables :
4647 self .make_variables ['HOSTCC' ] = self .make_variables ['CC' ]
48+ if self ._test_clang (ld_path := f"--ld-path={ bin_folder } /ld.lld" ):
49+ self .make_variables ['HOSTLDFLAGS' ] = ld_path
4750 else :
4851 self .make_variables ['HOSTCC' ] = 'gcc'
4952 self .make_variables ['HOSTCXX' ] = 'g++'
@@ -54,7 +57,7 @@ def build(self):
5457 )
5558 return
5659 self .make_variables ['CROSS_COMPILE' ] = self .cross_compile
57- self .make_variables ['LLVM' ] = f"{ self . toolchain_prefix } /bin /"
60+ self .make_variables ['LLVM' ] = f"{ bin_folder } /"
5861 if not self .can_use_ias ():
5962 self .make_variables ['LLVM_IAS' ] = '0'
6063 self .make_variables ['O' ] = self .folders .build
@@ -136,18 +139,35 @@ def get_toolchain_version(self):
136139 return self .toolchain_version
137140
138141 def can_use_clang_as_hostcc (self ):
142+ return self ._test_clang ('-c' )
143+
144+ def needs_binutils (self ):
145+ return not self .can_use_ias ()
146+
147+ def _test_clang (self , args = None ):
139148 clang = Path (self .toolchain_prefix , 'bin/clang' )
149+
150+ clang_args = ['-x' , 'c' , '-o' , '/dev/null' , '-' ]
151+ if args :
152+ if isinstance (args , str ):
153+ clang_args .append (args )
154+ elif isinstance (args , list ):
155+ clang_args .extend (args )
156+ else :
157+ raise ValueError (f"Invalid type for args: { args } " )
158+
159+ prog = 'int main(void) { return 0; }'
160+
140161 try :
141- subprocess .run ([clang , '-x' , 'c' , '-c' , '-o' , '/dev/null' , '/dev/null' ],
162+ subprocess .run ([clang , * clang_args ],
142163 capture_output = True ,
143- check = True )
164+ check = True ,
165+ input = prog ,
166+ text = True )
144167 except subprocess .CalledProcessError :
145168 return False
146169 return True
147170
148- def needs_binutils (self ):
149- return not self .can_use_ias ()
150-
151171
152172class ArmKernelBuilder (KernelBuilder ):
153173
0 commit comments