4

I have very little experience with kernel module development. Despite this I have been tasked with maintaining an old driver for a Sensoray 626 DAQ card. I am using a very simple dkms setup to build and install the driver which has been working well for a long time. The driver has been working in Ubuntu 22.04 until recently I ran into the error below during the kernel module build and I'm unable to find a solution. Any help is appreciated. If additional information is needed, simply ask and I will update the question with the requested information.

Note: I am aware that Comedi has a driver for the Sensoray 626. I do not want to use the Comedi driver.

DKMS build log:

DKMS make.log for s626-1.0.5 for kernel 6.5.0-14-generic (x86_64)
Fri Jan 12 01:17:52 PM PST 2024
make -C /lib/modules/6.5.0-14-generic/build M=/var/lib/dkms/s626/1.0.5/build SUBDIRS=/var/lib/dkms/s626/1.0.5/build
make[1]: Entering directory '/usr/src/linux-headers-6.5.0-14-generic'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
  You are using:           gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
  CC [M]  /var/lib/dkms/s626/1.0.5/build/s626drv.o
gcc: error: unrecognized command-line option ‘-ftrivial-auto-var-init=zero’
make[3]: *** [scripts/Makefile.build:251: /var/lib/dkms/s626/1.0.5/build/s626drv.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.5.0-14-generic/Makefile:2037: /var/lib/dkms/s626/1.0.5/build] Error 2
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.5.0-14-generic'
make: *** [Makefile:29: all] Error 2
  • Distribution: Ubuntu 22.04.3 LTS
  • Linux kernel version: 6.5.0-14-generic

Output of apt list --installed | grep gcc

gcc-11-base/jammy-updates,jammy-security,now 11.4.0-1ubuntu1~22.04 amd64 [installed,automatic]
gcc-11/jammy-updates,jammy-security,now 11.4.0-1ubuntu1~22.04 amd64 [installed,automatic]
gcc-12-base/jammy-updates,jammy-security,now 12.3.0-1ubuntu1~22.04 amd64 [installed,automatic]
gcc-12/jammy-updates,jammy-security,now 12.3.0-1ubuntu1~22.04 amd64 [installed,automatic]
gcc/jammy,now 4:11.2.0-1ubuntu1 amd64 [installed,automatic]
libgcc-11-dev/jammy-updates,jammy-security,now 11.4.0-1ubuntu1~22.04 amd64 [installed,automatic]
libgcc-12-dev/jammy-updates,jammy-security,now 12.3.0-1ubuntu1~22.04 amd64 [installed,automatic]
libgcc-s1/jammy-updates,jammy-security,now 12.3.0-1ubuntu1~22.04 amd64 [installed,automatic]

Makefile (note this makefile has recipes for things other than the kernel module and the CC variable is not used for building the kernel module):

###############################################################################
# for kernel modeule level driver:

# Kernel directory
KDIR        := /lib/modules/$(shell uname -r)/build
# Module directory
MODDIR      := /lib/modules/$(shell uname -r)/kernel/drivers/sensoray

# System values
PWD     := $(shell pwd)
KERNEL_24   := $(if $(wildcard $(KDIR)/Rules.make),1,0)

# Target file
obj-m       := s626.o


# Source files
ifeq    ($(KERNEL_24),0) # > 2.4
s626-objs   := s626drv.o 
else # <= 2.4
s626-objs   := s626drv.o
endif

.PHONY:     all clean modules_install

ifeq    ($(KERNEL_24),0) # > 2.4
ifeq    ($(KERNELRELEASE),)
all:
        $(MAKE) -C $(KDIR) M=$(PWD) SUBDIRS=$(PWD)
clean modules_install:
        $(MAKE) -C $(KDIR) M=$(PWD) SUBDIRS=$(PWD) $@
endif   # KERNELRELEASE

else    # <= 2.4

ifneq   ($(KERNELRELEASE),)

include $(KDIR)/Rules.make

s626.o: $(s626-objs)
        $(Q)$(LD) $(LD_RFLAG) -r -o $@ $(s626-objs)
else

all:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
        rm -f *.ko *.o .*.cmd .*.o.flags *.mod.c

endif   # KERNELRELEASE

endif   # KERNEL_24

ifeq    ($(KERNEL_24),1) # <= 2.4

install:        s626.o
    @if [ -d /lib/modules/$(shell uname -r)/kernel/drivers/sensoray/ ];\
    then rm -f /lib/modules/$(shell uname -r)/kernel/drivers/sensoray/s626.*;\
    fi
    @if [ -d /lib/modules/$(shell uname -r)/extra/ ];\
    then rm -f /lib/modules/$(shell uname -r)/extra/s626.*;\
    fi
    su -c "set -x;./MAKEDEV;mkdir -p $(MODDIR);cp -v s626.o $(MODDIR);depmod -a"

else
install:        s626.ko
    @if [ -d /lib/modules/$(shell uname -r)/kernel/drivers/sensoray/ ];\
    then rm -f /lib/modules/$(shell uname -r)/kernel/drivers/sensoray/s626.*; \
    fi
    @if [ -d /lib/modules/$(shell uname -r)/extra/ ];\
    then rm -f /lib/modules/$(shell uname -r)/extra/s626.*;\
    fi
    @if [ -d /lib/modules/$(shell uname -r)/kernel/drivers/staging/comedi/drivers ];\
    then rm -f /lib/modules/$(shell uname -r)/kernel/drivers/staging/comedi/drivers/s626.*;\
    fi
    su -c "set -x;./MAKEDEV;mkdir -p $(MODDIR);cp -v s626.ko $(MODDIR);install -m 444 s626.ko $(MODDIR);depmod -a"
endif  # KERNEL > 2.4


###############################################################################
# for library and application level:
SRC=            # module source tree
CC=         # compiler
AR=         # library manager

# source path
ifeq ($(strip $(SRC)),)
    SRC=.
endif

# the compiler
ifeq ($(strip $(CC)),)
    CC=gcc
endif

# the library manager
ifeq ($(strip $(AR)),)
    AR=ar
endif

# build the distribution's library
lib:        libs626.a
libs626.a:  s626core.o s626mod.o
        $(AR) cr libs626.a $(SRC)/s626core.o $(SRC)/s626mod.o

# compile the 626 universal core
core:       s626core.o
s626core.o: $(SRC)/s626core.c $(SRC)/s626core.h $(SRC)/s626mod.h
        $(CC) $(CFLAGS) -c $(SRC)/s626core.c

# build the 626 OS-dependent module
mod:        s626mod.o
s626mod.o:  $(SRC)/s626mod.c $(SRC)/s626core.h $(SRC)/s626mod.h $(SRC)/s626drv.h $(SRC)/s626.h $(SRC)/s626api.h
        $(CC) $(CFLAGS) -c $(SRC)/s626mod.c

# build the distribution's library (you may need to install gcc-multilib package)
lib32:      libs626-32.a
libs626-32.a:   s626core-32.o s626mod-32.o
        $(AR) cr libs626-32.a $(SRC)/s626core-32.o $(SRC)/s626mod-32.o

# compile the 626 universal core
s626core-32.o:  $(SRC)/s626core.c $(SRC)/s626core.h $(SRC)/s626mod.h
        $(CC) $(CFLAGS) -m32 -c $(SRC)/s626core.c -o $@

# build the 626 OS-dependent module
s626mod-32.o:   $(SRC)/s626mod.c $(SRC)/s626core.h $(SRC)/s626mod.h $(SRC)/s626drv.h $(SRC)/s626.h $(SRC)/s626api.h
        $(CC) $(CFLAGS) -m32 -c $(SRC)/s626mod.c -o $@

#----------------------------------------------------------------
# Demonstration programs
# type "make demo" to compile, link, and create demo application
demo:       libs626.a s626demo.o s626dm2b.o
        $(CC) -o s626demo s626demo.o -L$(SRC) -ls626 -lpthread
        $(CC) -o s626dm2b s626dm2b.o -L$(SRC) -ls626 -lpthread

s626demo.o: $(SRC)/s626demo.c $(SRC)/s626core.h $(SRC)/s626mod.h $(SRC)/s626drv.h $(SRC)/s626api.h $(SRC)/App626.h
        $(CC) $(CFLAGS) -c $(SRC)/s626demo.c

s626dm2b.o: $(SRC)/s626dm2b.c $(SRC)/s626core.h $(SRC)/s626mod.h $(SRC)/s626drv.h $(SRC)/s626api.h $(SRC)/App626.h
        $(CC) $(CFLAGS) -c $(SRC)/s626dm2b.c

demo32:     libs626-32.a s626demo-32.o s626dm2b-32.o
        $(CC) -m32 -o s626demo-32 s626demo-32.o -L$(SRC) -ls626-32 -lpthread
        $(CC) -m32 -o s626dm2b-32 s626dm2b-32.o -L$(SRC) -ls626-32 -lpthread

s626demo-32.o:  $(SRC)/s626demo.c $(SRC)/s626core.h $(SRC)/s626mod.h $(SRC)/s626drv.h $(SRC)/s626api.h $(SRC)/App626.h
        $(CC) $(CFLAGS) -m32 -c $(SRC)/s626demo.c -o $@

s626dm2b-32.o:  $(SRC)/s626dm2b.c $(SRC)/s626core.h $(SRC)/s626mod.h $(SRC)/s626drv.h $(SRC)/s626api.h $(SRC)/App626.h
        $(CC) $(CFLAGS) -m32 -c $(SRC)/s626dm2b.c -o $@


# for debugging:
#     gcc -g -o s626demo s626core.c s626mod.c s626demo.c -lpthread
#     gcc -g -o s626dm2b s626core.c s626mod.c s626dm2b.c -lpthread

clnall:
        rm -f *.ko *.o .*.cmd .*.o.flags *.mod.c libs626*.a s626demo s626dm2b *.tar.gz s626*-32 Module.symvers modules.order


###############################################################################
# for internal develoment only
#----------------------------------------------------------------
# select files for the distribution tarball
T =  $(SRC)/README
T += $(SRC)/COPYING
T += $(SRC)/MAKEDEV
T += $(SRC)/Modules.conf
T += $(SRC)/Makefile
T += $(SRC)/s626drv.h
T += $(SRC)/s626drv.c
T += $(SRC)/s626.h
T += $(SRC)/s626mod.h
T += $(SRC)/s626mod.c
T += $(SRC)/s626core.h
T += $(SRC)/s626core.c
T += $(SRC)/s626api.h
T += $(SRC)/App626.h
T += $(SRC)/libs626.a
T += $(SRC)/s626demo.c
T += $(SRC)/s626dm2b.c

#----------------------------------------------------------------
# build distribution tarball (only for development)
tar:
#       tar -Pzcf s626-0.3.tar.gz $(T)
        tar -czvf s626-1.0.tar.gz $(T)

DKMS configuration file:

MAKE="'make' KDIR=/lib/modules/${kernelver}/build"
CLEAN="'make' clean"
BUILT_MODULE_NAME=s626
BUILT_MODULE_LOCATION=./
DEST_MODULE_LOCATION=/kernel/drivers/sensoray/
PACKAGE_NAME=s626
PACKAGE_VERSION=1.0.5
AUTOINSTALL=yes
REMAKE_INITRD=yes
9
  • 1
    Is gcc-11 set as the default on your system (i.e. does gcc --version show 11.x or 12.x)? My guess is that some step in the build is using gcc-11 (which lacks the -ftrivial-auto-var-init option) rather than gcc-12 Jan 12 at 23:17
  • ... perhaps related to this bug More dkms fixes for exact cc compiler in which some dkms modules apparently don't honor a CC environment variable Jan 13 at 0:01
  • Looks like the output of gcc --version is gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0. So my default is 11. How do I change that? Is it possible to temporarily make that change only during the dmks build, in case switching from 11 to 12 has other ramifications? Jan 13 at 16:09
  • I added the makefile and the DKMS config file since it appears these will probably be relevant. Jan 13 at 16:41
  • I have pretty much zero experience with dkms, but as a first step you could try adding CC=gcc-12 or CC=/usr/bin/gcc-12 to the conf file. If that fails, then you could (at least temporarily) symlink /usr/bin/gcc to gcc-12 either via the update-alternatives mechanism or (as a last resort) manually. Jan 13 at 17:09

4 Answers 4

3

Same problem. My system is Ubuntu 23.10 and the default gcc/g++ version is 13. During CUDA 11.8 installation, I switched to gcc/g++ version 11.

I used update-alternatives to install the version options.

Switching back to gcc-13 and g++-13 solved this problem.

1

It appears that the problem is that the Makefile (which was written by the original developers) sets the CC make variable, thus preventing DKMS from properly overriding the compiler using a CC environment variable. This potential problem is described by this bug report.

Since in my case the Makefile only uses the CC make variable for building a user-level API library (i.e. it is not used in the portion of the Makefile used for building the module), the best solution was to install (into /usr/src/) a copy of the Makefile that only contains that portion dealing with the kernel module instead of installing the full Makefile.

1
  • This problem never arose before because the default GCC version has always been the same version that built the kernel in my past experience with this module. Therefore, it was not a problem that the CC environment variable was being ignored since the CC variable in the Makefile was being set to the same value anyway. Jan 18 at 21:27
1

I changed symlink /usr/bin/gcc to gcc-12 (instead of gcc-11)

and run sudo /sbin/vboxconfig

vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.

(using Ubuntu 22.04.3 LTS, 5.19.17-051917-generic kernel)

0

Kudos to the user harkants @ this Parallels Forum, here is a working solution for this gcc version issue. It changes the links to point them to gcc-12:

cd /usr/bin
sudo ln -sf gcc-12 gcc
sudo ln -sf gcc-ar-12 gcc-ar
sudo ln -sf gcc-nm-12 gcc-nm
sudo ln -sf gcc-ranlib-12 gcc-ranlib

sudo rm /usr/lib/parallels-tools
sudo rm /var/lib/parallel-tools

go to the mount directory cd "/media/YOUR_USER_NAME_HERE/Parallels Tools" or whatever mount directory you have

and finally execute again:

sudo ./install

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .