freebsd: fix cross build for aarch64-freebsd (#541914)

This commit is contained in:
Artemis Tosini
2026-07-15 13:06:52 +00:00
committed by GitHub
10 changed files with 67 additions and 47 deletions

View File

@@ -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" && \

View File

@@ -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*} != "")

View File

@@ -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 <bsd.prog.mk>
${PROG_FULL}: ${VERSION_MAP}

View File

@@ -1,4 +1,6 @@
{
lib,
stdenv,
mkDerivation,
include,
rpcgen,
@@ -9,6 +11,7 @@
i18n,
libsys,
llvmPackages,
libcompiler_rt,
extraSrc ? [ ],
}:
@@ -39,6 +42,9 @@ mkDerivation {
"include/paths.h"
"include/gssapi"
]
++ lib.optionals (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [
"contrib/arm-optimized-routines"
]
++ extraSrc;
outputs = [
@@ -52,6 +58,7 @@ mkDerivation {
buildInputs = [
include
libsys
libcompiler_rt
];
extraNativeBuildInputs = [

View File

@@ -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;
}

View File

@@ -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 = ''

View File

@@ -1,6 +1,7 @@
{
mkDerivation,
include,
libcompiler_rt,
csu,
}:
@@ -25,6 +26,7 @@ mkDerivation {
buildInputs = [
include
csu
libcompiler_rt
];
preBuild = ''

View File

@@ -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 = [

View File

@@ -1,4 +1,6 @@
{
lib,
stdenv,
mkDerivation,
fetchpatch,
include,
@@ -7,6 +9,7 @@
flex,
byacc,
csu,
libcompiler_rt,
extraSrc ? [ ],
}:
@@ -32,6 +35,9 @@ mkDerivation {
"sys/crypto"
"include/gssapi"
]
++ lib.optionals (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [
"contrib/arm-optimized-routines"
]
++ extraSrc;
patches = [
@@ -55,6 +61,7 @@ mkDerivation {
buildInputs = [
include
libsys
libcompiler_rt
];
extraNativeBuildInputs = [

View File

@@ -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