Clang Linux kernels and DKMS - ClangBuiltLinux/linux GitHub Wiki

Support for building out of tree kernel modules via DKMS with clang and ld.lld was added in the 3.0.2 release.

If you observe the following warnings from DKMS:

warning: the compiler differs from the one used to build the kernel
  The kernel was built by: clang version XX.X.X
  You are using:           gcc YY.Y.Y

Verify that:

  1. Your DKMS version is at least 3.0.2
  • To check dkms --version
  1. Clang and ld.lld are in (or symlinked from) the specific $PATHs DKMS uses.
  • Depending on the system, either use either which clang && which ld.lld or use command -V clang && command -V ld.lld

Note, at least as of the 3.0.2 release, DKMS will ignore the user's $PATH and instead rely on its own internal list. You may need to add a symlink to your clang binary in one of these directories if clang isn't already installed in of the the predefined locations. The same holds for the LLVM linker, ld.lld. The allowlist for $PATHs that DKMS will use is currently PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/lib/dkms" (but may have changed since this was written).

Other messages that indicate this issue are those produced automatically by apt/DPKG which may include

Consult /var/lib/dkms/[package name]

Error! Bad return status for module build on kernel:

package post-installation script subprocess returned error exit status 10

Amongst others.

if you encounter other errors related to but not mentioned here, please feel free to open an issue or send a pull request with a fix.