Fails to build on Debian 9 with Linux 5.4

I am running a self-built Linux 5.4 on Debian 9. When trying to install driver 440.44, it fails with these messages:

CONFTEST: is_export_symbol_gpl_refcount_dec_and_test
    CONFTEST: drm_alpha_blending_available
     LD [M]  /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia.o
     LD [M]  /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm.o
   ld -r -o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-interface.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-frontend.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-pci.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-acpi.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-cray.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-dma.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-i2c.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-mempool.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-mmap.o /
   tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-p2p.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-pat.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-procfs.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-usermap.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-vm.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-vtophys.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-interface.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-mlock.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-pci.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-registry.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-usermap.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-modeset-interface.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-pci-table.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-kthread-q.o /tmp/selfgz61840/NVIDIA-Linux-x86_
   64-440.44/kernel/nvidia/nv-memdbg.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-ibmnpu.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-report-err.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-rsync.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-msi.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv_uvm_interface.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nvlink_linux.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/linux_nvswitch.o
   ld -r -o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-modeset/nv-modeset-interface.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-modeset/nvidia-modeset-linux.o /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-modeset/nv-kthread-q.o
     LD [M]  /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-modeset.o
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-frontend.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-pci.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-acpi.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-cray.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-dma.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-i2c.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-mempool.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-mmap.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-p2p.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-pat.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-procfs.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-usermap.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-vm.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-vtophys.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-interface.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-mlock.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-pci.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-registry.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/os-usermap.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-modeset-interface.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-pci-table.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-kthread-q.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-memdbg.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-ibmnpu.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-report-err.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-rsync.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv-msi.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nv_uvm_interface.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/nvlink_linux.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia/linux_nvswitch.o: No such file or directory
     LD [M]  /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-drm.o
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm/uvm_utils.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm/uvm_common.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm/uvm_linux.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm/nvstatus.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm/nvCpuUuid.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm/nv-kthread-q.o: No such file or directory
   ld: cannot find /tmp/selfgz61840/NVIDIA-Linux-x86_64-440.44/kernel/nvidia-uvm/nv-kthread-q-selftest.o: No such file or directory

What could be wrong?
nvidia-bug-report.log.gz (52.9 KB)

Well, this error is fixed by removing the package libelf-dev. I was inspired by this thread: http://www.pclinuxos.com/forum/index.php/topic,145750.0.html

However, now it fails with:

CONFTEST: drm_alpha_blending_available
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-frontend.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-pci.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-acpi.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-cray.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-dma.o
In file included from /var/lib/dkms/nvidia/440.44/build/common/inc/conftest.h:5:0,
                 from /var/lib/dkms/nvidia/440.44/build/common/inc/nv-linux.h:17,
                 from /var/lib/dkms/nvidia/440.44/build/nvidia/nv-frontend.c:13:
/var/lib/dkms/nvidia/440.44/build/conftest/functions.h:10:2: error: #error acpi_walk_namespace() conftest failed!
 #error acpi_walk_namespace() conftest failed!
  ^~~~~
/var/lib/dkms/nvidia/440.44/build/conftest/functions.h:56:2: error: #error wait_on_bit_lock() conftest failed!
 #error wait_on_bit_lock() conftest failed!
  ^~~~~
/var/lib/dkms/nvidia/440.44/build/conftest/functions.h:61:2: error: #error radix_tree_replace_slot() conftest failed!
 #error radix_tree_replace_slot() conftest failed!
  ^~~~~
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-i2c.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-mempool.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-mmap.o
  CC [M]  /var/lib/dkms/nvidia/440.44/build/nvidia/nv-p2p.o
In file included from /var/lib/dkms/nvidia/440.44/build/common/inc/conftest.h:5:0,
                 from /var/lib/dkms/nvidia/440.44/build/common/inc/nv-linux.h:17,
                 from /var/lib/dkms/nvidia/440.44/build/nvidia/nv.c:14:
/var/lib/dkms/nvidia/440.44/build/conftest/functions.h:10:2: error: #error acpi_walk_namespace() conftest failed!
 #error acpi_walk_namespace() conftest failed!