ClangBuiltLinux / linux

Linux kernel source tree
Other
241 stars 14 forks source link

Building VirtualBox kernel modules with Clang and DKMS #1104

Closed torvic9 closed 2 years ago

torvic9 commented 4 years ago

Hi,

I don't know where to report this, but...let me try :) feel free to close if it's the wrong place.

So I finally managed to build current 5.7.10 kernel with LLVM=1 LLVM_IAS=1 with clang11 from the release/11.x branch, and the IAS related patches I found (among others) here: https://github.com/ClangBuiltLinux/linux/issues/1049 , and which I assembled together here: https://github.com/torvic9/linux57-vd/blob/master/0006-clang-llvm-ias-support.patch

The problem is that I cannot build the VBox host modules using CC=clang LD=ld.lld. I get the following errors:

./arch/x86/include/asm/page_64.h:49:2: error: expected '(' after 'asm'
        alternative_call_2(clear_page_orig,
        ^
/arch/x86/include/asm/segment.h:266:2: error: expected '(' after 'asm'
        alternative_io ("lsl %[seg],%[p]",
        ^

./arch/x86/include/asm/special_insns.h:212:2: error: expected '(' after 'asm'
        alternative_io(".byte " __stringify(NOP_DS_PREFIX) "; clflush %P0",
        ^

and many more of the same type.

Compiling the kernel with clang10 and without LLVM_IAS results in working VBox modules.

Is this an issue with the fact that I used LLVM_IAS for the kernel? Or is it rather related to using clang11 instead of clang10?

Thanks!

torvic9 commented 3 years ago

Here is a rebased version (based on Linus' tree): https://gitlab.com/torvic9/linux513-vd/-/blob/master/unused/Kbuild-add-option-for-choosing-a-ThinLTO-cache-direc.patch

Feel free to test and report.$

EDIT: major oops! I accidently removed a line. Do not use this, I will put up a rectified version.

torvic9 commented 3 years ago

Fixed patch (as a gist): https://gist.github.com/torvic9/17c6a86ca4345d62e7907c96231c2775

nickdesaulniers commented 3 years ago

I sent dkms a patch.

nickdesaulniers commented 2 years ago

This should be fixed as of DKMS 3.0.2. https://github.com/dell/dkms/commit/6ddb09145930b03c88e63f5930e718a33501024d

Note: there's also a requirement for dkms that clang be accesible from a $PATH allowlist. https://github.com/dell/dkms/issues/124#issuecomment-955194338 https://github.com/dell/dkms/blob/41efbd50f635af0ec230478525e5be56d6003896/dkms.in#L2163-L2164