From a1a36bfe71225fdc12b6a8d31cae2addcf873571 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Tue, 14 Jul 2026 12:03:08 -0400 Subject: [PATCH 1/3] freebsd.libcompiler_rt: init --- .../bsd/freebsd/pkgs/libcompiler_rt.nix | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 pkgs/os-specific/bsd/freebsd/pkgs/libcompiler_rt.nix diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libcompiler_rt.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libcompiler_rt.nix new file mode 100644 index 000000000000..1d6f44e3fd19 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libcompiler_rt.nix @@ -0,0 +1,31 @@ +{ + stdenv, + lib, + mkDerivation, + include, +}: + +mkDerivation { + path = "lib/libcompiler_rt"; + extraPaths = [ + "contrib/llvm-project/compiler-rt" + ]; + + buildInputs = [ + include + ]; + + # The build system is importing source files from another directory, + # then trying to put the objects in lib/libcompiler_rt + # It does not create subdirectories in the lib/libcompiler_rt directory. + preBuild = '' + mkdir cpu_model + '' + + lib.optionalString stdenv.hostPlatform.isx86_64 '' + mkdir i386 + ''; + + noLibc = true; + + alwaysKeepStatic = true; +} From 9ab1989aba6b1b1a108e6fa3c342a29aad3f3a14 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Tue, 14 Jul 2026 14:41:39 -0400 Subject: [PATCH 2/3] freebsd: Build packages with compiler-rt --- .../patches/15.0/bmake-no-compiler-rt.patch | 11 ---------- .../15.0/libc-no-force--lcompiler-rt.patch | 21 ------------------- .../15.0/rtld-no-force--lcompiler-rt.patch | 10 --------- .../bsd/freebsd/pkgs/libcMinimal.nix | 2 ++ pkgs/os-specific/bsd/freebsd/pkgs/libsys.nix | 2 ++ .../os-specific/bsd/freebsd/pkgs/rtld-elf.nix | 2 ++ 6 files changed, 6 insertions(+), 42 deletions(-) delete mode 100644 pkgs/os-specific/bsd/freebsd/patches/15.0/bmake-no-compiler-rt.patch delete mode 100644 pkgs/os-specific/bsd/freebsd/patches/15.0/libc-no-force--lcompiler-rt.patch delete mode 100644 pkgs/os-specific/bsd/freebsd/patches/15.0/rtld-no-force--lcompiler-rt.patch diff --git a/pkgs/os-specific/bsd/freebsd/patches/15.0/bmake-no-compiler-rt.patch b/pkgs/os-specific/bsd/freebsd/patches/15.0/bmake-no-compiler-rt.patch deleted file mode 100644 index 20be3503fd17..000000000000 --- a/pkgs/os-specific/bsd/freebsd/patches/15.0/bmake-no-compiler-rt.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/share/mk/src.libnames.mk 2023-12-21 23:56:50.767042385 -0800 -+++ b/share/mk/src.libnames.mk 2023-12-21 23:56:39.671089506 -0800 -@@ -392,7 +392,7 @@ - _DP_ztest= geom m nvpair umem zpool pthread avl zfs_core spl zutil zfs uutil icp - # The libc dependencies are not strictly needed but are defined to make the - # assert happy. --_DP_c= compiler_rt sys -+_DP_c= sys - # Use libssp_nonshared only on i386 and power*. Other archs emit direct calls - # to __stack_chk_fail, not __stack_chk_fail_local provided by libssp_nonshared. - .if ${MK_SSP} != "no" && \ diff --git a/pkgs/os-specific/bsd/freebsd/patches/15.0/libc-no-force--lcompiler-rt.patch b/pkgs/os-specific/bsd/freebsd/patches/15.0/libc-no-force--lcompiler-rt.patch deleted file mode 100644 index 3cc8fee77355..000000000000 --- a/pkgs/os-specific/bsd/freebsd/patches/15.0/libc-no-force--lcompiler-rt.patch +++ /dev/null @@ -1,21 +0,0 @@ ---- a/lib/libc/Makefile -+++ b/lib/libc/Makefile -@@ -58,7 +58,6 @@ CFLAGS+=${CANCELPOINTS_CFLAGS} - # Link with static libcompiler_rt.a. - # - LDFLAGS+= -nodefaultlibs --LIBADD+= compiler_rt - LIBADD+= sys - - .if ${MK_SSP} != "no" && \ ---- a/lib/libsys/Makefile -+++ b/lib/libsys/Makefile -@@ -46,7 +46,6 @@ - # - LDFLAGS+= -nodefaultlibs - LDFLAGS+= -Wl,-Bsymbolic --LIBADD+= compiler_rt - - .if ${MK_SSP} != "no" && \ - (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "") - diff --git a/pkgs/os-specific/bsd/freebsd/patches/15.0/rtld-no-force--lcompiler-rt.patch b/pkgs/os-specific/bsd/freebsd/patches/15.0/rtld-no-force--lcompiler-rt.patch deleted file mode 100644 index 45f0d0c51eec..000000000000 --- a/pkgs/os-specific/bsd/freebsd/patches/15.0/rtld-no-force--lcompiler-rt.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- a/libexec/rtld-elf/Makefile -+++ b/libexec/rtld-elf/Makefile -@@ -86,7 +86,6 @@ - - # Some of the required math functions (div & mod) are implemented in - # libcompiler_rt on some architectures. --LIBADD+= compiler_rt - - .include - ${PROG_FULL}: ${VERSION_MAP} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix index 6ad205b215ab..515fcc7d82fc 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix @@ -9,6 +9,7 @@ i18n, libsys, llvmPackages, + libcompiler_rt, extraSrc ? [ ], }: @@ -52,6 +53,7 @@ mkDerivation { buildInputs = [ include libsys + libcompiler_rt ]; extraNativeBuildInputs = [ diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libsys.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libsys.nix index 67611f7e0ce1..a4360a99021c 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libsys.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libsys.nix @@ -1,6 +1,7 @@ { mkDerivation, include, + libcompiler_rt, csu, }: @@ -25,6 +26,7 @@ mkDerivation { buildInputs = [ include csu + libcompiler_rt ]; preBuild = '' diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix b/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix index eef5e067da29..db41b450a168 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix @@ -7,6 +7,7 @@ flex, byacc, csu, + libcompiler_rt, extraSrc ? [ ], }: @@ -55,6 +56,7 @@ mkDerivation { buildInputs = [ include libsys + libcompiler_rt ]; extraNativeBuildInputs = [ From 25a581579fd75f10e6465b14663a2440ebb9ec12 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Tue, 14 Jul 2026 10:40:32 -0400 Subject: [PATCH 3/3] freebsd: fix compile for aarch64-freebsd --- pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix | 5 +++++ pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix | 6 ++++++ pkgs/os-specific/bsd/freebsd/pkgs/msun.nix | 5 +++++ pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix | 5 +++++ pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix | 14 +++++++++----- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix index 515fcc7d82fc..01473102e061 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix @@ -1,4 +1,6 @@ { + lib, + stdenv, mkDerivation, include, rpcgen, @@ -40,6 +42,9 @@ mkDerivation { "include/paths.h" "include/gssapi" ] + ++ lib.optionals (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [ + "contrib/arm-optimized-routines" + ] ++ extraSrc; outputs = [ diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix index 6bcc4639d15f..22e2f32bf868 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix @@ -1,4 +1,6 @@ { + lib, + stdenv, mkDerivation, include, libcMinimal, @@ -30,6 +32,10 @@ mkDerivation { preBuild = '' export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + '' + # Undefined symbols in the version script related to arm-optimized-routines + + lib.optionalString (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) '' + export NIX_LDFLAGS="$NIX_LDFLAGS --undefined-version" ''; postBuild = '' diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/msun.nix b/pkgs/os-specific/bsd/freebsd/pkgs/msun.nix index 87e081c6c445..3f9f0414f581 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/msun.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/msun.nix @@ -1,4 +1,6 @@ { + lib, + stdenv, mkDerivation, include, libcMinimal, @@ -10,6 +12,9 @@ mkDerivation { path = "lib/msun"; extraPaths = [ "lib/libc" # wants arch headers + ] + ++ lib.optionals (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [ + "contrib/arm-optimized-routines" ]; outputs = [ diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix b/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix index db41b450a168..5fcb65fcb811 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix @@ -1,4 +1,6 @@ { + lib, + stdenv, mkDerivation, fetchpatch, include, @@ -33,6 +35,9 @@ mkDerivation { "sys/crypto" "include/gssapi" ] + ++ lib.optionals (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [ + "contrib/arm-optimized-routines" + ] ++ extraSrc; patches = [ diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix index e2a765552add..fa7bba6025e2 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix @@ -26,6 +26,7 @@ kldxref, ctfconvert, ctfmerge, + dtc, }: let baseConfigFile = @@ -35,7 +36,7 @@ let extraConfig else writeText "extraConfig" extraConfig; - hostArchBsd = freebsd-lib.mkBsdArch stdenv; + hostMachineBsd = freebsd-lib.mkBsdMachine stdenv; filteredSource = filterSource { pname = "sys"; path = "sys"; @@ -57,7 +58,7 @@ let done '' + lib.optionalString (baseConfigFile != null) '' - cat ${baseConfigFile} >>sys/${hostArchBsd}/conf/${baseConfig} + cat ${baseConfigFile} >>sys/${hostMachineBsd}/conf/${baseConfig} ''; }; @@ -93,7 +94,9 @@ mkDerivation rec { kldxref ctfconvert ctfmerge - ]; + ] + # Device trees are built in the same sys package + ++ lib.optional (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) dtc; # --dynamic-linker /red/herring is used when building the kernel. NIX_ENFORCE_PURITY = 0; @@ -125,7 +128,8 @@ mkDerivation rec { KODIR = "${placeholder "out"}/kernel"; KMODDIR = "${placeholder "out"}/kernel"; - DTBDIR = "${placeholder "out"}/dbt"; + DTBDIR = "${placeholder "out"}/dtb"; + DTBODIR = "${placeholder "out"}/dtb/overlays"; KERN_DEBUGDIR = "${placeholder "debug"}/lib/debug"; KERN_DEBUGDIR_KODIR = "${KERN_DEBUGDIR}/kernel"; @@ -136,7 +140,7 @@ mkDerivation rec { configurePhase = '' runHook preConfigure - cd ${hostArchBsd}/conf + cd ${hostMachineBsd}/conf config ${baseConfig} runHook postConfigure