Skip to content

zfs: map kernel make flags to what zfs expects - #408433

Open
yshui wants to merge 1 commit into
NixOS:masterfrom
yshui:zfs-cc-fix
Open

yshui wants to merge 1 commit into
NixOS:masterfrom
yshui:zfs-cc-fix

Conversation

@yshui

@yshui yshui commented May 18, 2025

Copy link
Copy Markdown
Contributor

Fixes #408428

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@nix-owners
nix-owners Bot requested review from adamcstephens and amarshall May 18, 2025 15:47
@github-actions github-actions Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 101-500 This PR causes between 101 and 500 packages to rebuild on Linux. labels May 18, 2025
@adamcstephens

Copy link
Copy Markdown
Contributor

I'm not sure I quite understand the problem or its proposed solution, but you'll need to apply the formatter at a minimum.

@amarshall

Copy link
Copy Markdown
Member

Yea a reproduction build cmd that fails before and passes after would be helpful.

@yshui

yshui commented May 19, 2025 •

Copy link
Copy Markdown
Contributor Author

understand the problem

ok i will try to explain with more details. so the kernel derivation just pulls in the compiler from stdenv, which is a wrapped compiler. with gcc, it works. but in general, since wrapper insert all kinds of flags thing can go wrong. and it does go wrong if you try to build kernel with clang.

see: ClangBuiltLinux/linux#2041 ClangBuiltLinux/linux#1983

two main issues:

  • the wrapper adds -fwrapv, which is equivalent to clang's -fno-strict-overflow - added by the kernel makefile. since both are present, clang complains about the latter being unused, which fails because -Werror.
  • same as above for -nostdlibinc.
  • the wrapper adds -Wl,--dynamic-linker=..., which puts an INTERP program header into the ELF. kernel's tooling just can't handle this, and you get either crashes during build or an unbootable kernel.

and also other minor issues, like the wrapper constantly complaining:

Warning: supplying the --target ____ argument to a nix-wrapped compiler may not work correctly - cc-wrapper is currently not designed with multi-target compilers in mind. You may want to use an un-wrapped compiler instead.

so i did just that, use the unwrapped clang instead. since the unwrapped compiler cannot build normal programs - it cannot find standard headers or libraries, you need both wrapped and unwrapped clang to build the kernel. wrapped version for building tools that runs on the host during build, and unwrapped version for building the kernel. this is done by specifying CC=.. (unwrapped, for kernel) and HOSTCC=.. (wrapped, for tools) in makeFlags.

and the kernel builds perfectly fine with this, but downstream packages don't. because they would pick up the wrong compiler from kernelModuleMakeFlags. zfs is one of them, another example is nvidia-persistenced, which uses CC to build user space programs.

like the kernel, zfs has user space parts and kernel parts, and does accept different compiler for each. the problem is just the variable names are different. equivalent of HOSTCC (kernel) is just CC (zfs), and CC -> KERNEL_CC. so to make sure zfs is built with the exactly same compilers as the kernel, you need to translate kernelModuleMakeFlags for zfs.

@adamcstephens

Copy link
Copy Markdown
Contributor

Please provide reproduction steps.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 28, 2025
@zowoq

zowoq commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

#435553 mapped the kernel flags but not sure if it works for clang.

@Shawn8901

Shawn8901 commented Aug 26, 2025 •

Copy link
Copy Markdown
Contributor

IMHO wie should still consider merging this variant, as its a more clean approach into solving the actual issue as its doing an educated mapping instead of just copying everything as KERNEL_

@yshui

yshui commented Aug 27, 2025

Copy link
Copy Markdown
Contributor Author

@alyssais hi, this is apparently partially being implemented by your commit af5dd57. but there is also a HOSTCC -> CC mapping needed.

@alyssais

alyssais commented Aug 28, 2025 via email

Copy link
Copy Markdown
Member

@yshui

yshui commented Aug 28, 2025 •

Copy link
Copy Markdown
Contributor Author

@alyssais sorry but that's not what i meant. maybe i wasn't clear. just like you need to set KERNEL_CC for zfs to what CC was set to while the kernel was being built. you need to set CC for zfs to what HOSTCC was.

CC is used to build user space tools, whereas KERNEL_CC is used to build the kernel module.

@alyssais

Copy link
Copy Markdown
Member

you need to set CC for zfs to what HOSTCC was.

Won't that be configured correctly by AC_PROG_CC?

@yshui

yshui commented Aug 28, 2025

Copy link
Copy Markdown
Contributor Author

if you don't care if zfs tools are built with the same compiler as the kernel HOSTCC, sure. i don't see why not, since you are already setting KERNEL_*.

@nixpkgs-ci nixpkgs-ci Bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 25, 2026
@n0099

n0099 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

This should fix #473637

@nixpkgs-ci nixpkgs-ci Bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 101-500 This PR causes between 101 and 500 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvment request: zfs, translate kernel makeFlags to what zfs expects.

8 participants