You are not logged in.

#1 2020-09-02 12:06:48

Sourav
Member
From: India
Registered: 2019-04-22
Posts: 84
Website

Use Clang with DKMS

Since the release of Kernel 5.0, I have tried to compile it with Clang. It succeeded. But I always had problems with dkms installing modules. Currently I use V4l2loopback and virtualbox-host-dkms which fails on a kernel and kernel header compiled with Clang. Compile the kernel with GCC, it works fine.

I am running 5.8.5 Xanmod kernel compiled with Clang:

Linux version 5.8.5-xanmod1-1-xanmod (makepkg@archlinux) (clang version 10.0.1 , LLD 10.0.1) #1 SMP PREEMPT Wed, 02 Sep 2020 07:55:08 +0000

This happens when I am trying to build v4l2loopback with dkms on a clang compiled Xanmod 5.8.5 kernel:

$ CC=clang CXX=clang++ HOSTCC=clang sudo dkms install --no-depmod -m v4l2loopback -v 0.12.5 -k 5.8.5-xanmod1-1-xanmod

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
make -j4 KERNELRELEASE=5.8.5-xanmod1-1-xanmod KERNEL_DIR=/usr/lib/modules/5.8.5-xanmod1-1-xanmod/build all...(bad exit status: 2)
Error! Bad return status for module build on kernel: 5.8.5-xanmod1-1-xanmod (x86_64)
Consult /var/lib/dkms/v4l2loopback/0.12.5/build/make.log for more information.

I know dkms doesn't take CC and HOSTCC environment variables, but I still tried...

Anyway, here' the /var/lib/dkms/v4l2loopback/0.12.5/build/make.log:

$ cat /var/lib/dkms/v4l2loopback/0.12.5/build/make.log 
DKMS make.log for v4l2loopback-0.12.5 for kernel 5.8.5-xanmod1-1-xanmod (x86_64)
Wed  2 Sep 17:39:11 IST 2020
Building v4l2-loopback driver...
make -C /usr/lib/modules/5.8.5-xanmod1-1-xanmod/build M=/var/lib/dkms/v4l2loopback/0.12.5/build modules
make[1]: Entering directory '/usr/lib/modules/5.8.5-xanmod1-1-xanmod/build'
  CC [M]  /var/lib/dkms/v4l2loopback/0.12.5/build/v4l2loopback.o
gcc: error: unrecognized command-line option ‘-Qunused-arguments’
gcc: error: unrecognized command-line option ‘-mno-global-merge’
make[2]: *** [scripts/Makefile.build:281: /var/lib/dkms/v4l2loopback/0.12.5/build/v4l2loopback.o] Error 1
make[1]: *** [Makefile:1760: /var/lib/dkms/v4l2loopback/0.12.5/build] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.8.5-xanmod1-1-xanmod/build'
make: *** [Makefile:43: v4l2loopback.ko] Error 2

When I search google about "dkms build with clang" I get some results like this:
clang, dkms and ERROR: could not insert 'nvidia': Exec format error

All the suggestions I get are for debian based systems that has the update-alternatives command.

And they suggest this:

sudo update-alternatives --config cc
sudo update-alternatives --config c++
sudo dkms remove nvidia/390.48 -k 4.15.0-32-generic
sudo dkms build nvidia/390.48 -k 4.15.0-32-generic
sudo dkms install nvidia/390.48 
sudo modprobe nvidia

I am not sure if that works, I don't have Debian based systems.

There were some other places where I have read the similar way to get dkms modules built with clang.

But on Arch, there's no update-alternatives command in general. So what's the way to build dkms modules with clang?

EDIT:

I guess it's because v4l2loopback doesn't support compiling with clang!
Here I have cloned the v4l2loopback from github, and ran make with clang:

CC=clang HOSTCC=clang make
Building v4l2-loopback driver...
make -C /lib/modules/`uname -r`/build M=/ramdisk/v4l2loopback modules
make[1]: Entering directory '/usr/lib/modules/5.8.5-xanmod1-1-xanmod/build'
  CC [M]  /ramdisk/v4l2loopback/v4l2loopback.o
gcc: error: unrecognized command-line option ‘-Qunused-arguments’
gcc: error: unrecognized command-line option ‘-mno-global-merge’
make[2]: *** [scripts/Makefile.build:281: /ramdisk/v4l2loopback/v4l2loopback.o] Error 1
make[1]: *** [Makefile:1760: /ramdisk/v4l2loopback] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.8.5-xanmod1-1-xanmod/build'
make: *** [Makefile:43: v4l2loopback.ko] Error 2

Last edited by Sourav (2020-09-02 12:44:39)

Offline

#2 2021-04-20 03:42:29

ssrrss
Member
Registered: 2021-04-20
Posts: 2

Re: Use Clang with DKMS

Please stop using Clang compile the kernel, trust me!!
After you compile the kernel, you may need to use clang compile some kernel modules which might be failed. For example nvidia-driver, vmware etc.

The command you mentioned 'alternative-update' is used for update link. You can update link at /usr/bin manually.
ln -sf gcc clang
ln -sf g++ clang++

After building, you need to update them back once again.
ln -sf gcc gcc-10
ln -sf g++ g++-10

So, if you really need to use clang to compile kernel, you may need to compile the hole system by clang.

Offline

#3 2021-04-20 03:46:20

ssrrss
Member
Registered: 2021-04-20
Posts: 2

Re: Use Clang with DKMS

Note that I have compiled my new kernel 5.10 by clang-12. But I can't compile the vmware module, which means I can't use vmware on this kernel. So, I back to my old kernel.
And I don't want another person to struggle at this, or waste your time.

Offline

#4 2021-05-23 05:50:29

ruthafjord
Member
Registered: 2021-05-23
Posts: 1

Re: Use Clang with DKMS

Getting DKMS to work with clang built linux seems to be finicky right now.

I've been reading threads to try to figure out how to get the nvidia driver to compile(e.g. this thread), and it's not clear I'm going to get anywhere in the short term, since people are mostly proposing clever hacks at this point.

Last edited by ruthafjord (2021-05-23 05:51:33)

Offline

#5 2023-07-26 23:59:04

memchr
Member
Registered: 2022-12-17
Posts: 3

Re: Use Clang with DKMS

DKMS merged clang support https://github.com/dell/dkms/pull/169

It will use clang as the toolchain if the kernel was compiled with clang.

Offline

#6 2023-07-27 03:30:43

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,793

Re: Use Clang with DKMS

Closing this old thread.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB