Frogging-Family / nvidia-all

Nvidia driver latest to 396 series AIO installer
768 stars 69 forks source link

Building the DKMS version on clang >= 13 fails #76

Closed keksbg closed 2 years ago

keksbg commented 2 years ago

It appears that on clang >= 13 it refuses to build due to the -mrecord-mcount flag not existing. Excerpt from make.log:

# [...]
 CONFTEST: ib_peer_memory_symbols
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv.o
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv-pci.o
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv-acpi.o
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv-cray.o
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv-dma.o
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv-i2c.o
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv-mmap.o
  CC [M]  /var/lib/dkms/nvidia/495.44/build/nvidia/nv-p2p.o
clang-13: error: unsupported option '-mrecord-mcount' for target 'x86_64-pc-linux-gnu'
clang-13: error: unsupported option '-mrecord-mcount' for target 'x86_64-pc-linux-gnu'
make[2]: *** [scripts/Makefile.build:272: /var/lib/dkms/nvidia/495.44/build/nvidia/nv.o] Error 1
make[2]: *** Waiting for unfinished jobs....
# [...]

Downgrading to clang 12 makes it work again with no errors.

ptr1337 commented 2 years ago

For me its working, also with clang-14. But i dont use atm -tkg nvidia drivers.

You can try to built with this patch dkms, then remove out of your framework.conf the exports.

From 3eb09af9358a1bd55b9ca04866b5161e714bd5f2 Mon Sep 17 00:00:00 2001
From: Simone Caronni <negativo17@gmail.com>
Date: Tue, 16 Nov 2021 16:53:56 +0100
Subject: [PATCH 1/5] Add more deprecated options

---
 dkms.in | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/dkms.in b/dkms.in
index 70b26ac..4d54378 100644
--- a/dkms.in
+++ b/dkms.in
@@ -2200,9 +2200,17 @@ while (($# > 0)); do
             exit 0
             ;;
         --no-initrd)
-            # This is a old option, consume and warn
+            # This is an old option, consume and warn
             deprecated $"--no-initrd"
             ;;
+        --no-clean-kernel)
+            # This is an old option, consume and warn
+            deprecated $"--no-clean-kernel"
+            ;;
+        --no-prepare-kernel)
+            # This is an old option, consume and warn
+            deprecated $"--no-prepare-kernel"
+            ;;
         --binaries-only)
             binaries_only="binaries-only"
             ;;
-- 
2.34.0

From f5051d0543aaf933874ae512f5624ac1fd95056d Mon Sep 17 00:00:00 2001
From: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Date: Wed, 17 Nov 2021 09:50:32 +0000
Subject: [PATCH 2/5] Enable using add, build and install with a directory
 again

Since commit e73f9bbf2013 ("dkms: fixup add/remove...uninstall
permission checking"), it was no longer possible to use "dkms add" with
a directory:

    $ dkms add test/dkms_test-1.0
    Error! Arguments <module> and <module-version> are not specified.
    Usage: add <module>/<module-version> or
           add -m <module>/<module-version> or
           add -m <module> -v <module-version>

But when options -m and -v are given, the source directory is ignored.

Fix this issue by removing the check for -m and -v in add, build and
install actions. This makes the following commands work again (for
example on Arch Linux):

    $ dkms add test/dkms_test-1.0
    Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0

    $ dkms remove -m dkms_test -v 1.0 --all
    ...
    $ dkms install -k 5.15.2-arch1-1 test/dkms_test-1.0
    Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0

    Building module:
    cleaning build area...
    make -j8 KERNELRELEASE=5.15.2-arch1-1 -C /lib/modules/5.15.2-arch1-1/build M=/var/lib/dkms/dkms_test/1.0/build...
    cleaning build area...

    dkms_test.ko:
    Running module version sanity check.
     - Original module
       - No original module exists within this kernel
     - Installation
       - Installing to /lib/modules/5.15.2-arch1-1/kernel/extra/
    depmod...

    $ dkms remove -m dkms_test -v 1.0 --all
    ...
    $ dkms build -k 5.15.2-arch1-1 test/dkms_test-1.0
    Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0

    Building module:
    cleaning build area...
    make -j8 KERNELRELEASE=5.15.2-arch1-1 -C /lib/modules/5.15.2-arch1-1/build M=/var/lib/dkms/dkms_test/1.0/build...
    cleaning build area...

Fixes: https://github.com/dell/dkms/issues/177
---
 dkms.in | 1 -
 1 file changed, 1 deletion(-)

diff --git a/dkms.in b/dkms.in
index 4d54378..ea51800 100644
--- a/dkms.in
+++ b/dkms.in
@@ -2347,7 +2347,6 @@ remove | unbuild | uninstall)
     ${action}_module
     ;;
 add | build | install)
-    check_module_args $action
     check_all_is_banned $action # TODO: fix/enable --all
     [[ $action = install ]] && check_root || check_rw_dkms_tree
     ${action}_module
-- 
2.34.0

From fe0a25b96b451333b9642ad960e87f5af2df15e5 Mon Sep 17 00:00:00 2001
From: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Date: Wed, 17 Nov 2021 16:21:01 +0000
Subject: [PATCH 3/5] Fix Linux distribution identification through
 /etc/os-release

On Linux distributions such as Arch Linux, /etc/os-release contains:

    NAME="Arch Linux"
    PRETTY_NAME="Arch Linux"
    ID=arch
    BUILD_ID=rolling
    ANSI_COLOR="38;2;23;147;209"
    HOME_URL="https://archlinux.org/"
    DOCUMENTATION_URL="https://wiki.archlinux.org/"
    SUPPORT_URL="https://bbs.archlinux.org/"
    BUG_REPORT_URL="https://bugs.archlinux.org/"
    LOGO=archlinux-logo

There is no `ID_LIKE` property, so `${#ID_LIKE[@]}` is zero:

    $ . /etc/os-release
    $ echo ${#ID_LIKE[@]}
    0

As `0` is not empty, `[[ ${#ID_LIKE[@]} ]]` is true:

    $ [[ ${#ID_LIKE[@]} ]] ; echo $?
    0

So in `dkms`, the function `distro_version` returns an empty string in

    [[ ${#ID_LIKE[@]} ]] && echo ${ID_LIKE[0]} || echo $ID

Fix this by replacing `[[ ${#ID_LIKE[@]} ]]` with `[[ ${#ID_LIKE[@]} != 0]]`.

Fixes: f0b11ce07005 ("dkms: rework distribution detection")
---
 dkms.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dkms.in b/dkms.in
index ea51800..9c98a89 100644
--- a/dkms.in
+++ b/dkms.in
@@ -317,7 +317,7 @@ distro_version()
 {
     if [[ -r /etc/os-release ]]; then
         . /etc/os-release
-        [[ ${#ID_LIKE[@]} ]] && echo ${ID_LIKE[0]} || echo $ID
+        [[ ${#ID_LIKE[@]} != 0 ]] && echo ${ID_LIKE[0]} || echo $ID
         return
     fi

-- 
2.34.0

From 64d252db8400a009e877b1c9c71ee556ae83a1ec Mon Sep 17 00:00:00 2001
From: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Date: Wed, 17 Nov 2021 16:59:17 +0000
Subject: [PATCH 4/5] Add a basic test infrastructure

To prevent regressions such as the one identified in
https://github.com/dell/dkms/issues/177, introduce a shell script which
executes dkms add/build/install/uninstall/unbuild/remove with some
variations. Also introduce a configuration for GitHub Actions'
continuous integration environment, which runs this scripts with several
Linux distributions, using containers.

This is a first step towards building a test suite similar to what was
described on https://github.com/dell/dkms/issues/173.
---
 .github/workflows/tests.yml | 128 ++++++++++++
 run_test.sh                 | 375 ++++++++++++++++++++++++++++++++++++
 2 files changed, 503 insertions(+)
 create mode 100644 .github/workflows/tests.yml
 create mode 100755 run_test.sh

diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..c08c1e3
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,128 @@
+name: Run tests
+
+on: [push, pull_request]
+
+jobs:
+  test-distributions:
+    name: Build in containers
+    strategy:
+      matrix:
+        distro:
+          - {name: "alpine", tag: "3.14", variant: "-lts"}
+          - {name: "alpine", tag: "3.14", variant: "-virt"}
+          - {name: "alpine", tag: "3.13", variant: "-lts"}
+          - {name: "alpine", tag: "3.13", variant: "-virt"}
+          - {name: "alpine", tag: "3.12", variant: "-lts"}
+          - {name: "alpine", tag: "3.12", variant: "-virt"}
+          - {name: "alpine", tag: "3.11", variant: "-lts"}
+          - {name: "alpine", tag: "3.11", variant: "-virt"}
+          - {name: "alpine", tag: "3.10", variant: "-vanilla"}
+          - {name: "alpine", tag: "3.10", variant: "-virt"}
+          - {name: "archlinux", tag: "latest"}
+          - {name: "archlinux", tag: "latest", variant: "-lts"}
+          - {name: "archlinux", tag: "latest", variant: "-zen"}
+          - {name: "centos", tag: "7"}
+          - {name: "centos", tag: "8"}
+          - {name: "debian", tag: "11"}
+          - {name: "debian", tag: "10"}
+          - {name: "debian", tag: "9"}
+          - {name: "debian", tag: "8"}
+          - {name: "ubuntu", tag: "20.04"}
+          - {name: "ubuntu", tag: "18.04"}
+          - {name: "ubuntu", tag: "16.04"}
+    runs-on: ubuntu-20.04
+    container:
+      image: docker://docker.io/library/${{ matrix.distro.name }}:${{ matrix.distro.tag }}
+
+    steps:
+    - uses: actions/checkout@v2
+
+    - name: Install Alpine dependencies
+      if: matrix.distro.name == 'alpine'
+      run: |
+        apk --no-cache --update add bash gcc linux${{ matrix.distro.variant }} linux${{ matrix.distro.variant }}-dev make
+
+    - name: Install Arch Linux dependencies
+      if: matrix.distro.name == 'archlinux'
+      run: |
+        pacman -Syu --noconfirm diffutils gcc make linux${{ matrix.distro.variant }}-headers
+
+    - name: Install CentOS dependencies
+      if: matrix.distro.name == 'centos'
+      run: |
+        yum install -y diffutils elfutils-libelf-devel gcc kernel kernel-devel make
+
+    - name: Install Debian dependencies
+      if: matrix.distro.name == 'debian'
+      run: |
+        apt-get update -q
+        apt-get install -qy gcc make linux-headers-amd64 linux-image-amd64
+
+    - name: Install Ubuntu dependencies
+      if: matrix.distro.name == 'ubuntu'
+      run: |
+        apt-get update -q
+        apt-get install -qy gcc make linux-headers-generic linux-image-generic
+
+    - name: Compute packaged kernel version
+      id: versions
+      run: |
+        KERNEL_VER=''
+        if [ "${{ matrix.distro.name }}" = alpine ] ; then
+            KERNEL_VER="$(apk info --contents "linux${{ matrix.distro.variant }}-dev" | sed -n 's:^lib/modules/\([^/][^/]*\)/.*:\1:p' | head -n 1)"
+        elif [ "${{ matrix.distro.name }}" = archlinux ] ; then
+            KERNEL_VER="$(pacman -Qql "linux${{ matrix.distro.variant }}-headers" | sed -n 's:^/usr/lib/modules/\([^/]\+\)/.*:\1:p' | head -n 1)"
+        elif [ "${{ matrix.distro.name }}" = centos ] ; then
+            KERNEL_VER="$(LANG=C rpm -qi kernel-devel | sed -n 's/^Source RPM *: kernel-\(.*\).src.rpm$/\1.x86_64/p' | tail -n 1)"
+        elif [ "${{ matrix.distro.name }}" = debian ] ; then
+            KERNEL_VER="$(LANG=C dpkg --status linux-headers-amd64 | sed -n 's/^Depends: linux-headers-\(\S\+\)\( .*\)\?/\1/p' | head -n 1)"
+        elif [ "${{ matrix.distro.name }}" = ubuntu ] ; then
+            KERNEL_VER="$(LANG=C dpkg --status linux-headers-generic | sed -n 's/^Depends: linux-headers-\(\S\+\)\( .*\)\?/\1/p' | head -n 1)"
+        fi
+        if [ -z "${KERNEL_VER}" ] ; then
+            echo >&2 "Error: no kernel package found"
+            exit 1
+        fi
+        echo "Found packaged kernel ${KERNEL_VER}"
+        echo "KERNEL_VER=${KERNEL_VER}" >> "$GITHUB_ENV"
+
+    - name: Install dkms
+      run: make install
+
+    - name: Run tests
+      run: ./run_test.sh
+
+  test-vm:
+    name: Test in Ubuntu VM
+    strategy:
+      matrix:
+        version:
+          - 20.04
+          - 18.04
+    runs-on: ubuntu-${{ matrix.version }}
+
+    steps:
+    - uses: actions/checkout@v2
+
+    - name: Install dependencies
+      run: |
+        sudo apt-get update -q
+        sudo apt-get install -qqy make
+
+        # Do not sign modules
+        sudo rm -r /var/lib/shim-signed/mok/
+
+    - name: Install dkms
+      run: sudo make install
+
+    - name: Run tests
+      run: sudo ./run_test.sh
+
+    - name: Install the test module
+      run: sudo dkms install test/dkms_test-1.0
+
+    - name: Load the test module
+      run: sudo modprobe dkms_test
+
+    - name: Remove the test module
+      run: sudo dkms remove --all -m dkms_test -v 1.0
diff --git a/run_test.sh b/run_test.sh
new file mode 100755
index 0000000..5baf98c
--- /dev/null
+++ b/run_test.sh
@@ -0,0 +1,375 @@
+#!/bin/bash
+# Test that dkms works properly
+set -eu
+
+# Change the to base directory
+cd "$(dirname -- "$0")"
+
+# To use a specific kernel version, use the environment variable KERNEL_VER
+KERNEL_VER="${KERNEL_VER:-$(uname -r)}"
+echo "Using kernel ${KERNEL_VER}"
+
+# Override PATH to use the local dkms binary
+PATH="$(pwd):$PATH"
+export PATH
+
+# Some helpers
+dkms_status_grep_dkms_test() {
+    (dkms status | grep '^dkms_test/') || true
+}
+
+check_no_dkms_test() {
+    local found_moule
+
+    found_moule="$(dkms_status_grep_dkms_test)"
+    if [[ -n "$found_moule" ]] ; then
+        echo >&2 'Error: module dkms_test is still in DKMS tree'
+        return 1
+    fi
+    if [[ -d /usr/src/dkms_test-1.0 ]] ; then
+        echo >&2 'Error: directory /usr/src/dkms_test-1.0 still exists'
+        return 1
+    fi
+}
+
+run_with_expected_output() {
+    cat > test_cmd_expected_output.log
+    if "$@" > test_cmd_output.log 2>&1 ; then
+        # "depmod..." lines can have multiple points. Replace them, to be able to compare
+        sed 's/\(depmod\|build\)\.\.\.\.*$/\1.../' -i test_cmd_output.log
+        # On CentOS, weak-modules is executed. Drop it from the output, to be more generic
+        sed '/^Adding any weak-modules$/d' -i test_cmd_output.log
+        sed '/^Removing any linked weak-modules$/d' -i test_cmd_output.log
+        # "depmod..." lines are missing when uninstalling modules on CentOS. Remove them to be more generic
+        if [[ $# -ge 2 && "$2" =~ uninstall|unbuild|remove ]] ; then
+            sed '/^depmod\.\.\.$/d' -i test_cmd_output.log
+        fi
+        if ! diff -U3 test_cmd_expected_output.log test_cmd_output.log ; then
+            echo >&2 "Error: unexpected output from: $*"
+            return 1
+        fi
+        rm test_cmd_expected_output.log test_cmd_output.log
+    else
+        echo "Error: command '$*' returned status $?"
+        cat test_cmd_output.log
+        rm test_cmd_expected_output.log test_cmd_output.log
+        return 1
+    fi
+}
+
+run_with_expected_error() {
+    local expected_error_code="$1"
+    local error_code
+
+    shift
+    cat > test_cmd_expected_output.log
+    if "$@" > test_cmd_output.log 2>&1 ; then
+        echo "Error: command '$*' was successful"
+        cat test_cmd_output.log
+        rm test_cmd_expected_output.log test_cmd_output.log
+        return 1
+    else
+        error_code=$?
+    fi
+    if [[ "${error_code}" != "${expected_error_code}" ]] ; then
+        echo "Error: command '$*' returned status ${error_code} instead of expected ${expected_error_code}"
+        cat test_cmd_output.log
+        rm test_cmd_expected_output.log test_cmd_output.log
+        return 1
+    fi
+    if ! diff -U3 test_cmd_expected_output.log test_cmd_output.log ; then
+        echo >&2 "Error: unexpected output from: $*"
+        return 1
+    fi
+    rm test_cmd_expected_output.log test_cmd_output.log
+}
+
+# Compute the expected destination module location
+os_id="$(sed -n 's/^ID\s*=\s*\(.*\)$/\1/p' /etc/os-release | tr -d '"')"
+mod_compression_ext=
+case "${os_id}" in
+    centos | fedora | rhel | ovm)
+        expected_dest_loc=extra
+        mod_compression_ext=.xz
+        ;;
+    sles | suse | opensuse)
+        expected_dest_loc=updates
+        ;;
+    arch | debian | ubuntu)
+        expected_dest_loc=updates/dkms
+        ;;
+    alpine)
+        expected_dest_loc=kernel/extra
+        ;;
+    *)
+        echo >&2 "Error: unknown Linux distribution ID ${os_id}"
+        exit 1
+        ;;
+esac
+
+
+echo 'Checking that the environment is clean'
+check_no_dkms_test
+
+echo 'Adding the test module by version (expected error)'
+run_with_expected_error 2 dkms add -m dkms_test -v 1.0 << EOF
+Error! Could not find module source directory.
+Directory: /usr/src/dkms_test-1.0 does not exist.
+EOF
+
+echo 'Adding the test module by directory'
+run_with_expected_output dkms add test/dkms_test-1.0 << EOF
+Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0: added
+EOF
+if ! [[ -d /usr/src/dkms_test-1.0 ]] ; then
+    echo >&2 'Error: directory /usr/src/dkms_test-1.0 was not created'
+    return 1
+fi
+
+echo 'Adding the test module again (expected error)'
+run_with_expected_error 3 dkms add test/dkms_test-1.0 << EOF
+Error! DKMS tree already contains: dkms_test-1.0
+You cannot add the same module/version combo more than once.
+EOF
+
+echo 'Adding the test module by version (expected error)'
+run_with_expected_error 3 dkms add -m dkms_test -v 1.0 << EOF
+Error! DKMS tree already contains: dkms_test-1.0
+You cannot add the same module/version combo more than once.
+EOF
+
+echo 'Building the test module'
+run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+
+Building module:
+cleaning build area...
+make -j$(nproc) KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build...
+cleaning build area...
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): built
+EOF
+
+echo 'Building the test module again'
+run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Module dkms_test/1.0 already built for kernel ${KERNEL_VER} ($(uname -m)).
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): built
+EOF
+
+echo 'Installing the test module'
+run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+
+dkms_test.ko${mod_compression_ext}:
+Running module version sanity check.
+ - Original module
+   - No original module exists within this kernel
+ - Installation
+   - Installing to /lib/modules/${KERNEL_VER}/${expected_dest_loc}/
+depmod...
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): installed
+EOF
+
+echo 'Installing the test module again'
+run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Module dkms_test/1.0 already installed on kernel ${KERNEL_VER} ($(uname -m)).
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): installed
+EOF
+if ! [[ -f "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then
+    echo >&2 "Error: module not found in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}"
+    exit 1
+fi
+
+echo 'Checking modinfo'
+run_with_expected_output sh -c "modinfo /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} | head -n 4" << EOF
+filename:       /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}
+version:        1.0
+description:    A Simple dkms test module
+license:        GPL
+EOF
+
+echo 'Uninstalling the test module'
+run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Module dkms_test-1.0 for kernel ${KERNEL_VER} ($(uname -m)).
+Before uninstall, this module version was ACTIVE on this kernel.
+
+dkms_test.ko${mod_compression_ext}:
+ - Uninstallation
+   - Deleting from: /lib/modules/${KERNEL_VER}/${expected_dest_loc}/
+ - Original module
+   - No original module was found for this module on this kernel.
+   - Use the dkms install command to reinstall any previous module version.
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): built
+EOF
+if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then
+    echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}"
+    exit 1
+fi
+
+echo 'Uninstalling the test module again'
+run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Module dkms_test 1.0 is not installed for kernel ${KERNEL_VER} ($(uname -m)). Skipping...
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): built
+EOF
+
+echo 'Unbuilding the test module'
+run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Module dkms_test 1.0 is not installed for kernel ${KERNEL_VER} ($(uname -m)). Skipping...
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0: added
+EOF
+
+echo 'Unbuilding the test module again'
+run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Module dkms_test 1.0 is not installed for kernel ${KERNEL_VER} ($(uname -m)). Skipping...
+Module dkms_test 1.0 is not built for kernel ${KERNEL_VER} ($(uname -m)). Skipping...
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0: added
+EOF
+
+echo 'Removing the test module'
+run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Module dkms_test 1.0 is not installed for kernel ${KERNEL_VER} ($(uname -m)). Skipping...
+Module dkms_test 1.0 is not built for kernel ${KERNEL_VER} ($(uname -m)). Skipping...
+Deleting module dkms_test-1.0 completely from the DKMS tree.
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+EOF
+if ! [[ -d /usr/src/dkms_test-1.0 ]] ; then
+    echo >&2 'Error: directory /usr/src/dkms_test-1.0 was removed'
+    return 1
+fi
+
+echo 'Adding the test module by version'
+run_with_expected_output dkms add -m dkms_test -v 1.0 << EOF
+Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0: added
+EOF
+
+echo 'Removing the test module'
+run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF
+Deleting module dkms_test-1.0 completely from the DKMS tree.
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+EOF
+
+echo 'Installing the test module by version (combining add, build, install)'
+run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF
+Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0
+
+Building module:
+cleaning build area...
+make -j$(nproc) KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build...
+cleaning build area...
+
+dkms_test.ko${mod_compression_ext}:
+Running module version sanity check.
+ - Original module
+   - No original module exists within this kernel
+ - Installation
+   - Installing to /lib/modules/${KERNEL_VER}/${expected_dest_loc}/
+depmod...
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): installed
+EOF
+if ! [[ -f "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then
+    echo >&2 "Error: module not found in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}"
+    exit 1
+fi
+
+echo 'Checking modinfo'
+run_with_expected_output sh -c "modinfo /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} | head -n 4" << EOF
+filename:       /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}
+version:        1.0
+description:    A Simple dkms test module
+license:        GPL
+EOF
+
+echo 'Removing the test module with --all'
+run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF
+Module dkms_test-1.0 for kernel ${KERNEL_VER} ($(uname -m)).
+Before uninstall, this module version was ACTIVE on this kernel.
+
+dkms_test.ko${mod_compression_ext}:
+ - Uninstallation
+   - Deleting from: /lib/modules/${KERNEL_VER}/${expected_dest_loc}/
+ - Original module
+   - No original module was found for this module on this kernel.
+   - Use the dkms install command to reinstall any previous module version.
+Deleting module dkms_test-1.0 completely from the DKMS tree.
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+EOF
+if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then
+    echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}"
+    exit 1
+fi
+
+echo 'Removing /usr/src/dkms_test-1.0'
+rm -r /usr/src/dkms_test-1.0
+
+echo 'Building the test module by config file (combining add, build)'
+run_with_expected_output dkms build -k "${KERNEL_VER}" test/dkms_test-1.0/dkms.conf << EOF
+Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0
+
+Building module:
+cleaning build area...
+make -j$(nproc) KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build...
+cleaning build area...
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+dkms_test/1.0, ${KERNEL_VER}, $(uname -m): built
+EOF
+
+echo "Running dkms autoinstall"
+run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF
+
+dkms_test.ko${mod_compression_ext}:
+Running module version sanity check.
+ - Original module
+   - No original module exists within this kernel
+ - Installation
+   - Installing to /lib/modules/${KERNEL_VER}/${expected_dest_loc}/
+depmod...
+EOF
+
+echo 'Removing the test module with --all'
+run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF
+Module dkms_test-1.0 for kernel ${KERNEL_VER} ($(uname -m)).
+Before uninstall, this module version was ACTIVE on this kernel.
+
+dkms_test.ko${mod_compression_ext}:
+ - Uninstallation
+   - Deleting from: /lib/modules/${KERNEL_VER}/${expected_dest_loc}/
+ - Original module
+   - No original module was found for this module on this kernel.
+   - Use the dkms install command to reinstall any previous module version.
+Deleting module dkms_test-1.0 completely from the DKMS tree.
+EOF
+run_with_expected_output dkms_status_grep_dkms_test << EOF
+EOF
+
+echo 'Removing /usr/src/dkms_test-1.0'
+rm -r /usr/src/dkms_test-1.0
+
+echo 'Checking that the environment is clean again'
+check_no_dkms_test
+
+echo 'All tests successful :)'
-- 
2.34.0

From 786dc39e5077d9c2c44e8a23bc836dc9523029a2 Mon Sep 17 00:00:00 2001
From: "P. Jung" <ptr1337@cachyos.org>
Date: Thu, 18 Nov 2021 19:23:57 +0000
Subject: [PATCH 5/5] clang

---
 dkms.in | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/dkms.in b/dkms.in
index 9c98a89..97cc1c9 100644
--- a/dkms.in
+++ b/dkms.in
@@ -571,6 +571,16 @@ read_conf()
         make_command="${MAKE[$index]}"
     done

+    # Check if clang was used to compile or lld was used to link the kernel.
+    if [[ -e $kernel_source_dir/vmlinux ]]; then
+      if  readelf -p .comment $kernel_source_dir/vmlinux | grep -q clang; then
+        make_command="${make_command} CC=clang"
+      fi
+      if  readelf -p .comment $kernel_source_dir/vmlinux | grep -q LLD; then
+        make_command="${make_command} LD=ld.lld"
+      fi
+    fi
+
     # Use the generic make and make clean commands if not specified
     [[ ! $make_command ]] && make_command="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build"
     [[ ! $clean ]] && clean="make -C $kernel_source_dir M=$dkms_tree/$module/$module_version/build clean"
-- 
2.34.0
ptr1337 commented 2 years ago

Can be closed. is fixed with the latest dkms @archlinux repos

keksbg commented 2 years ago

Yes, this does appear to have been fixed by the update to dkms.