So, I am writing a module, that is working in kernel space. My code compiles correctly and works correctly.

The thing is that there are some header files, which I couldn't find anywhere. That doesn't make sense to me, how come everything goes right when header files are not present. They must be present somewhere.

These are some of header files I couldn't find anywhere (there are more, but for my question, they may be enough):

#include <asm/errno.h>
#include <asm/socket.h>  /* /include/linux/socket.h */
#include <stdarg.h>      /* /include/linux/kernel.h */
#include <asm/types.h>
#include <asm/mmiowb.h>  /* /include/linux/spinlock.h */
#include <asm/param.h>   /* /include/linux/jiffies.h */

Though some of header files can be found on architectures other than x86, but I don't think that's any solution to the question.

And I don't have any idea where to look for these files:

#include <generated/timeconst.h>    /* /include/linux/jiffies.h */
#include <generated/bounds.h>
#include <generated/autoconf.h>     /* /include/linux/kconfig.h */
#include <generated/asm-offsets.h>

I am looking for these files in the following directories from linux kernel 5.4.31:


I expect the files to be found in the above include paths. But I don't know much about where and how linux header files are processed after compilation, since I'm finding for them in the source code.

  • What command do you use to compile your module? After you have compiled your module can you run grep asm/errno.h $(find , -name \*.d) to locate your first include file using the information the compiler has written? – icarus May 9 '20 at 4:27
  • @icarus I am using make -C /lib/modules/`uname -r`/build M=`pwd` to build the module. Though, I am not understanding the command you're saying, it just runs with a line printing find ',': No such file or directory and doesn't exit. – Akshdeep Singh May 9 '20 at 4:45
  • @icarus you can try to run this make command in /net/wireless/ directory. It has a file nl80211.c (which has a header file #include <linux/err.h>) which I am using as a reference to write my code. – Akshdeep Singh May 9 '20 at 4:52
  • Sorry, typo, grep linux/err.h $(find . -name \*.d) The idea is that after you have done the build in addition to the ".ko" file you will have one or more ".o" object files and also one or more ".d" files. The latter are Makefile fragments listing dependencies. – icarus May 9 '20 at 7:12
  • @icarus There is no .d file in my directory after the build, all I have are .ko, .o, .mod.c, .mod.o, modules.order, Module.symvers, files other than .c and .h files. – Akshdeep Singh May 9 '20 at 11:08

You’ll find the header files used by your build in /lib/modules/$(uname -r)/build/, see for example

find /lib/modules/$(uname -r)/build/ -name timeconst.h

All these files are generated during the build, in various ways; timeconst.h is built by kernel/time/timeconst.bc.

/lib/modules/$(uname -r)/build/ stores the generated headers (and a few other files) corresponding to the running kernel; the intention is to make them available for external module builds in particular. If you’re building a new kernel, you’ll find the generated files in your build tree (after a kernel build, or an in-tree-module build).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.