Skip to content

Commit

Permalink
Initial LoongArch support
Browse files Browse the repository at this point in the history
The LLD port is still in review, so do not add it to the default list of
architectures.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
  • Loading branch information
nathanchance committed Jun 28, 2023
1 parent b422d54 commit 1563255
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import lkt.arm64
import lkt.hexagon
import lkt.i386
import lkt.loongarch
import lkt.mips
import lkt.powerpc
import lkt.riscv
Expand All @@ -40,14 +41,17 @@
's390',
'x86_64',
]
EXPERIMENTAL_ARCHITECTURES = [
'loongarch',
]


def parse_arguments():
parser = ArgumentParser(description='Build a set of Linux kernels with LLVM')

parser.add_argument('-a',
'--architectures',
choices=SUPPORTED_ARCHITECTURES,
choices=[*SUPPORTED_ARCHITECTURES, *EXPERIMENTAL_ARCHITECTURES],
default=SUPPORTED_ARCHITECTURES,
metavar='ARCH',
nargs='+',
Expand Down Expand Up @@ -183,6 +187,7 @@ def interrupt_handler(_signum, _frame):
'arm64': lkt.arm64.Arm64LKTRunner,
'hexagon': lkt.hexagon.HexagonLKTRunner,
'i386': lkt.i386.I386LKTRunner,
'loongarch': lkt.loongarch.LoongArchLKTRunner,
'mips': lkt.mips.MipsLKTRunner,
'powerpc': lkt.powerpc.PowerPCLKTRunner,
'riscv': lkt.riscv.RISCVLKTRunner,
Expand Down
90 changes: 90 additions & 0 deletions lkt/loongarch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python3

import lkt.runner

KERNEL_ARCH = 'loongarch'
CLANG_TARGET = 'loongarch64-linux-gnusf'

# See https://github.com/ClangBuiltLinux/linux/issues/1787#issuecomment-1603764274 for more info
BROKEN_CONFIGS = [
'CONFIG_MODULES=n', # need __attribute__((model("extreme"))) in clang
'CONFIG_CRASH_DUMP=n', # selects RELOCATABLE
'CONFIG_RELOCATABLE=n', # ld.lld prepopulates GOT?
]


class LoongArchLLVMKernelRunner(lkt.runner.LLVMKernelRunner):

def __init__(self):
super().__init__()

self.boot_arch = KERNEL_ARCH
self.image_target = 'vmlinuz.efi'


class LoongArchLKTRunner(lkt.runner.LKTRunner):

def __init__(self):
super().__init__()

self.make_vars['ARCH'] = KERNEL_ARCH
self.make_vars['LLVM_IAS'] = 1

self._clang_target = CLANG_TARGET

def _add_defconfig_runners(self):
runner = LoongArchLLVMKernelRunner()
runner.bootable = True
runner.configs = ['defconfig', *BROKEN_CONFIGS]
runner.only_test_boot = self.only_test_boot
self._runners.append(runner)

runner = LoongArchLLVMKernelRunner()
runner.bootable = True
runner.configs = ['defconfig', *BROKEN_CONFIGS, 'CONFIG_LTO_CLANG_THIN=y']
runner.only_test_boot = self.only_test_boot
self._runners.append(runner)

def _add_otherconfig_runners(self):
runner = LoongArchLLVMKernelRunner()
# Eventually, allmodconfig instead
runner.configs = ['allyesconfig', *BROKEN_CONFIGS]
if 'CONFIG_WERROR' in self.lsm.configs:
runner.configs.append('CONFIG_WERROR=n')
self._runners.append(runner)

runner = LoongArchLLVMKernelRunner()
runner.configs = [
'allyesconfig',
*BROKEN_CONFIGS,
'CONFIG_FTRACE=n',
'CONFIG_GCOV_KERNEL=n',
'CONFIG_LTO_CLANG_THIN=y',
]
if 'CONFIG_WERROR' in self.lsm.configs:
runner.configs.append('CONFIG_WERROR=n')
self._runners.append(runner)

def run(self):
if self._llvm_version < (17, 0, 0):
return self._skip(
'LLVM < 17.0.0',
'LoongArch requires LLVM 17.0.0 or newer to build properly with LLVM=1')

if '65b66f3531c2' not in self.lsm.commits:
print_text = (
'LoongArch needs the following series from Linux 6.5 to build properly:\n'
'\n'
' * https://git.kernel.org/torvalds/l/65b66f3531c2756356534b4927ba2d4fbbef603f\n'
'\n'
'Provide a kernel tree with Linux 6.5+ or one with this series to build LoongArch kernels.'
)
return self._skip('missing 65b66f3531c2', print_text)

if 'def' in self.targets:
self._add_defconfig_runners()

if not self.only_test_boot and 'other' in self.targets:
self._add_otherconfig_runners()

return super().run()
5 changes: 5 additions & 0 deletions lkt/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def __init__(self, linux_source):
self._add_commit('788dcee0306e1', r"KBUILD_CFLAGS \+= -mlong-calls",
'arch/hexagon/Makefile')

# Commit: Makefile: Add loongarch target flag for Clang compilation
# Link: https://git.kernel.org/linus/65b66f3531c2756356534b4927ba2d4fbbef603f
# First appeared: v6.5-rc1
self._add_commit('65b66f3531c2', 'loongarch64-linux-gnusf', 'scripts/Makefile.clang')

# Commit: s390: always build relocatable kernel
# Link: https://git.kernel.org/linus/80ddf5ce1c9291cb175d52ed1227134ad48c47ee
# First appeared: v6.1-rc5~10^2~1
Expand Down

0 comments on commit 1563255

Please sign in to comment.