Can not compile driver on Linux 5.12 with clang lto enable

compile driver failed when ld

The kernel has to be compiled using clang as well. Kernel and modules compiler have to match.

I already compiled using clang with lto and booted it successfully. But I failed to compile nvidia driver. I reproduce that later.

It will failed to compile like the pic when I enable the kernel’s lto. Fortunately I found old module can be used in the new kernel

You need to set LD to lld.

I already set lld as default LD in my distro. It’s able to compile others with lld. But it seems that the install script use ld.bfd to build the nvidia driver.

A quick glance at the kbuild script makes me believe it can be set by the LD env variable, did you try to set that?

Though I set LLVM_IAS=1 LLVM=1 as well as compiled with lld. Failed when linking too.

It’s ok in Linux 5.12 rc7