From 2306b2f4e895556a42f8049d1388547cf347d752 Mon Sep 17 00:00:00 2001 From: Lucas Holt Date: Fri, 25 Sep 2026 14:28:08 -0400 Subject: [PATCH 1/2] Makefile.inc1: define __MidnightBSD__ for external cross compilers An external toolchain (upstream clang on Linux/macOS CI) is driven with -target *-unknown-freebsd13.4 and predefines __FreeBSD__ but not __MidnightBSD__. The tree keys on __MidnightBSD__ throughout the kernel (ACPICA's acenv.h, netmap, ipfilter, dtrace, sys/param.h, ...), so the cross build died in the first ACPICA header: contrib/dev/acpica/include/platform/acenv.h:365:2: error: Unknown target environment When bsd.compiler.mk reports the external compiler does not know __MidnightBSD_cc_version, add -D__MidnightBSD__= to XCFLAGS, using the same value our own clang derives from the triple's OS major version. AI-Assisted-by: Claude Fable 5.1 Co-Authored-By: Claude Fable 5.1 Signed-off-by: Lucas Holt --- Makefile.inc1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile.inc1 b/Makefile.inc1 index a7b61aa963..596af0c4c2 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -853,6 +853,14 @@ BFLAGS+= -B${WORLDTMP}/usr/bin (defined(X_COMPILER_TYPE) && ${X_COMPILER_TYPE} == clang) XCFLAGS+= -target ${TARGET_TRIPLE} .endif +# An external compiler (e.g. upstream clang on Linux/macOS) only knows the +# freebsd triple, so it predefines __FreeBSD__ but not __MidnightBSD__. The +# tree keys on __MidnightBSD__ everywhere, so supply it ourselves with the same +# value our own clang derives from the triple's OS major version. +.if defined(X_COMPILER_MIDNIGHTBSD_VERSION) && \ + ${X_COMPILER_MIDNIGHTBSD_VERSION} == "unknown" +XCFLAGS+= -D__MidnightBSD__=${TARGET_TRIPLE:C/.*freebsd([0-9]+).*/\1/} +.endif XCFLAGS+= --sysroot=${WORLDTMP} .if !empty(BFLAGS) From 3514aa9a5c278ab01e4269d848bc837963f368c3 Mon Sep 17 00:00:00 2001 From: Lucas Holt Date: Fri, 25 Sep 2026 14:46:18 -0400 Subject: [PATCH 2/2] libkern: add abs64() and drop the private copies in linuxkpi and drm2 cpufreq_dt.c calls abs64(), which this tree only defined privately in linuxkpi's and drm2's drm_os_freebsd.h. Every arm64 GENERIC build therefore fails: sys/dev/cpufreq/cpufreq_dt.c:116:10: error: call to undeclared function 'abs64' Provide abs64() in next to qabs(), as FreeBSD does, and remove the two duplicate static inlines so headers that include both do not hit a redefinition error. Verified: cpufreq_dt.o cross-compiles for aarch64; translation units including and build with amd64 kernel flags; sys/modules/linuxkpi linux_compat.o/linux_kmod.o build natively. AI-Assisted-by: Claude Fable 5.1 Co-Authored-By: Claude Fable 5.1 Signed-off-by: Lucas Holt --- sys/compat/linuxkpi/common/include/linux/kernel.h | 6 ------ sys/dev/drm2/drm_os_freebsd.h | 7 ------- sys/sys/libkern.h | 1 + 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index e60191414e..309b987e36 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -593,12 +593,6 @@ mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor) return ((q * multiplier) + ((r * multiplier) / divisor)); } -static inline int64_t -abs64(int64_t x) -{ - return (x < 0 ? -x : x); -} - typedef struct linux_ratelimit { struct timeval lasttime; int counter; diff --git a/sys/dev/drm2/drm_os_freebsd.h b/sys/dev/drm2/drm_os_freebsd.h index 7f5bb22aff..0ce0dede6d 100644 --- a/sys/dev/drm2/drm_os_freebsd.h +++ b/sys/dev/drm2/drm_os_freebsd.h @@ -304,13 +304,6 @@ ilog2(unsigned long x) return (flsl(x) - 1); } -static inline int64_t -abs64(int64_t x) -{ - - return (x < 0 ? -x : x); -} - int64_t timeval_to_ns(const struct timeval *tv); struct timeval ns_to_timeval(const int64_t nsec); diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h index 570caac448..def05a6466 100644 --- a/sys/sys/libkern.h +++ b/sys/sys/libkern.h @@ -114,6 +114,7 @@ static __inline off_t omin(off_t a, off_t b) { return (a < b ? a : b); } static __inline int abs(int a) { return (a < 0 ? -a : a); } static __inline long labs(long a) { return (a < 0 ? -a : a); } static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); } +static __inline int64_t abs64(int64_t a) { return (a < 0 ? -a : a); } #ifndef RANDOM_FENESTRASX #define ARC4_ENTR_NONE 0 /* Don't have entropy yet. */