compiler-errorslinux-kernelkernel-module

How to solve "objtool error" when compiling kernel module?


I tried to compile a kernel module with the following script:

obj-m :=rwsem_bench.o 
all:
    make -C /lib/modules/$(shell uname -r)/build SUBDIRS=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build SUBDIRS=$(PWD) clean 

I have succeeded in compiling and insmod the same module on Kernel-4.18 and GCC-4.8.5.

However, when I switch to Kernel-5.14 and GCC-8.3.1, it failed with the following message:

make -C /lib/modules/5.14.0.xxxx.x86_64/build SUBDIRS=/home/sre/rwsem modules
make[1]: Entering directory `/usr/src/kernels/5.14.0.xxxx.x86_64'
scripts/Makefile.build:481: warning: overriding recipe for target `modules.order'
Makefile:1506: warning: ignoring old recipe for target `modules.order'
  DESCEND objtool
make[4]: *** [/usr/src/kernels/5.14.0.xxxx.x86_64/tools/objtool/objtool-in.o] 
Error 1
make[3]: *** [objtool] Error 2
make[2]: *** [tools/objtool] Error 2
make[1]: *** [__sub-make] Error 2
make[1]: Leaving directory `/usr/src/kernels/5.14.0.xxxx.x86_64'
make: *** [all] Error 2

I don't know what does it mean or how to solve it.


Solution

  • Replace SUBDIRS=$(PWD) with M=$(PWD)

    obj-m :=rwsem_bench.o 
    all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    

    Take it from The Linux Kernel Module Programming Guide.