![驱动程序在一台机器上构建,但在另一台机器上不构建:代码模型内核不支持 PIC 模式](https://linux22.com/image/1172789/%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F%E5%9C%A8%E4%B8%80%E5%8F%B0%E6%9C%BA%E5%99%A8%E4%B8%8A%E6%9E%84%E5%BB%BA%EF%BC%8C%E4%BD%86%E5%9C%A8%E5%8F%A6%E4%B8%80%E5%8F%B0%E6%9C%BA%E5%99%A8%E4%B8%8A%E4%B8%8D%E6%9E%84%E5%BB%BA%EF%BC%9A%E4%BB%A3%E7%A0%81%E6%A8%A1%E5%9E%8B%E5%86%85%E6%A0%B8%E4%B8%8D%E6%94%AF%E6%8C%81%20PIC%20%E6%A8%A1%E5%BC%8F.png)
我有一个自定义硬件的驱动程序,每次内核版本更新时我都会重建它。我有两台不同的 Ubuntu 18.04 机器,两台都运行相同版本的 gcc ( gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
)。在一台机器上,内核驱动程序正常构建。在第二台机器上,Ubuntu 在二月份从头开始重新安装,它无法构建内核驱动程序。我只需将驱动程序从第一台机器复制到第二台机器,它就可以正常工作了。为什么第二台机器无法构建驱动程序?
make
这是故障机器的完整输出
make -C /lib/modules/4.15.0-96-generic/build M=/home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-96-generic'
CC [M] /home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero-base.o
cc1: error: code model kernel does not support PIC mode
scripts/Makefile.build:330: recipe for target '/home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero-base.o' failed
make[2]: *** [/home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero-base.o] Error 1
Makefile:1577: recipe for target '_module_/home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver' failed
make[1]: *** [_module_/home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-96-generic'
Makefile:32: recipe for target 'lancero.ko' failed
make: *** [lancero.ko] Error 2
make
以下是工作机器上的完整输出:
make -C /lib/modules/4.15.0-96-generic/build M=/home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-96-generic'
CC [M] /home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero-base.o
CC [M] /home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero-user.o
LD [M] /home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: modpost: Found 1 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
CC /home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero.mod.o
LD [M] /home/pcuser/drivers/lancero/Lancero-RELEASE/C/driver/lancero.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-96-generic'
有很多类似的问题,但似乎没有一个有用的答案。最接近的是这里,但这是关于编译内核,而不是驱动程序。我尝试-fno-pie
在其中添加标志Makefile
,但我不能 100% 确定我做对了,因为我不太了解 Makefile 的工作原理。
这两台机器之间有什么不同,导致了不同的行为?