Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 814194 - sys-fs/zfs-kmod: fails to build with clang-compiled kernel (*** Unable to build an empty module)
Summary: sys-fs/zfs-kmod: fails to build with clang-compiled kernel (*** Unable to bui...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Georgy Yakovlev
URL: https://github.com/openzfs/zfs/issues...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-21 17:16 UTC by Diratof Azdimarlow
Modified: 2022-04-07 07:25 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build log (sys-fs:zfs-kmod-2.1.1:20210920-125341.log,13.27 KB, text/plain)
2021-09-21 17:46 UTC, Diratof Azdimarlow
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Diratof Azdimarlow 2021-09-21 17:16:06 UTC
emerge --info '=sys-fs/zfs-kmod-2.1.1::gentoo' - https://termbin.com/0c9rl
emerge -pqv '=sys-fs/zfs-kmod-2.1.1::gentoo' - https://termbin.com/t7nl
ebuild environment - https://termbin.com/nkmcs
sys-fs/zfs-kmod build failed whith kernel, which compiled with clang.
with kernel, which compiled with gcc sys-fs/zfs-kmod builds and installs without any problem.
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-09-21 17:19:25 UTC
Please attach the logs instead for posterity, thanks (compress if it complains about being too large).
Comment 2 Nit Proc 2021-09-21 17:28:31 UTC
Does this problem appear on ubuntu 20.04 LTS?
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-09-21 17:31:04 UTC
(In reply to Sam James from comment #1)
> Please attach the logs instead for posterity, thanks (compress if it
> complains about being too large).

Please also include the missing build.log.

Probably related to https://github.com/gentoo/gentoo/pull/22339.
Comment 4 Gtick Fleth 2021-09-21 17:31:37 UTC
Just use gcc lol
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-09-21 17:33:33 UTC
(In reply to Gtick Fleth from comment #4)
> Just use gcc lol

This isn't a helpful comment, please keep things like this off our bug tracker. Thanks.
Comment 6 Diratof Azdimarlow 2021-09-21 17:46:54 UTC
Created attachment 740538 [details]
build log
Comment 7 Georgy Yakovlev archtester gentoo-dev 2021-10-07 05:59:36 UTC
I'll check correct way of doing it. the PR version completely broke compilation under some configurations and broke cross compilation.
Comment 8 Peter Levine 2022-01-31 07:20:58 UTC
Mine for good measure: https://github.com/openzfs/zfs/pull/13046

Tested working with sys-fs/zfs-kmod-9999 against sys-kernel/gentoo-sources-5.16.3. Haven't tested with cross-compiling, though.
Comment 9 Peter Levine 2022-02-11 04:52:31 UTC
The PR was accepted upstream with https://github.com/openzfs/zfs/commit/b66140c6ad481cb13e685465c6a732f7f2b9dc77.

There are now three environment variables that can be set to affect the module build.  LINUX_CC is passed as $(CC), LINUX_LD as $(LD), and LINUX_LLVM as $(LLVM).  A trivial example of how it can be used, at the end of pkg_setup():

> if tc-is-clang; then
> 	ewarn "Warning: building ${PN} with a clang is experimental."
> 	export KERNEL_CC="$(tc-getBUILD_CC)"
> 
> 	if tc-ld-is-lld; then
> 		export KERNEL_LD="$(tc-getBUILD_LD)"
> 
> 		KERNEL_LLVM=1
> 		for tool in AR NM STRIP OBJCOPY READELF; do
> 			[[ $(tc-getBUILD_${tool}) != *llvm-${tool,,} ]] && KERNEL_LLVM=0
> 		done
> 		export KERNEL_LLVM
> 	fi
> fi
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-03-11 12:28:27 UTC
(In reply to Peter Levine from comment #9)
> The PR was accepted upstream with
> https://github.com/openzfs/zfs/commit/
> b66140c6ad481cb13e685465c6a732f7f2b9dc77.
> 
> There are now three environment variables that can be set to affect the
> module build.  LINUX_CC is passed as $(CC), LINUX_LD as $(LD), and
> LINUX_LLVM as $(LLVM).  A trivial example of how it can be used, at the end
> of pkg_setup():
> 
> > if tc-is-clang; then
> > 	ewarn "Warning: building ${PN} with a clang is experimental."
> > 	export KERNEL_CC="$(tc-getBUILD_CC)"
> > 
> > 	if tc-ld-is-lld; then
> > 		export KERNEL_LD="$(tc-getBUILD_LD)"
> > 
> > 		KERNEL_LLVM=1
> > 		for tool in AR NM STRIP OBJCOPY READELF; do
> > 			[[ $(tc-getBUILD_${tool}) != *llvm-${tool,,} ]] && KERNEL_LLVM=0
> > 		done
> > 		export KERNEL_LLVM
> > 	fi
> > fi

Oh, I'd forgot this was included in 2.1.3. Let's chuck it in.
Comment 11 Larry the Git Cow gentoo-dev 2022-03-11 12:33:37 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7b55c828e5df46717ed9eaecd18598eaaacab856

commit 7b55c828e5df46717ed9eaecd18598eaaacab856
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-03-11 12:31:04 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-03-11 12:31:04 +0000

    sys-fs/zfs-kmod: add Clang logic
    
    The needed patch made its way upstream but we need
    a small amount of logic in the ebuild to accommodate
    it fully.
    
    Bug: https://github.com/openzfs/zfs/pull/13046
    Closes: https://bugs.gentoo.org/814194
    Thanks-to: Peter Levine <plevine457@gmail.com>
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-fs/zfs-kmod/zfs-kmod-2.1.3.ebuild | 18 ++++++++++++++++++
 sys-fs/zfs-kmod/zfs-kmod-9999.ebuild  | 18 ++++++++++++++++++
 2 files changed, 36 insertions(+)
Comment 12 Ionen Wolkens gentoo-dev 2022-03-11 15:16:29 UTC
Optimally feel linux-info/mod would need a *get_kernelCC / *set_kernel_toolchain or something like that (not that I've had interest in looking into this).

That aside, you can skip the clang logic if `linux_chkconfig_present CC_IS_CLANG` is false, meaning the kernel wasn't built with clang. There's also LD_IS_LLD and LTO_CLANG_THIN which may be useful (the latter is because a thinlto kernel cause sandbox violations with cache last I tried it, but been a while).

nvidia-drivers has some lazy logic which ignores tc-is-clang, not perfect but given it always failed on a clang-built kernel otherwise felt harmless to add.
Comment 13 Peter Levine 2022-03-12 09:46:37 UTC
(In reply to Ionen Wolkens from comment #12)
> That aside, you can skip the clang logic if `linux_chkconfig_present
> CC_IS_CLANG` is false, meaning the kernel wasn't built with clang.

How ideally should one handle a case in which `linux_chkconfig_present CC_IS_CLANG` returns true but $(tc-getBUILD_CC) is gcc?  die? Assume that "clang" corresponds to the executable that $(tc-getBUILD_CC) would have been at the time of the kernel build and pass that?  Parse 'linux_chkconfig_present CLANG_VERSION' for a major version number and pass "clang-$MAJ_VER"?
Comment 14 Peter Levine 2022-03-12 09:51:56 UTC
(In reply to Peter Levine from comment #13)
> How ideally should one handle a case in which `linux_chkconfig_present
> CC_IS_CLANG` returns true but $(tc-getBUILD_CC) is gcc?  die? Assume that
> "clang" corresponds to the executable that $(tc-getBUILD_CC) would have been
> at the time of the kernel build and pass that?  Parse
> 'linux_chkconfig_present CLANG_VERSION' for a major version number and pass
> "clang-$MAJ_VER"?

I meant parse $(linux_chkconfig_string CLANG_VERSION)