Skip to content

Commit

Permalink
tc_build: kernel: Only use GNU tools for s390 when necessary
Browse files Browse the repository at this point in the history
With Linux 6.9 and LLVM 18.1.0, it is possible to build ARCH=s390 with
LLVM=1, so wire up support for it in a manner that keeps older kernel
trees and toolchains building properly.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
  • Loading branch information
nathanchance committed Apr 7, 2024
1 parent 592da6a commit 200ae6f
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions tc_build/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class KernelBuilder(Builder):
# If the user supplies their own kernel source, it must be at least this
# version to ensure that all the build commands work, as the build commands
# were written to target at least this version.
MINIMUM_SUPPORTED_VERSION = (6, 5, 0)
MINIMUM_SUPPORTED_VERSION = (6, 9, 0)

def __init__(self, arch):
super().__init__()
Expand Down Expand Up @@ -258,12 +258,6 @@ def __init__(self):

self.cross_compile = 's390x-linux-gnu-'

# LD: https://github.com/ClangBuiltLinux/linux/issues/1524
# OBJCOPY: https://github.com/ClangBuiltLinux/linux/issues/1530
# OBJDUMP: https://github.com/ClangBuiltLinux/linux/issues/859
for key in ['LD', 'OBJCOPY', 'OBJDUMP']:
self.make_variables[key] = self.cross_compile + key.lower()

def build(self):
self.toolchain_version = self.get_toolchain_version()
if self.toolchain_version <= (15, 0, 0):
Expand All @@ -272,6 +266,33 @@ def build(self):
's390 does not build with LLVM < 15.0.0, skipping build...')
return

# LD: https://github.com/ClangBuiltLinux/linux/issues/1524
# OBJCOPY: https://github.com/ClangBuiltLinux/linux/issues/1530
gnu_vars = []

# https://github.com/llvm/llvm-project/pull/75643
lld_res = subprocess.run([Path(self.toolchain_prefix, 'bin/ld.lld'), '-m', 'elf64_s390'],
capture_output=True,
check=False,
text=True)
if 'error: unknown emulation:' in lld_res.stderr:
gnu_vars.append('LD')

# https://github.com/llvm/llvm-project/pull/81841
objcopy_res = subprocess.run([
Path(self.toolchain_prefix, 'bin/llvm-objcopy'), '-I', 'binary', '-O', 'elf64-s390',
'-', '/dev/null'
],
capture_output=True,
check=False,
input='',
text=True)
if 'error: invalid output format:' in objcopy_res.stderr:
gnu_vars.append('OBJCOPY')

for key in gnu_vars:
self.make_variables[key] = self.cross_compile + key.lower()

super().build()

def can_use_ias(self):
Expand Down

0 comments on commit 200ae6f

Please sign in to comment.