AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 766795
Accepted
Adam Sperry
Adam Sperry
Asked: 2024-01-13 06:02:12 +0800 CST2024-01-13 06:02:12 +0800 CST 2024-01-13 06:02:12 +0800 CST

构建内核模块时无法识别的命令行选项“-ftrivial-auto-var-init=zero”

  • 772

我对内核模块开发的经验很少。尽管如此,我的任务还是维护 Sensoray 626 DAQ 卡的旧驱动程序。我正在使用一个非常简单的 dkms 设置来构建和安装驱动程序,该驱动程序已经运行良好很长时间了。该驱动程序一直在 Ubuntu 22.04 中工作,直到最近我在内核模块构建过程中遇到了以下错误,并且无法找到解决方案。任何帮助表示赞赏。如果需要其他信息,只需询问,我将使用所需信息更新问题。

注意:我知道 Comedi 有 Sensoray 626 的驱动程序。我不想使用 Comedi 驱动程序。

DKMS 构建日志:

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
  • 发行版:Ubuntu 22.04.3 LTS
  • Linux内核版本:6.5.0-14-generic

输出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(请注意,此 makefile 具有除内核模块之外的其他内容的配方,并且该CC变量不用于构建内核模块):

###############################################################################
# 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配置文件:

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
kernel-modules
  • 2 2 个回答
  • 525 Views

2 个回答

  • Voted
  1. Best Answer
    Adam Sperry
    2024-01-19T05:20:21+08:002024-01-19T05:20:21+08:00

    问题似乎在于 Makefile(由原始开发人员编写)设置了CCmake 变量,从而阻止了 DKMS 使用环境变量正确覆盖编译器CC。此错误报告描述了此潜在问题。

    因为在我的例子中,Makefile 仅使用CCmake 变量来构建用户级 API 库(即,它没有在用于构建模块的 Makefile 部分中使用),所以最好的解决方案是安装(到/usr/src/)一份仅包含处理内核模块的部分的 Makefile,而不是安装完整的 Makefile。

    • 0
  2. Jan Pejša
    2024-01-24T14:56:14+08:002024-01-24T14:56:14+08:00

    我将符号链接更改/usr/bin/gcc为gcc-12(而不是gcc-11)

    并运行sudo /sbin/vboxconfig

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

    (使用 Ubuntu 22.04.3 LTS、5.19.17-051917-通用内核)

    • 0

相关问题

  • 为什么 sys_call_table 是可预测的?

  • 为什么 Udev 为单个 USB 设备加载两个内核模块?

  • 如何解决 Vuurmuur 中的“内核中不支持连接跟踪”?

  • 无法设置内核模块参数

  • 在 Fedora 27 中未检测到 Broadcom 无线

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve