[patch] [virtualbox-host-dkms] Suggestion: Build host modules only for GCC compiled kernels, since it makes CLANG compiled kernels freezing and upstream only supports GCC compiled kernels.
*This is not a bug report, but a feature suggestion, and includes a [patch](/uploads/f473627c8b36f3f9653deefb39fab04e/virtualbox_arch_linux_package_build_host_modules_only_for_gcc-kernels.patch) which tries to implement the feature. It fixes possible system freezes.*
*Note also that I report a "feature request" here because on [the site "Bug reporting guidelines" in the Arch Linux wiki](https://wiki.archlinux.org/title/Bug_reporting_guidelines#Opening_a_bug) it seems to me that feature suggestions are also going to this issue tracker:* "When you are sure it is a bug or a feature […], then you are ready to open a […] feature request." *So forgive me if this tracker is* only *for bugs, and then please point me to the correct place and maybe correct [the wiki](https://wiki.archlinux.org/title/Bug_reporting_guidelines).*
---
Ahoj,
according to [this comment from VirtualBox upstream](https://www.virtualbox.org/ticket/22064#comment:10):
> *We do not officially support CLANG on Linux host (only GCC is supported).*
`clang` compiled Linux kernels are not supported by the VirtualBox host kernel modules.
And [I experience kernel freeze when I actually do that](https://www.virtualbox.org/ticket/22064).
So I suggest to add some logic to the [`virtualbox PKGBUILD`](https://gitlab.archlinux.org/archlinux/packaging/packages/virtualbox) that the package `virtualbox-host-dkms` only compiles a module for Linux kernels compiled with `gcc`, not with `clang`.
The issue happens when someone has a custom compiled kernel, and has it compiled using CLANG.
And then install `virtualbox-host-dkms`.
DKMS then, _after_ installing the package `virtualbox-host-dkms`, builds VirtualBox host modules via DKMS also for CLANG compiled kernels, and it builds them with CLANG.
And when I then launch a VirtualBox VM, the system hard-freezes.
Attached (and below in plaintext) is a patch suggestion to this package which adds checks and maked DKMS abort if the kernel it is building for is not compiled with `gcc`:
[`virtualbox_arch_linux_package_build_host_modules_only_for_gcc-kernels.patch`](/uploads/f473627c8b36f3f9653deefb39fab04e/virtualbox_arch_linux_package_build_host_modules_only_for_gcc-kernels.patch):
```diff
diff -rNU1 virtualbox.orig/dkms_check_kernel_cc_make_wrapper.sh virtualbox/dkms_check_kernel_cc_make_wrapper.sh
--- virtualbox.orig/dkms_check_kernel_cc_make_wrapper.sh 1970-01-01 01:00:00.000000000 +0100
+++ virtualbox/dkms_check_kernel_cc_make_wrapper.sh 2024-11-24 14:26:27.940099446 +0100
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+_msg() {
+ printf '%s\n' "$@"
+}
+
+if [ "${KERNEL_CC}" == "gcc" ]; then
+ make "$@"
+else
+ _msg ""
+ _msg "ERROR building VirtualBox host modules:"
+ _msg ""
+ _msg "Build of VirtualBox host drivers is only supported for Linux kernels compiled with GCC."
+ _msg "Experience shows that using VirtualBox on CLANG compiled kernels leads to system freeze."
+ _msg "This kernel for which the modules now should be compiled was compiled with '${KERNEL_CC}'."
+ _msg "(For background, see e.g. https://www.virtualbox.org/ticket/22064)"
+ _msg ""
+ _msg "Aborting."
+ exit 99
+fi
diff -rNU1 virtualbox.orig/dkms_inform_about_cc.sh virtualbox/dkms_inform_about_cc.sh
--- virtualbox.orig/dkms_inform_about_cc.sh 1970-01-01 01:00:00.000000000 +0100
+++ virtualbox/dkms_inform_about_cc.sh 2024-11-24 14:26:01.943432530 +0100
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+_msg() {
+ printf '%s\n' "$@"
+}
+
+_msg ""
+_msg "== Information about compiler and linker to be used =="
+_msg "KERNEL_CC: ${KERNEL_CC:-(unset)}"
+_msg "CC: ${CC:-(unset)}"
+_msg "LD: ${LD:-(unset)}"
+
+if [ "${KERNEL_CC}" != "gcc" ]; then
+ _msg ""
+ _msg "ERROR building VirtualBox host modules:"
+ _msg ""
+ _msg "Build of VirtualBox host drivers is only supported for Linux kernels compiled with GCC."
+ _msg "Experience shows that using VirtualBox on CLANG compiled kernels leads to system freeze."
+ _msg "This kernel for which the modules now should be compiled was compiled with '${KERNEL_CC}'."
+ _msg "(For background, see e.g. https://www.virtualbox.org/ticket/22064)"
+ _msg ""
+ _msg "Build process will be aborted to prevent those modules from beeing installed."
+ ## Note: Exiting the PRE_BUILD script with a non-zero exitcode makes `dkms` _not_ aborting the build process. So we have a wrapper arounf `make` which does the check again and aborts. But the output of this is not printed to the terminal, so we have this block here to inform the user.
+fi
diff -rNU1 virtualbox.orig/PKGBUILD virtualbox/PKGBUILD
--- virtualbox.orig/PKGBUILD 2024-11-22 16:47:36.750020729 +0100
+++ virtualbox/PKGBUILD 2024-11-24 15:04:12.506787865 +0100
@@ -56,2 +56,4 @@
'virtualbox-host-dkms.conf'
+ 'dkms_inform_about_cc.sh'
+ 'dkms_check_kernel_cc_make_wrapper.sh'
'virtualbox.sysusers'
@@ -76,3 +78,5 @@
sha256sums=('872e7a42b41f8558abbf887f1bdc7aac932bb88b2764d07cbce270cab57e3b5e'
- '76d98ea062fcad9e5e3fa981d046a6eb12a3e718a296544a68b66f4b65cb56db'
+ '7790b2752f209abb194d597a35b4d0828dd1703a7c4169736a38a752bc0aa3ea' # 'virtualbox-host-dkms.conf'
+ 'fbfc010246e0a31be26bc971650f85ff7d607a00cc5f6bdcdb77df7a9aa200a5' # 'dkms_inform_about_cc.sh'
+ 'b497d03341766cfe9294f8df73625f40e9eb53f0c8c3574edf9ff9612bb47f39' # 'dkms_check_kernel_cc_make_wrapper.sh'
'2101ebb58233bbfadf3aa74381f22f7e7e508559d2b46387114bc2d8e308554c'
@@ -282,2 +286,3 @@
sed -i "s,@VERSION@,${pkgver}," "${_p}"
+ install -D -m0755 -t "${pkgdir}/usr/src/vboxhost-${pkgver}_OSE" "${srcdir}"/{dkms_inform_about_cc.sh,dkms_check_kernel_cc_make_wrapper.sh}
}
diff -rNU1 virtualbox.orig/virtualbox-host-dkms.conf virtualbox/virtualbox-host-dkms.conf
--- virtualbox.orig/virtualbox-host-dkms.conf 2024-11-22 16:47:36.750020729 +0100
+++ virtualbox/virtualbox-host-dkms.conf 2024-11-24 13:05:09.250052599 +0100
@@ -31 +31,7 @@
DEST_MODULE_LOCATION[2]="/kernel/misc"
+
+## clang compiled kernel is not supported and leads to system freeze, so do not build modules for that. See https://www.virtualbox.org/ticket/22064#comment:10.
+# Inform the user about kernel compiler and possible abort if it is not GCC:
+PRE_BUILD="dkms_inform_about_cc.sh" # Needs to be relative to `dkms.conf`.
+# Check if the kernel compiler is GCC, and abort if not:
+MAKE="./dkms_check_kernel_cc_make_wrapper.sh" # Is a system command, prepend `./` if it is relative to `dkms.conf`.
```
Regards!
issue