Prefix getting added to license information during Linux Kernel module build

71 views Asked by At

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?

2

There are 2 answers

1
ysonishi On BEST ANSWER

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.

0
youfu On

I ran into same problem and I tried to figure out the root cause.

#ifdef MODULE
#define MODULE_PARAM_PREFIX /* empty */
#define __MODULE_INFO_PREFIX /* empty */
#else
#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."
#define __MODULE_INFO_PREFIX KBUILD_MODNAME "."
#endif
#define __MODULE_INFO(tag, name, info)                    \
    static const char __UNIQUE_ID(name)[]                 \
        __used __section(".modinfo") __aligned(1)         \
        = __MODULE_INFO_PREFIX __stringify(tag) "=" info

Apparently, when MODULE is not defined, MODULE_INFO would expand to a tag with module name prefix.

By appending V=1 to Makefile, I can observe gcc command lines. My module does not have -DMODULE argument during compilation while a hello-world example do has -DMODULE.

In my case, I set KBUILD_CFLAGS_MODULE=-Ixxxxxx to provide additional include path. The expected usage is CFLAGS_MODULE=xxx. Overrides KBUILD_CFLAGS_MODULE makes -DMODULE lost.