Welcome to the Linux Foundation Forum!

Error building linux kernel module (Invalid module format)

Hello, currently I began learning linux kernel programming and I faced the following problem. After successfully creating and compiling some modules I made a new directory that contained two files, my_module.c (containing just init and exit functions with pr_info) and Makefile. Accidentally on this particular Makefile I didn't put M= before ${PWM} like in the example below.

  1. ...
  2. all:
  3. make -C /lib/modules/$(uname -r)/build ${PWD} modules
  4. ...

Before even realizing, I had tried to build this module as root. Getting the following
result.

  1. make[1]: Entering directory '/usr/src/linux-headers-5.11.0-41-generic'
  2. SYNC include/config/auto.conf.cmd
  3. HOSTCC scripts/basics/fixdep
  4. HOSTCC scripts/kconfig/conf.o
  5. HOSTCC scripts/kconfig/confdata.o
  6. HOSTCC scripts/kconfig/expr.o
  7. LEX scripts/kconfig/lexer.lex.c
  8. YACC scripts/kconfig/parser.tab.[ch]
  9. HOSTCC scripts/kconfig/lexer.lex.o
  10. HOSTCC scripts/kconfig/parser.tab.o
  11. HOSTCC scripts/kconfig/preprocess.o
  12. HOSTCC scripts/kconfig/symbol.o
  13. HOSTCC scripts/kconfig/util.o
  14. HOSTLD scripts/kconfig/cong
  15. make[2]: *** No rule to make target 'arch/x86/tools/relocs_32.c', need by 'arch/x86/tools/relocs_32.o'. Stop.
  16. make[1]: *** [arch/x86/Makefile:211: archscripts] Error 2
  17. make[1]: Leaving directory '/usr/src/linux-headers-5.11.0-41-generic'
  18. make: *** [Makefile:4: all] Error 2

But the actual problem isn't this. After putting M= on the Makefile and trying to build my module again, I cannot insmode it, since if I try to insmod that module I get this error

  1. insmod: ERROR: could not insert module my_module.ko: Invalid module format
  2.  

Moreover, on dmesg I see the following output.

  1. module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1, loc 000000001528b80b, val ffffffffc0797000

Now, none of the previously running modules (that I made) can be build and run. Does anyone know how I could fix this error? Thank you in advance!

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training