Skip to content

Fix remaining Cross-build Kernel CI failures - #524

Merged
laffer1 merged 2 commits into
masterfrom
fix-cross-build-midnightbsd-define
Sep 25, 2026
Merged

laffer1 merged 2 commits into
masterfrom
fix-cross-build-midnightbsd-define

Conversation

@laffer1

@laffer1 laffer1 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #523. With the ck header and CFLAGS fixes in, every Cross-build Kernel job got past genassym and died in the first ACPICA header. Three commits, each fixing the next failure CI exposed:

1. Makefile.inc1: define __MidnightBSD__ for external cross compilers. The cross build drives upstream clang-18 with a *-unknown-freebsd13.4 triple, which predefines __FreeBSD__ but not __MidnightBSD__. The whole kernel tree keys on __MidnightBSD__ (ACPICA acenv.h failed first with Unknown target environment), so patching headers one by one is the wrong fix. When bsd.compiler.mk reports the external compiler has no __MidnightBSD_cc_version, Makefile.inc1 now adds -D__MidnightBSD__=<N> to XCFLAGS next to -target, with N taken from the triple's OS major version exactly as our own clang derives it. Native builds are unaffected. This alone turned both amd64 jobs green.

2. libkern: add abs64(). Both arm64 jobs then failed on a genuine source bug: cpufreq_dt.c calls abs64(), which this tree only defined privately in linuxkpi and drm2. This breaks native arm64 GENERIC too. Added to <sys/libkern.h> next to qabs() as FreeBSD does; removed the two private copies to avoid redefinition errors.

3. arm64: drop the stale crypto/openssl/aarch64/arm_arch.h. Next arm64 failure, also a native bug: the OpenSSL aarch64 .S files #include "arm_arch.h", which resolves to a sibling copy from OpenSSL 1.1 (2018) that lacks AARCH64_VALID_CALL_TARGET, so the macro is assembled literally (unrecognized instruction mnemonic). Removed the stale copy so the maintained sys/crypto/openssl/arm_arch.h is found, added -I$S/crypto/openssl to the aarch64 OpenSSL rules in files.arm64 as FreeBSD does, and repointed ossl_aarch64.c at the surviving header. No assembly was modified.

Verified locally: bmake -f Makefile.inc1 -V XCFLAGS for simulated external and native compilers; cpufreq_dt.o and all OpenSSL/armv8crypto aarch64 objects cross-compile from a GENERIC+ossl config (each fails identically before its fix); translation units including <linux/kernel.h> and <dev/drm2/drmP.h> build with amd64 kernel flags; sys/modules/linuxkpi objects build natively.

AI-Assisted-by: Claude Fable 5.1

🤖 Generated with Claude Code

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__=<N> 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 <noreply@anthropic.com>
Signed-off-by: Lucas Holt <luke@foolishgames.com>
@sourcery-ai

sourcery-ai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates cross-build compiler flags so external clang toolchains targeting FreeBSD-compatible triples define __MidnightBSD__ with the target OS major version, allowing ACPICA and other kernel components to select the correct platform while leaving native builds unchanged.

File-Level Changes

Change Details Files
Make external cross-compilers identify the kernel build as MidnightBSD by deriving and injecting the OS major version macro.
  • Detect external compilers that lack the native MidnightBSD compiler version macro.
  • Derive the OS major version from the target triple and add it as -D__MidnightBSD__=<N> alongside the cross-compilation target flag.
  • Preserve existing behavior for native MidnightBSD toolchains.
Makefile.inc1

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

cpufreq_dt.c calls abs64(), which this tree only defined privately in
linuxkpi's <linux/kernel.h> 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 <sys/libkern.h> 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 <linux/kernel.h> and <dev/drm2/drmP.h> 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 <noreply@anthropic.com>
Signed-off-by: Lucas Holt <luke@foolishgames.com>
@laffer1 laffer1 changed the title Makefile.inc1: define __MidnightBSD__ for external cross compilers Fix remaining Cross-build Kernel CI failures Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Claude finished @laffer1's task in 2m 28s —— View job


Claude finished the code review

  • Gather context (PR diff, files changed)
  • Review Makefile.inc1 changes
  • Review sys/sys/libkern.h, linuxkpi, drm2 changes
  • Check style(9) compliance
  • Post final review

Review

Two commits: the __MidnightBSD__ cross-compile fix, and a small abs64() consolidation into sys/sys/libkern.h. Both are Makefile/C changes; per AI_POLICY.md these were manually audited (no malloc/free involved, so bounds/symmetry checks are trivial here).

Makefile.inc1:856-863 — the core fix.

  • Verified X_COMPILER_MIDNIGHTBSD_VERSION is set to the literal string "unknown" by share/mk/bsd.compiler.mk:222-223 when the compiler doesn't answer __MidnightBSD_cc_version, so the .if guard matches the intended external-compiler case and native builds are untouched.
  • Verified the value derivation matches upstream clang's own logic: contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.h:187-194 sets __MidnightBSD__ from Triple.getOSMajorVersion(). TARGET_TRIPLE/MACHINE_TRIPLE both default to ...-freebsd13.4 (Makefile.inc1:146,148), so the :C/.*freebsd([0-9]+).*/\1/ regex reliably extracts 13 in the default case — matches.
  • Minor/low-confidence edge case: if a user manually overrides TARGET_TRIPLE to a value without a freebsdNN substring, the :C modifier leaves the string unmodified on no-match, producing an invalid -D__MidnightBSD__=<whole-triple> flag. Not a real concern given the hardcoded default and the PR's stated (amd64/aarch64) test scope — just noting it's not fully robust to arbitrary overrides.
  • Style/placement: tab after XCFLAGS+=, 4-space continuation indent — consistent with the surrounding block.

sys/sys/libkern.h:117 — abs64() added alongside the existing abs/labs/qabs one-liners; consistent style, correct implementation.

sys/compat/linuxkpi/common/include/linux/kernel.h and sys/dev/drm2/drm_os_freebsd.h — local abs64() copies removed. Verified both call sites still resolve the symbol:

  • linuxkpi's kernel.h already includes <sys/libkern.h> directly.
  • drm2/drm_os_freebsd.h doesn't include it directly, but dev/drm2/drmP.h → <sys/systm.h> → <sys/libkern.h> (systm.h:397), and drm_irq.c (the only other abs64 user in that subtree) includes drmP.h. No breakage.
  • Bonus: this also gives sys/dev/cpufreq/cpufreq_dt.c a working abs64() via the same sys/systm.h chain — it calls abs64() but had no prior definition in scope, so this consolidation incidentally fixes what looks like a pre-existing latent build issue there (untouched by this PR, out of scope to fix further here).

No correctness, malloc/free, bounds-checking, or style(9) issues found. No assembly or contrib/mksh changes in this diff. LGTM.

@laffer1
laffer1 merged commit 8a27bff into master Sep 25, 2026
8 of 11 checks passed
@laffer1
laffer1 deleted the fix-cross-build-midnightbsd-define branch September 25, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant