From 577ade67ad3099c8a1d627511347d867a2c10ea9 Mon Sep 17 00:00:00 2001 From: Paul Metzger Date: Fri, 21 Nov 2025 09:06:48 +0000 Subject: [PATCH 1/9] Added libmd targets CheriBSDtest depends on libxo which in turn depends on libmd. --- pycheribuild/projects/cross/libmd.py | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 pycheribuild/projects/cross/libmd.py diff --git a/pycheribuild/projects/cross/libmd.py b/pycheribuild/projects/cross/libmd.py new file mode 100644 index 000000000..773a40cb4 --- /dev/null +++ b/pycheribuild/projects/cross/libmd.py @@ -0,0 +1,73 @@ +# +# Copyright (c) 2025-2026 Paul Metzger +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +import typing + +from .crosscompileproject import CrossCompileAutotoolsProject, DefaultInstallDir, GitRepository, MakeCommandKind +from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase +from ...utils import classproperty + + +class BuildLibmd(CrossCompileAutotoolsProject): + _always_add_suffixed_targets = True + _can_use_autogen_sh = True + _supported_architectures = ( + CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, + ) + _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 + make_kind = MakeCommandKind.GnuMake + is_sdk_target = False + repository = GitRepository("https://git.hadrons.org/git/libmd.git") + + @classproperty + def default_install_dir(self): + return DefaultInstallDir.ROOTFS_LOCALBASE + + @classmethod + def dependencies(cls, config) -> "tuple[str, ...]": + ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls) + return (ti.musl_target,) + + def setup(self) -> None: + super().setup() + # Remove dependency on libgcc_eh + self.COMMON_LDFLAGS.append("--unwindlib=none") + # Remove dependcy on libgcc_s + self.COMMON_LDFLAGS.append("-Wc,--unwindlib=none") + + def configure(self, **kwargs): + if not self.configure_command.exists(): + self.run_cmd(self.source_dir / "autogen", cwd=self.source_dir) + super().configure(**kwargs) + + def compile(self, **kwargs): + self.run_make() + super().compile(**kwargs) + + def install(self, **kwargs): + self.run_make_install() + super().install(**kwargs) From 09bc465bed34a2f6ff35015ef0632e1de68e2a3b Mon Sep 17 00:00:00 2001 From: Paul Metzger Date: Fri, 21 Nov 2025 10:28:23 +0000 Subject: [PATCH 2/9] Added libbsd targets This is a dependency of the stand-alone CheriBSD test suite. --- pycheribuild/projects/cross/libbsd.py | 98 +++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 pycheribuild/projects/cross/libbsd.py diff --git a/pycheribuild/projects/cross/libbsd.py b/pycheribuild/projects/cross/libbsd.py new file mode 100644 index 000000000..d1e8a4752 --- /dev/null +++ b/pycheribuild/projects/cross/libbsd.py @@ -0,0 +1,98 @@ +# +# Copyright (c) 2025-2026 Paul Metzger +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +import typing + +from .crosscompileproject import CrossCompileAutotoolsProject, DefaultInstallDir, GitRepository, MakeCommandKind +from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase +from ...utils import classproperty + + +class BuildLibbsd(CrossCompileAutotoolsProject): + _always_add_suffixed_targets = True + _can_use_autogen_sh = True + _supported_architectures = ( + CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, + ) + _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 + make_kind = MakeCommandKind.GnuMake + # `default_branch` is set because the build scripts assume that + # a git tag is checked out. In more detail ./get-version returns an + # empty string if main is checked out. + repository = GitRepository("https://gitlab.freedesktop.org/libbsd/libbsd.git", default_branch="0.12.2") + + @classproperty + def default_install_dir(self): + return DefaultInstallDir.ROOTFS_LOCALBASE + + @classmethod + def dependencies(cls, config) -> "tuple[str, ...]": + ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls) + return ti.musl_target, "libmd" + + def _apply_patch(self) -> None: + patch = """ +diff --git a/src/merge.c b/src/merge.c +index 3f1b3fb..f8cb602 100644 +--- a/src/merge.c ++++ b/src/merge.c +@@ -84,8 +84,8 @@ static void insertionsort(unsigned char *, size_t, size_t, + */ + /* Assumption: PSIZE is a power of 2. */ + #define EVAL(p) (unsigned char **) \\ +- (((unsigned char *)p + PSIZE - 1 - \\ +- (unsigned char *)0) & ~(PSIZE - 1)) ++ __builtin_cheri_address_set(p, ((__builtin_cheri_address_get(p) + PSIZE - 1 - \\ ++ 0) & ~(PSIZE - 1))) + + /* + * Arguments are as for qsort. +""" + self.write_file(self.source_dir / "merge.patch", patch, overwrite=True) + self.run_cmd("git", "restore", ".", cwd=self.source_dir) + self.run_cmd("git", "apply", "merge.patch", cwd=self.source_dir) + + def setup(self) -> None: + super().setup() + # Remove dependency on libgcc_eh + self.COMMON_LDFLAGS.append("--unwindlib=none") + # Remove dependcy on libgcc_s + self.COMMON_LDFLAGS.append("-Wc,--unwindlib=none") + + def configure(self, **kwargs): + if not self.configure_command.exists(): + self.run_cmd(self.source_dir / "autogen", cwd=self.source_dir) + super().configure(**kwargs) + + def compile(self, **kwargs): + self._apply_patch() + self.run_make() + super().compile() + + def install(self, **kwargs): + self.run_make_install() + super().install(**kwargs) From a1d99b784b0b94eeb522384f1b8d865e91066b1b Mon Sep 17 00:00:00 2001 From: Paul Metzger Date: Fri, 21 Nov 2025 11:50:28 +0000 Subject: [PATCH 3/9] Added libxo targets This is a dependency of the stand-alone CheriBSD test suite. --- pycheribuild/projects/cross/libxo.py | 87 ++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 pycheribuild/projects/cross/libxo.py diff --git a/pycheribuild/projects/cross/libxo.py b/pycheribuild/projects/cross/libxo.py new file mode 100644 index 000000000..bcfe96c9d --- /dev/null +++ b/pycheribuild/projects/cross/libxo.py @@ -0,0 +1,87 @@ +# +# Copyright (c) 2025-2026 Paul Metzger +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +import typing + +from .crosscompileproject import CrossCompileAutotoolsProject, DefaultInstallDir, GitRepository, MakeCommandKind +from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase +from ...utils import classproperty + + +class BuildLibxo(CrossCompileAutotoolsProject): + _always_add_suffixed_targets = True + _can_use_autogen_sh = True + _supported_architectures = ( + CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, + ) + _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 + make_kind = MakeCommandKind.GnuMake + repository = GitRepository("https://github.com/Juniper/libxo.git") + + @classproperty + def default_install_dir(self): + return DefaultInstallDir.ROOTFS_LOCALBASE + + @classmethod + def dependencies(cls, config) -> "tuple[str, ...]": + ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls) + return ti.musl_target, "libbsd", "libmd" + + def _patch_to_use_libbsd(self, path): + self.run_cmd("sed", "-i", "s|||g", path, cwd=self.source_dir) + + def _patch_includes(self) -> None: + self._patch_to_use_libbsd("libxo/xo_encoder.c") + self._patch_to_use_libbsd("xopo/xopo.c") + + def _patch_configure_ac(self) -> None: + self.run_cmd("sed", "-i", "s|AC_FUNC_REALLOC|#AC_FUNC_REALLOC|g", "configure.ac", cwd=self.source_dir) + self.run_cmd("sed", "-i", "s|AC_FUNC_MALLOC|#AC_FUNC_MALLOC|g", "configure.ac", cwd=self.source_dir) + + def configure(self, **kwargs): + # Don't depend on libgcc_s. If this isn't set then clang wants to link + # with libgcc_s, which is not available on Morello Linux. + self.LDFLAGS.append("--unwindlib=none") + # This prompts libtool to pass '--unwindlib=none' to clang during + # linking. Libtool ignores "--unwindlib=none" and needs + # "-Wc,--unwindlib=none" instead. "-Wc,--unwindlib=none" is turned + # into "--unwindlib=none" by libtool when it invokes clang. + self.CFLAGS.append("-Wc,--unwindlib=none") + + self._patch_configure_ac() + self._patch_includes() + self.run_shell_script("sh bin/setup.sh", shell="sh", cwd=self.source_dir) + + super().configure(**kwargs) + + def compile(self, **kwargs): + self.run_make() + super().compile(**kwargs) + + def install(self, **kwargs): + self.run_make_install() + super().install(**kwargs) From 11fb9452bc3c27fcc88fe7032a825ec27af3d11d Mon Sep 17 00:00:00 2001 From: Paul Metzger Date: Tue, 14 Apr 2026 15:11:02 +0100 Subject: [PATCH 4/9] Added stand-alone CheriBSD test suite targets Added targets for the stand-alone test suite, including flags to avoid linking with libgcc_s, which isn't available on CHERI Alliance Linux. --- .../projects/cross/cheriportableostests.py | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 pycheribuild/projects/cross/cheriportableostests.py diff --git a/pycheribuild/projects/cross/cheriportableostests.py b/pycheribuild/projects/cross/cheriportableostests.py new file mode 100644 index 000000000..2ba129ccc --- /dev/null +++ b/pycheribuild/projects/cross/cheriportableostests.py @@ -0,0 +1,110 @@ +# +# Copyright (c) 2025-2026 Paul Metzger +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +import os +import typing + +from .crosscompileproject import CrossCompileMakefileProject, DefaultInstallDir, GitRepository, MakeCommandKind +from ...config.compilation_targets import CompilationTargets, LinuxTargetInfoBase +from ...utils import classproperty + + +class BuildPortableOSTests(CrossCompileMakefileProject): + _always_add_suffixed_targets = True + _needs_sysroot = True + _supported_architectures = ( + CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, + ) + _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 + target = "cheri-portable-os-tests" + build_in_source_dir = False + make_kind = MakeCommandKind.BsdMake + repository = GitRepository("https://github.com/CTSRD-CHERI/portable-cheribsd-test-suite.git") + + @classproperty + def default_install_dir(self): + return DefaultInstallDir.ROOTFS_LOCALBASE + + @classmethod + def dependencies(cls, config) -> "tuple[str, ...]": + ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls) + return ti.musl_target, "libxo", "libbsd" + + def setup(self) -> None: + # Don't depend on libgcc_s + self.COMMON_LDFLAGS.append("--unwindlib=none") + + if self.get_crosscompile_target().is_aarch64(include_purecap=True): + self.set_env_make_args(machine_cpuarch="aarch64c", machine_abi="purecap", machine_arch="aarch64c") + elif self.get_crosscompile_target().is_experimental_cheri093_std(self.config): + self.set_env_make_args( + machine_cpuarch="rv64imafdc_zcherihybrid_zcherilevels", + machine_abi="purecap", + machine_arch="rv64imafdc_zcherihybrid_zcherilevels", + ) + else: + target = self.target_info.target + raise NotImplementedError(f"Unsupported architecture: {target.cpu_architecture} {target._cheri_isa}") + + return super().setup() + + def compile(self, **kwargs): + # The binaries will be put into /opt/cheri-api-tests + # This ensures Pyrefly that destdir won't be None + assert self.destdir is not None + self.destdir = self.destdir / "rootfs" / "opt" / "cheri-portable-os-tests" + self.makedirs(self.destdir) + + self.make_args.set_env( + # Put the binary into root's home directory + DESTDIR=str(self.destdir), + BINOWN=os.getuid(), + BINGRP=os.getgid(), + BINMODE=755, + # Suppress a warning related to absent exception handlers. + LD_FATAL_WARNINGS="no", + # This is not supported by Morello LLVM, + MAKESYSPATH=str(self.source_dir / "mk"), + MAKEOBJDIRPREFIX=str(self.build_dir), + **self.env_make_args, + ) + + self.run_make(cwd=self.source_dir / "cheribsdtest") + + def set_env_make_args(self, machine_cpuarch: str, machine_abi: str, machine_arch: str): + self.env_make_args = { + "MACHINE_CPUARCH": machine_cpuarch, + "MACHINE_ABI": machine_abi, + "MACHINE_ARCH": machine_arch, + } + + def install(self, **kwargs): + self.run_make_install(cwd=self.source_dir / "cheribsdtest") + + def process(self): + self.check_required_system_tool("bmake", homebrew="bmake", cheribuild_target="bmake") + super().process() From 43eb7d4ef9d9b4c4414c6bbc4d36ce505346168a Mon Sep 17 00:00:00 2001 From: Paul Metzger Date: Mon, 2 Feb 2026 16:58:30 +0000 Subject: [PATCH 5/9] Set OBJCOPY for the portable CheriBSD test suite The installation of libcheribsdtest_dynamic failed when cross-compiling on Ubuntu because the local objcopy was used instead of CHERI LLVM's objcopy. This commit fixes this by setting the OBJCOPY environment variable. The property objcopy was add to _ClangBasedTargetInfo to support this. --- pycheribuild/config/compilation_targets.py | 4 ++++ pycheribuild/projects/cross/cheriportableostests.py | 2 ++ pycheribuild/projects/simple_project.py | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/pycheribuild/config/compilation_targets.py b/pycheribuild/config/compilation_targets.py index c27a889d9..6eb7bfd9e 100644 --- a/pycheribuild/config/compilation_targets.py +++ b/pycheribuild/config/compilation_targets.py @@ -190,6 +190,10 @@ def c_preprocessor(self) -> Path: def linker(self) -> Path: return self._compiler_dir / "ld.lld" + @property + def objcopy(self) -> Path: + return self._compiler_dir / "objcopy" + @property def ar(self) -> Path: return self._compiler_dir / "llvm-ar" diff --git a/pycheribuild/projects/cross/cheriportableostests.py b/pycheribuild/projects/cross/cheriportableostests.py index 2ba129ccc..5dced3e20 100644 --- a/pycheribuild/projects/cross/cheriportableostests.py +++ b/pycheribuild/projects/cross/cheriportableostests.py @@ -90,6 +90,8 @@ def compile(self, **kwargs): # This is not supported by Morello LLVM, MAKESYSPATH=str(self.source_dir / "mk"), MAKEOBJDIRPREFIX=str(self.build_dir), + # This property was added to _ClangBasedTargetInfo to support this specific use case. + OBJCOPY=self.target_info.objcopy, **self.env_make_args, ) diff --git a/pycheribuild/projects/simple_project.py b/pycheribuild/projects/simple_project.py index 4d4f8ac74..a27a51cbf 100644 --- a/pycheribuild/projects/simple_project.py +++ b/pycheribuild/projects/simple_project.py @@ -685,6 +685,11 @@ def CXX(self) -> Path: # noqa: N802 def CPP(self) -> Path: # noqa: N802 return self.target_info.c_preprocessor + # noinspection PyPep8Naming + @property + def OBJCOPY(self) -> Path: # noqa: N802 + return self.target_info.objcopy + # noinspection PyPep8Naming @property def host_CC(self) -> Path: # noqa: N802 From e2ab89e56defb8259ef0ef29752c5fe4257e4c05 Mon Sep 17 00:00:00 2001 From: Paul Metzger Date: Thu, 23 Apr 2026 10:18:59 +0100 Subject: [PATCH 6/9] Fixed naming conflict between Linux targets The targets for Morello Linux and CHERI Linux on Morello both used the 'morello-purecap' suffix. This commit fixes this by chaning the suffix for Morello Linux targets to 'legacy-morello-purecap', as suggested by Alexander Richardson. This commit also includes a similar fix for non-purecap Morello targets. --- pycheribuild/config/compilation_targets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pycheribuild/config/compilation_targets.py b/pycheribuild/config/compilation_targets.py index 6eb7bfd9e..7cacf9afe 100644 --- a/pycheribuild/config/compilation_targets.py +++ b/pycheribuild/config/compilation_targets.py @@ -1650,10 +1650,10 @@ class CompilationTargets(BasicCompilationTargets): _cheri_isa=RiscvCheriISA.EXPERIMENTAL_STD093, ) UPSTREAM_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, UpstreamLinuxTargetInfo) - CHERI_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, CheriLinuxTargetInfo) + CHERI_LINUX_AARCH64 = CrossCompileTarget("wip-aarch64", CPUArchitecture.AARCH64, CheriLinuxTargetInfo) MORELLO_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, MorelloLinuxTargetInfo) CHERI_LINUX_MORELLO_PURECAP = CrossCompileTarget( - "morello-purecap", + "wip-morello-purecap", CPUArchitecture.AARCH64, CheriLinuxWithMorelloCompilerTargetInfo, is_cheri_purecap=True, From 6ba5dc14373f66a957642038c9224b0d4550a028 Mon Sep 17 00:00:00 2001 From: Paul Metzger Date: Tue, 28 Apr 2026 16:30:26 +0100 Subject: [PATCH 7/9] Removed the libbsd patch We are now using a patched fork of libbsd with a view to merging the patch upstream. --- pycheribuild/projects/cross/libbsd.py | 33 +++++---------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/pycheribuild/projects/cross/libbsd.py b/pycheribuild/projects/cross/libbsd.py index d1e8a4752..393103faa 100644 --- a/pycheribuild/projects/cross/libbsd.py +++ b/pycheribuild/projects/cross/libbsd.py @@ -40,10 +40,12 @@ class BuildLibbsd(CrossCompileAutotoolsProject): ) _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 make_kind = MakeCommandKind.GnuMake - # `default_branch` is set because the build scripts assume that - # a git tag is checked out. In more detail ./get-version returns an - # empty string if main is checked out. - repository = GitRepository("https://gitlab.freedesktop.org/libbsd/libbsd.git", default_branch="0.12.2") + repository = GitRepository( + "https://gitlab.freedesktop.org/libbsd/libbsd.git", + temporary_url_override="https://gitlab.freedesktop.org/paul-metzger/libbsd-private-fork-pmetzger.git", + default_branch="0_12_2_with_alignment_macro_fix", + force_branch=True, + ) @classproperty def default_install_dir(self): @@ -54,28 +56,6 @@ def dependencies(cls, config) -> "tuple[str, ...]": ti = typing.cast(typing.Type[LinuxTargetInfoBase], cls.get_crosscompile_target().target_info_cls) return ti.musl_target, "libmd" - def _apply_patch(self) -> None: - patch = """ -diff --git a/src/merge.c b/src/merge.c -index 3f1b3fb..f8cb602 100644 ---- a/src/merge.c -+++ b/src/merge.c -@@ -84,8 +84,8 @@ static void insertionsort(unsigned char *, size_t, size_t, - */ - /* Assumption: PSIZE is a power of 2. */ - #define EVAL(p) (unsigned char **) \\ -- (((unsigned char *)p + PSIZE - 1 - \\ -- (unsigned char *)0) & ~(PSIZE - 1)) -+ __builtin_cheri_address_set(p, ((__builtin_cheri_address_get(p) + PSIZE - 1 - \\ -+ 0) & ~(PSIZE - 1))) - - /* - * Arguments are as for qsort. -""" - self.write_file(self.source_dir / "merge.patch", patch, overwrite=True) - self.run_cmd("git", "restore", ".", cwd=self.source_dir) - self.run_cmd("git", "apply", "merge.patch", cwd=self.source_dir) - def setup(self) -> None: super().setup() # Remove dependency on libgcc_eh @@ -89,7 +69,6 @@ def configure(self, **kwargs): super().configure(**kwargs) def compile(self, **kwargs): - self._apply_patch() self.run_make() super().compile() From 89a24540f70cd610cb5f606fe503b3ad91a68a52 Mon Sep 17 00:00:00 2001 From: Hesham Almatary Date: Wed, 3 Jun 2026 11:19:30 +0100 Subject: [PATCH 8/9] Favour CHERI-Linux over Morello Linux --- pycheribuild/config/compilation_targets.py | 12 ++++++++---- pycheribuild/projects/cross/cheriportableostests.py | 1 + pycheribuild/projects/cross/libbsd.py | 1 + pycheribuild/projects/cross/libmd.py | 1 + pycheribuild/projects/cross/libxo.py | 1 + 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pycheribuild/config/compilation_targets.py b/pycheribuild/config/compilation_targets.py index 7cacf9afe..a6d7e8093 100644 --- a/pycheribuild/config/compilation_targets.py +++ b/pycheribuild/config/compilation_targets.py @@ -1650,18 +1650,22 @@ class CompilationTargets(BasicCompilationTargets): _cheri_isa=RiscvCheriISA.EXPERIMENTAL_STD093, ) UPSTREAM_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, UpstreamLinuxTargetInfo) - CHERI_LINUX_AARCH64 = CrossCompileTarget("wip-aarch64", CPUArchitecture.AARCH64, CheriLinuxTargetInfo) - MORELLO_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, MorelloLinuxTargetInfo) + CHERI_LINUX_AARCH64 = CrossCompileTarget("aarch64", CPUArchitecture.AARCH64, CheriLinuxTargetInfo) + MORELLO_LINUX_AARCH64 = CrossCompileTarget("legacy-aarch64", CPUArchitecture.AARCH64, MorelloLinuxTargetInfo) CHERI_LINUX_MORELLO_PURECAP = CrossCompileTarget( - "wip-morello-purecap", + "morello-purecap", CPUArchitecture.AARCH64, CheriLinuxWithMorelloCompilerTargetInfo, is_cheri_purecap=True, check_conflict_with=CHERI_LINUX_AARCH64, non_cheri_target=CHERI_LINUX_AARCH64, ) + # This target is kept for historical reasons as Morello Linux (from Arm) was the first Linux kernel + # and target that added CHERI support. CHERI-Linux (from CHERI Alliance) has built on top of Morello + # Linux to include more features, targets (RISC-V), and is the currently active project and should + # be used instead of the following target unless there is a good reason not to. MORELLO_LINUX_MORELLO_PURECAP = CrossCompileTarget( - "morello-purecap", + "legacy-morello-purecap", CPUArchitecture.AARCH64, MorelloLinuxTargetInfo, is_cheri_purecap=True, diff --git a/pycheribuild/projects/cross/cheriportableostests.py b/pycheribuild/projects/cross/cheriportableostests.py index 5dced3e20..f02b9374f 100644 --- a/pycheribuild/projects/cross/cheriportableostests.py +++ b/pycheribuild/projects/cross/cheriportableostests.py @@ -37,6 +37,7 @@ class BuildPortableOSTests(CrossCompileMakefileProject): _needs_sysroot = True _supported_architectures = ( CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.CHERI_LINUX_MORELLO_PURECAP, CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, ) _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 diff --git a/pycheribuild/projects/cross/libbsd.py b/pycheribuild/projects/cross/libbsd.py index 393103faa..be2b502fa 100644 --- a/pycheribuild/projects/cross/libbsd.py +++ b/pycheribuild/projects/cross/libbsd.py @@ -36,6 +36,7 @@ class BuildLibbsd(CrossCompileAutotoolsProject): _can_use_autogen_sh = True _supported_architectures = ( CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.CHERI_LINUX_MORELLO_PURECAP, CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, ) _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 diff --git a/pycheribuild/projects/cross/libmd.py b/pycheribuild/projects/cross/libmd.py index 773a40cb4..f25f9db13 100644 --- a/pycheribuild/projects/cross/libmd.py +++ b/pycheribuild/projects/cross/libmd.py @@ -36,6 +36,7 @@ class BuildLibmd(CrossCompileAutotoolsProject): _can_use_autogen_sh = True _supported_architectures = ( CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.CHERI_LINUX_MORELLO_PURECAP, CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, ) _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 diff --git a/pycheribuild/projects/cross/libxo.py b/pycheribuild/projects/cross/libxo.py index bcfe96c9d..bd5bca5b9 100644 --- a/pycheribuild/projects/cross/libxo.py +++ b/pycheribuild/projects/cross/libxo.py @@ -36,6 +36,7 @@ class BuildLibxo(CrossCompileAutotoolsProject): _can_use_autogen_sh = True _supported_architectures = ( CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093, + CompilationTargets.CHERI_LINUX_MORELLO_PURECAP, CompilationTargets.MORELLO_LINUX_MORELLO_PURECAP, ) _default_architecture = CompilationTargets.CHERI_LINUX_RISCV64_PURECAP_093 From bbca37f076b9dc658b1a6958c37eaa2ff02a77c8 Mon Sep 17 00:00:00 2001 From: Hesham Almatary Date: Wed, 3 Jun 2026 11:22:44 +0100 Subject: [PATCH 9/9] CHERI-Linux: point the kernel to Cambridge branch This cambridge-morello-7.0 branch has fixes for the Morello support and should be used until all of those fixes are merged. --- pycheribuild/projects/cross/linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycheribuild/projects/cross/linux.py b/pycheribuild/projects/cross/linux.py index be8f22c1f..e233a7780 100644 --- a/pycheribuild/projects/cross/linux.py +++ b/pycheribuild/projects/cross/linux.py @@ -154,7 +154,7 @@ def install(self, **kwargs): class BuildCheriAllianceLinux(BuildLinux): target = "linux-kernel" - repository = GitRepository("https://github.com/CHERI-Alliance/linux.git", default_branch="codasip-cheri-riscv-6.18") + repository = GitRepository("https://github.com/CHERI-Alliance/linux.git", default_branch="cambridge-morello-7.0") _supported_architectures = ( *CompilationTargets.ALL_CHERI_LINUX_TARGETS, CompilationTargets.LINUX_KERNEL_RISCV64_GCC,