Issue
I am trying to build a single Linux Kernel module from multiple source files. I am using the following Makefile:
obj-m := mymodule.o
mymodule-y := mymodule_a.o mymodule_b.o mymodule_c.o
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
However, even when the build is successful, the output from modinfo isn't as expected. Specifically, the license, author, parameters etc. all have a prefix ("mymodule." in this case):
mymodule.description: mymodule driver
mymodule.author: myname
mymodule.license: GPL
What I expect is:
description: mymodule driver
author: myname
license: GPL
I've noticed that this prefixing issue does not occur when building the module with Kernel version 5.19. However, when building with Kernel version 5.4, the issue does manifest. I've tried several methods (not generating intermediate .o files, adding directly to obj-m etc.), but none have resolved the issue.
Does anyone know why this prefix is being added on specific Kernel versions, and how to prevent this?
Solution
The issue was resolved by adding the -fno-pic
flag to the compiler. This was done by adding EXTRA_CFLAGS+=-fno-pic
to the Makefile.
Position Independent Code (PIC) is typically not needed for kernel modules. Disabling PIC resolved the modinfo prefixing issue I was facing.
Answered By - ysonishi Answer Checked By - Willingham (WPSolving Volunteer)