-
Notifications
You must be signed in to change notification settings - Fork 1.9k
linux: Fix out-of-src builds #17517
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
linux: Fix out-of-src builds #17517
Conversation
Oh, interesting. I wonder if that's related to this output change in the build recently. Up to and including 6.12:
6.13+:
Regardless, I'll have a look over this tonight. |
Seems to build in- and out-of-dir back to 4.19, but I didn't try very hard yet. I'm guessing it's at least in part related to torvalds/linux@b1992c3772e6, but I haven't had a chance to really think it through either. (Sorry that's not more helpful, but I'm out of brain today. I'll try to look more tomorrow). |
Thanks for the testing - sounds good as I think the earliest kernel we're committed to support is like 5.13 or 5.18 in the next major release. I tried unwinding the spaghetti in Linux's Kbuild code for much of the weekend myself and ran out of brain too, which is largely the reason I put this band-aid together after coming up empty on the root cause. Might be related to the I scanned through the other DKMS modules I've got on my system, and the closest one in similarity (with subdir targets under the module build dir) was the |
So, reflecting on this comment, I went back to
My bad, was looking at |
Not sure if it helps, but I noticed recently (#17541) that newer kernels involve an additional make step, changing to the build directory.
vs.
|
Yeah, this is what we were talking about above, too. Seems like the way targets are being defined changed, but after messing with the existing code a bunch I couldn't figure out why the targets are now not being built correctly automatically by the Kbuild recipes, using our existing code, after the change. |
4ea428f
to
f7a335b
Compare
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.
I played about with this a bit myself, but was only able to come up with worse ways to handle this. Unless someone has a better solution for this, I'm good with merging this fix until we figure something better out. @ckane thanks for digging in to this.
You're welcome - I've tried similar over the past week or so too and also haven't found a more elegant way to address what is going on, either. The root-level targets seem to be generated fine by Kbuild (and thus, most kernel modules build fine as they're typically a flat src tree), but the targets further down in submodules seem to not be traversed and generated by Kbuild anymore, even if we put their |
The linux kernel modules haven't been building successfully when the build occurs in a separate directory than the source code, which is a common build pattern in Linux. Was not able to determine the root cause, but the %.o targets in subdirectories are no longer being matched by the pattern targets in the Linux Kbuild system. This change fixes the issue by dynamically creating the missing ones inside our Kbuild. Signed-off-by: Coleman Kane <[email protected]>
f7a335b
to
ad41d15
Compare
Also just now rebased it against latest |
oops sorry @behlendorf looks like that removed the "Accepted" status tag |
The linux kernel modules haven't been building successfully when the build occurs in a separate directory than the source code, which is a common build pattern in Linux. Was not able to determine the root cause, but the %.o targets in subdirectories are no longer being matched by the pattern targets in the Linux Kbuild system. This change fixes the issue by dynamically creating the missing ones inside our Kbuild. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Coleman Kane <[email protected]> Closes openzfs#17517
so Kbuild file must be in the same dir which stores source code? Yes — in the Linux kernel build system, when building an external module, the Kbuild file (or more commonly, a Makefile containing obj-m := ...) must be placed in the source directory, not the build directory. When you build an external module using the kernel build system like this: make -C /lib/modules/$(uname -r)/build M=/path/to/module-src O=/path/to/module-build modules
The kernel build system expects to find obj-m := my_module.o in the source dir (i.e. where you point M=...), and it always looks for it there, never in the build directory. |
The linux kernel modules haven't been building successfully when the build occurs in a separate directory than the source code, which is a common build pattern in Linux. Was not able to determine the root cause, but the %.o targets in subdirectories are no longer being matched by the pattern targets in the Linux Kbuild system. This change fixes the issue by dynamically creating the missing ones inside our Kbuild. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Coleman Kane <[email protected]> Closes openzfs#17517
The linux kernel modules haven't been building successfully when the build occurs in a separate directory than the source code, which is a common build pattern in Linux. Was not able to determine the root cause, but the %.o targets in subdirectories are no longer being matched by the pattern targets in the Linux Kbuild system. This change fixes the issue by dynamically creating the missing ones inside our Kbuild. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Coleman Kane <[email protected]> Closes openzfs#17517
The linux kernel modules haven't been building successfully when the build occurs in a separate directory than the source code, which is a common build pattern in Linux. Was not able to determine the root cause, but the %.o targets in subdirectories are no longer being matched by the pattern targets in the Linux Kbuild system. This change fixes the issue by dynamically creating the missing ones inside our Kbuild. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Coleman Kane <[email protected]> Closes openzfs#17517
ZFS can't compile in a separate build directory on newer kernels, which I hit when building Linux 6.12. The problem is described in [1] and fixed in [2] but that fix is already present in 2.3.4 and the problem still persists in Yocto builds. I don't know what's wrong, it seems to be an issue deep in the guts of Kbuild, but building in-tree (${S} == ${B}) seems to work so just do that. [1] openzfs/zfs#17321 [2] openzfs/zfs#17517
The linux kernel modules haven't been building successfully when the build occurs in a separate directory than the source code, which is a common build pattern in Linux. Was not able to determine the root cause, but the %.o targets in subdirectories are no longer being matched by the pattern targets in the Linux Kbuild system. This change fixes the issue by dynamically creating the missing ones inside our Kbuild. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Coleman Kane <[email protected]> Closes openzfs#17517 (cherry picked from commit 7191c1d)
Motivation and Context
The problem is described in #17321 - due to some apparent change in Kbuild, our source tree stopped building when the build was done in a separate directory, e.g.:
The
make -C module/ modules
command would typically fail with messages about not finding any matching targets for the*.o
files, typically starting withos/linux/spl/spl-atomic.o
due to its place at the top of the lexical order.Description
Though I am uncertain what change in Kbuild caused this, I was able to determine that the pattern targets in the Linux Kbuild system are no longer matching the
%.o
targets in subdirectories. In response to this, I added some dynamically-generated targets to themodule/Kbuild
file to fill in the missing targets and allow the build to succeed. Seems to work for me at the moment, both in-source and out-of-source builds.I am not certain how well it works with earlier kernels (like 6.1.x branch, which probably doesn't have the Kbuild change).
If someone understands better what causes the breakage and can propose a cleaner fix here, I'm happy to implement it instead of mine. Otherwise, I'd recommend accepting this one (if it passes testing) until that mystery can be sorted out, so that things like the Arch AUR zfs-dkms-git package can work again, as well as anything else that builds like this.
How Has This Been Tested?
I have tested the module build on 6.15.x and 6.16-rc kernels.
I have tested the module build both out-of-source and in-source builds.
I have not tested kernels where the out-of-source build was still working, yet - maybe someone with one of these kernels already in place can give this a whirl and approve here.
Types of changes
Checklist:
Signed-off-by
.