Skip to content

Commit aaec068

Browse files
authored
Merge pull request ClangBuiltLinux#316 from nathanchance/handle-sframe-mismatch
Avoid .sframe version mismatch errors
2 parents 9c525ea + da99030 commit aaec068

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

tc_build/binutils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from pathlib import Path
55
import platform
6+
import subprocess
67
from tempfile import TemporaryDirectory
78

89
from tc_build.builder import Builder
@@ -52,6 +53,15 @@ def build(self):
5253
self.configure_vars['CFLAGS'] = ' '.join(self.cflags)
5354
self.configure_vars['CXXFLAGS'] = ' '.join(self.cflags)
5455

56+
# Avoid "input SFrame sections with different format versions prevent
57+
# .sframe generation" error by discarding .sframe altogether if
58+
# possible, as we may be linking against libraries with their own
59+
# .sframe sections and versions.
60+
ld_help = subprocess.run(['ld', '--help'], capture_output=True, check=True,
61+
text=True).stdout
62+
if '--discard-sframe' in ld_help:
63+
self.configure_vars['LDFLAGS'] = '-Wl,--discard-sframe'
64+
5565
self.clean_build_folder()
5666
self.folders.build.mkdir(exist_ok=True, parents=True)
5767
tc_build.utils.print_header(f"Building {self.target} binutils")

tc_build/kernel.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

152172
class ArmKernelBuilder(KernelBuilder):
153173

0 commit comments

Comments
 (0)