I have a driver for custom hardware, which I rebuild every time the kernel version updates. I have two different Ubuntu 18.04 machines, both of which are running the same version of gcc (gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
). On one machine, the kernel driver builds as normal. On the second machine, which had Ubuntu reinstalled from scratch in Febuary, it fails to build the kernel driver. I can just copy the driver from the first machine to the second machine, and it works. Why can't the second machine build the driver?
Here is the full output of make
on the failing machine
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
Here is the full output of make
on the working machine:
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'
There are many similar questions, but non seem to have a useful answer. The closest is here, but that is about compiling the kernel, not a driver. I have tried adding -fno-pie
flag in the Makefile
though I'm not 100% sure I did it right since I don't really understand how Makefiles work.
What could be different between these two machines to cause the different behavior?