-
Notifications
You must be signed in to change notification settings - Fork 20
Add reproducible builds support in OHCL-Linux-Kernel #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: product/hcl-main/6.12
Are you sure you want to change the base?
Add reproducible builds support in OHCL-Linux-Kernel #115
Conversation
Add kernel Makefile changes to support reproducible builds across machines. Changes: - Makefile: Add KBUILD_BUILD_ID variable (default: sha1) to allow overriding the build-id linker flag for vmlinux and modules - arch/x86/entry/vdso/Makefile: Use --build-id=none for x86 VDSO - arch/arm64/kernel/vdso/Makefile: Use --build-id=none for arm64 VDSO - arch/arm64/kernel/vdso32/Makefile: Use --build-id=none for arm64-32 VDSO The VDSO changes must remain in kernel Makefiles as VDSO_LDFLAGS are not overridable from the command line. Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
Add reproducible build system using NixOS flakes with pinned dependencies. New files: - flake.nix: Nix environment with pinned toolchain (GCC 13.2.0, binutils, etc.) - flake.lock: Locked package versions for reproducibility - Microsoft/nix-build.sh: Main build script with reproducible environment - Microsoft/nix-setup.sh: One-time Nix installation helper - Microsoft/nix-clean.sh: Build artifact cleanup Modified files: - Microsoft/build-hcl-kernel.sh: When REPRODUCIBLE_BUILD=1: - Pass KBUILD_BUILD_ID=none to disable Build IDs - Pass KCFLAGS=-fdebug-prefix-map to normalize debug paths - Skip --add-gnu-debuglink to avoid CRC embedding - .gitignore: Add Nix-related entries Environment variables set for reproducibility: - SOURCE_DATE_EPOCH=1609459200 (fixed timestamp) - KBUILD_BUILD_USER=builder - KBUILD_BUILD_HOST=nixos - REPRODUCIBLE_BUILD=1 (flag for build scripts) Usage: ./Microsoft/nix-setup.sh # One-time Nix installation ./Microsoft/nix-build.sh x64 # Build x64 kernel ./Microsoft/nix-build.sh arm64 # Build arm64 kernel Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
Add build-hcl-kernel-pipeline.sh that implements the full kernel build workflow for Azure DevOps pipelines with reproducible build support. Features: - Supports amd64 and arm64 architectures - CVM config merge support - Reproducible build mode with Nix environment - Generates kernel, headers, modules, and debug symbols - Progress indicators for build stages [1/5] through [5/5] - SHA256 checksum output for reproducibility verification Usage: ./build-hcl-kernel-pipeline.sh -s <source> -b <build> -c <config> -a <arch> ./build-hcl-kernel-pipeline.sh ... --reproducible # Enable Nix environment
Enhance nix-setup.sh to ensure Nix is available in PATH immediately after installation or when sourcing existing profiles. Changes: - Add source_nix_profile() helper function - Check multiple profile locations (~/.nix-profile, /nix/var/nix/profiles) - Clean up debug prints to informative messages - Better error handling when Nix is installed but not in PATH
Ensure only Nix-provided tools are used during reproducible builds, preventing system package leakage that could affect reproducibility. Changes: - Add --ignore-environment to nix develop for pure shell - Keep essential env vars: HOME, USER, TERM - Explicitly set CC=gcc to use Nix's GCC in all scenarios - Detect host architecture to avoid cross-compiler on native builds - Add LOCALVERSION= to prevent '+' suffix in version string - Add shell utilities to flake.nix (getopt, coreutils, rsync, etc.) - Print SHA256 checksum of vmlinux for verification This ensures cross-compiled and native builds use the correct compiler identification strings for reproducibility.
saurabh-sengar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we upstream Linux kernel changes in this PR ?
Is there no way reproducibitly builds are supported by Linux kernel today ?
Ref: https://docs.kernel.org/kbuild/reproducible-builds.html
| # For reproducible builds, use --build-id=none to avoid non-deterministic Build IDs. | ||
| ldflags-y := -shared -soname=linux-vdso.so.1 \ | ||
| -Bsymbolic --build-id=sha1 -n $(btildflags-y) | ||
| -Bsymbolic --build-id=none -n $(btildflags-y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we upstream this ?
OHCL-Linux-Kernel has Microsoft/build-hcl-kernel.sh script which is used to build kernel. However, in build pipelines, that script is not used and similar code in pipeline code itself is used.
To implement reproducible builds, add this support in both local build script (Microsoft/build-hcl-kernel.sh) and the pipeline code. Instead of adding the support in pipeline directly, move the kernel build code from pipeline to a new script "Microsoft/build-hcl-kernel-pipeline.sh" and ad reproducible builds changes in it. With that, buddy/official pipeline would then call this script to build kernel.