【问题标题】:Makefile ignoring '-isystem' flag when compiling kernel module编译内核模块时Makefile忽略'-isystem'标志
【发布时间】:2017-02-10 23:20:11
【问题描述】:

我正在用 C 语言编写一个基本的内核模块来在虚拟机上进行实验。目前我所有的代码都运行良好,但是在编译时我也收到了来自内核头文件的警告,这让我发现很难看到我自己可能不小心忽略的任何错误。

我找到了关于如何禁用来自外部库的警告的答案here,我需要使用 GCC -isystem {dir} 标志,但这似乎不起作用。有人可以指出我做错了什么吗?这是我当前的 Makefile:

obj-m += module.o
module-objs := \
    src/main.o \
    src/logger.o

EXTRA_CFLAGS += -fno-stack-protector
EXTRA_CFLAGS += -fno-pie
EXTRA_CFLAGS += -isystem /usr/src/kernels/*  # This doesn't seem to work, I still end up getting warnings

all:
    make -C /lib/modules/{my kernel}/build M=$(PWD) modules
clean:
    make -C /lib/modules/{my kernel}/build M=$(PWD) clean

我收到的警告示例:

make -C /lib/modules/{my kernel}/build M=/root/Documents/Projects/TestKernelMod modules
make[1]: Entering directory '/usr/src/kernels/{my kernel}'
/usr/src/kernels/{my kernel}/arch/x86/Makefile:81: stack protector enabled but no compiler support
  CC [M]  /root/Documents/Projects/TestKernelMod/src/main.o
In file included from /usr/src/kernels/{my kernel}/arch/x86/include/asm/smp.h:13:0,
                 from /usr/src/kernels/{my kernel}/arch/x86/include/asm/mmzone_64.h:12,
                 from /usr/src/kernels/{my kernel}/arch/x86/include/asm/mmzone.h:4,
                 from include/linux/mmzone.h:850,
                 from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /root/Documents/Projects/TestKernelMod/src/main.c:2:
/usr/src/kernels/{my kernel}/arch/x86/include/asm/apic.h: In function ‘native_apic_msr_read’:
/usr/src/kernels/{my kernel}/arch/x86/include/asm/apic.h:150:11: warning: variable ‘high’ set but not used [-Wunused-but-set-variable]
  u32 low, high;
           ^~~~
/usr/src/kernels/{my kernel}/arch/x86/include/asm/apic.h: In function ‘x2apic_enabled’:
/usr/src/kernels/{my kernel}/arch/x86/include/asm/apic.h:190:11: warning: variable ‘msr2’ set but not used [-Wunused-but-set-variable]
  int msr, msr2;
           ^~~~

【问题讨论】:

  • 如果你明确地做-isystem /usr/src/kernels/{my kernel}/arch/x86/include/asm/apic.h 你会摆脱以前的警告吗?

标签: c gcc makefile


【解决方案1】:

在 make 命令行中添加 V=1 以查看正在执行的实际命令。

您会发现 make 不会为您扩展通配符。您给出的带有文字* 的路径并不指向任何真实目录。请参阅使用$(wildcard) 进行扩展或放入正确的路径。

【讨论】:

  • isystem 标志更改为 -isystem /usr/src/kernels/{my kernel}/arch/x86/include/ 成功了,谢谢 :)
猜你喜欢
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 2019-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-12
  • 1970-01-01
相关资源
最近更新 更多