1

I'm writing a basic kernel module in C to experiment on a virtual machine. Currently all my code runs fine, however upon compiling I'm also receiving warnings from the kernel header files which lead me to find it really hard to see any of my own errors I might accidentally overlook.

I found an answer here on how to disable warnings from external libraries, which state I need to use the GCC -isystem {dir} flag, however this doesn't seem to work. Could someone point out what I'm doing wrong? This is my current 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

Examples of the warnings I get:

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;
           ^~~~
Community
  • 1
  • 1
Paradoxis
  • 4,471
  • 7
  • 32
  • 66
  • If you explicitly do `-isystem /usr/src/kernels/{my kernel}/arch/x86/include/asm/apic.h` do you get rid of the previous warnings? – fedepad Feb 10 '17 at 23:48

1 Answers1

1

Add V=1 to the make command line to see the actual commands being executed.

You'll find the make does not expand the wildcard for you. The path you've given, with a literal *, doesn't point to any real directory. See using $(wildcard) to have make expand or put in the correct path.

TrentP
  • 4,240
  • 24
  • 35
  • Changing the `isystem` flag to `-isystem /usr/src/kernels/{my kernel}/arch/x86/include/` did the trick, thank you :) – Paradoxis Feb 11 '17 at 12:30