KBuild 在没有调试标志的情况下编译时失败

KBuild 在没有调试标志的情况下编译时失败

我正在尝试编译一个非常简单的模块,但当我没有添加 -g 标志时,它无法创建 *.ko。这是源代码:

#include <linux/init.h>
#include <linux/module.h>

static int simple_test_init(void){
    printk(KERN_INFO "Hello Kernel!");
    return 0;
}

static void simple_test_exit(void){
    printk(KERN_INFO "Goodbye Kernel!");
}

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple test module");

module_init(simple_test_init);
module_exit(simple_test_exit);

这是 GCC/Makefile。

KBUILD_CFLAGS := -Werror -fcf-protection=branch

obj-m   += test.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

最后是 GCC 的输出。

make -C /lib/modules/5.19.3-arch1-1/build M=/test modules
make[1]: Entering directory '/usr/lib/modules/5.19.3-arch1-1/build'
  CC [M]  /test/test.o
/test/test.o: warning: objtool: folio_flags+0x29: 'naked' return found in RETHUNK build
/test/test.o: warning: objtool: simple_test_init+0x22: 'naked' return found in RETHUNK build
/test/test.o: warning: objtool: simple_test_exit+0x1e: 'naked' return found in RETHUNK build
/test/test.o: warning: objtool: folio_flags+0x29: missing int3 after ret
/test/test.o: warning: objtool: simple_test_init+0x22: missing int3 after ret
/test/test.o: warning: objtool: simple_test_exit+0x1e: missing int3 after ret
  MODPOST /test/Module.symvers
  CC [M]  /test/test.mod.o
  LD [M]  /test/test.ko
  BTF [M] /test/test.ko
pahole: /test/test.ko: No such file or directory
make[3]: *** [scripts/Makefile.modfinal:60: /test/test.ko] Error 1
make[3]: *** Deleting file '/test/test.ko'
make[2]: *** [scripts/Makefile.modpost:134: __modpost] Error 2
make[1]: *** [Makefile:1763: modules] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.19.3-arch1-1/build'
make: *** [Makefile:6: all] Error 2

谢谢。

相关内容