Skip to content

fix(kernel-headers): preserve build-time autoconf.h across postinst olddefconfig (#9425)#9426

Open
iav wants to merge 1 commit intoarmbian:mainfrom
iav:fix/linux-headers-autoconf-build-artifact
Open

fix(kernel-headers): preserve build-time autoconf.h across postinst olddefconfig (#9425)#9426
iav wants to merge 1 commit intoarmbian:mainfrom
iav:fix/linux-headers-autoconf-build-artifact

Conversation

@iav
Copy link
Contributor

@iav iav commented Feb 22, 2026

Summary

Fixes #9425.

The linux-headers postinst script runs make olddefconfig before natively
recompiling scripts/ on the target host (necessary for cross-built kernels).
However, olddefconfig re-evaluates toolchain availability on the installation
host
and silently disables CONFIG_* options whose tools are absent there —
even though the compiled kernel image was built with those options enabled.

This causes the installed headers package to describe a different kernel than
the one actually running.

Affected files:

  • include/generated/autoconf.h — used by the C preprocessor
  • include/config/auto.conf + include/config/ marker files — used by kbuild make rules in external modules
  • include/generated/rustc_cfg — used by Rust builds

Fix: at packaging time, save a sidecar tarball of the build-time
include/config/ and include/generated/{autoconf.h,rustc_cfg}; restore it
in postinst as the very last step, after all make targets complete.

Completed tests

  • Build linux-headers for BOARD=odroidn2 (aarch64, native build) with kernel-rust extension (CONFIG_RUST=y)
  • Build linux-headers for BOARD=odroidm1 (aarch64, cross-compiled on x86_64)
  • Build linux-headers for BOARD=uefi-x86 (amd64) — exercises the tools/objtool postinst block
  • Verify sidecar tarball present in .deb: include/generated/.armbian-build.tar.gz containing include/config/, autoconf.h, rustc_cfg
  • Install on target host without rustc in $PATH; postinst completes successfully
  • include/generated/autoconf.h: #define CONFIG_RUST 1, CONFIG_RUSTC_VERSION 108500 (not 0)
  • include/config/auto.conf: CONFIG_RUST=y
  • include/generated/rustc_cfg: --cfg=CONFIG_RUST

@iav iav requested a review from a team as a code owner February 22, 2026 23:25
@iav iav requested review from Tearran and dimitry-ishenko and removed request for a team February 22, 2026 23:25
@github-actions github-actions bot added the 02 Milestone: First quarter release label Feb 22, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

Preserves build-time kernel configuration during linux-headers packaging by creating an include/generated/.armbian-build.tar.gz sidecar (when include/config/auto.conf exists) and restoring its contents in the package's postinst finish to avoid target-side make olddefconfig altering the original config.

Changes

Cohort / File(s) Summary
Kernel headers packaging
lib/functions/compilation/kernel-debs.sh
Adds creation of include/generated/.armbian-build.tar.gz (captures include/config/, include/generated/autoconf.h, optional include/generated/rustc_cfg) during headers packaging when include/config/auto.conf exists; excludes the tarball from DEBUG binary checks; restores tarball contents in postinst finish and removes the tarball after restoration.

Sequence Diagram(s)

sequenceDiagram
    participant Packager
    participant Package
    participant TargetPostinst
    participant Filesystem

    Packager->>Filesystem: check for include/config/auto.conf
    alt auto.conf exists
        Packager->>Filesystem: create include/generated/.armbian-build.tar.gz (include/config + generated files)
        Packager->>Package: include tarball in linux-headers package
    end
    Note right of Package: Package shipped to target

    Package->>TargetPostinst: postinst runs on install
    TargetPostinst->>Filesystem: run make olddefconfig / prepare scripts/
    TargetPostinst->>Filesystem: if .armbian-build.tar.gz exists, extract to restore saved config
    TargetPostinst->>Filesystem: remove .armbian-build.tar.gz
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A tarball snug within the tree,
Saved configs hop back home with glee,
Postinst runs but leaves truth intact,
Host-made kernels stay exact —
Hooray for builds preserved! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: preserving build-time autoconf.h across postinst olddefconfig, directly addressing issue #9425.
Linked Issues check ✅ Passed The PR implementation fully addresses all coding requirements: preserves build-time config artifacts in a sidecar tarball, prevents make olddefconfig mutation, and restores artifacts during postinst.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing kernel-headers preservation of build-time configuration; no unrelated modifications detected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size/small PR with less then 50 lines Needs review Seeking for review Framework Framework components labels Feb 22, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
lib/functions/compilation/kernel-debs.sh (1)

495-502: Sidecar tarball will trigger a false positive in the DEBUG binary check

include/generated/.armbian-build.tar.gz is a gzip binary. The grep -v filter at line 500 excludes include/config/ but not include/generated/, so file will report it as an unexpected binary when DEBUG=yes.

♻️ Proposed fix — exclude the sidecar from the binary scan
- find . -type f | grep -v -e "include/config/" -e "\.h$" -e ".c$" -e "Makefile$" -e "Kconfig$" -e "Kbuild$" -e "\.cocci$" | xargs file | grep -v -e "ASCII" -e "script text" -e "empty" -e "Unicode text" -e "symbolic link" -e "CSV text" -e "SAS 7+" || true
+ find . -type f | grep -v -e "include/config/" -e "include/generated/\.armbian-build\.tar\.gz" -e "\.h$" -e ".c$" -e "Makefile$" -e "Kconfig$" -e "Kbuild$" -e "\.cocci$" | xargs file | grep -v -e "ASCII" -e "script text" -e "empty" -e "Unicode text" -e "symbolic link" -e "CSV text" -e "SAS 7+" || true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/functions/compilation/kernel-debs.sh` around lines 495 - 502, The DEBUG
binary-scan in kernel-debs.sh (inside the if [[ "${DEBUG}" == "yes" ]] block
that cd's into "${headers_target_dir}" and runs the find | grep -v ... | xargs
file pipeline) falsely flags include/generated/.armbian-build.tar.gz; update the
grep -v filter in that pipeline to also exclude the include/generated/ sidecar
(or the specific filename .armbian-build.tar.gz) so the file is ignored by the
binary check, keeping the rest of the exclusion rules intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/functions/compilation/kernel-debs.sh`:
- Around line 495-502: The DEBUG binary-scan in kernel-debs.sh (inside the if [[
"${DEBUG}" == "yes" ]] block that cd's into "${headers_target_dir}" and runs the
find | grep -v ... | xargs file pipeline) falsely flags
include/generated/.armbian-build.tar.gz; update the grep -v filter in that
pipeline to also exclude the include/generated/ sidecar (or the specific
filename .armbian-build.tar.gz) so the file is ignored by the binary check,
keeping the rest of the exclusion rules intact.

…lddefconfig (armbian#9425)

При упаковке linux-headers скомпилированные бинарники из scripts/ удаляются,
так как они собраны под хост сборки, а не под целевую машину (типичный случай
кросс-сборки). Поэтому postinst при установке пакета пересобирает их нативно,
предварительно запустив `make olddefconfig`.

Однако olddefconfig не только подготавливает окружение — он заново вычисляет
конфигурацию ядра, проверяя тулчейн, доступный на целевом хосте при установке.
Если инструменты, использовавшиеся при сборке ядра, на целевой машине отсутствуют
или имеют другую версию, olddefconfig молча отключает соответствующие CONFIG_*
опции (например, CONFIG_CC_IS_CLANG, CONFIG_LTO_CLANG, CONFIG_DEBUG_INFO_BTF).

В результате установленный пакет заголовков описывает не то ядро, которое
реально собрано и работает, а то, которое можно было бы собрать на данном хосте.

Это затрагивает:
- include/generated/autoconf.h (используется препроцессором C)
- include/config/auto.conf + маркер-файлы include/config/ (используются
  make-правилами kbuild)
- include/generated/rustc_cfg (используется Rust-сборками)

Все эти файлы — артефакты сборки и должны описывать скомпилированное ядро,
а не возможности хоста установки.

Исправление: при упаковке сохраняем сайдкар-тарбол с build-time версиями
include/config/ и include/generated/{autoconf.h,rustc_cfg}; восстанавливаем
его в postinst в самом конце, после всех make-шагов.

Fixes: armbian#9425

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@iav iav force-pushed the fix/linux-headers-autoconf-build-artifact branch from 59a3ab7 to 5c893ea Compare February 22, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

02 Milestone: First quarter release Framework Framework components Needs review Seeking for review size/small PR with less then 50 lines

Development

Successfully merging this pull request may close these issues.

[Bug]: linux-headers postinst regenerates autoconf.h with incomplete toolchain, misrepresenting installed kernel configuration

1 participant