Skip to content

Commit

Permalink
Adjust the order of linux kernel header include paths
Browse files Browse the repository at this point in the history
The current order of include paths could cause the following error:

In file included from /virtual/main.c:3:
In file included from include/linux/sched.h:13:
In file included from include/linux/pid.h:4:
In file included from include/linux/rculist.h:10:
In file included from include/linux/rcupdate.h:38:
In file included from include/linux/spinlock.h:50:
In file included from include/linux/preempt.h:80:
In file included from /lib/modules/4.12.14-197.45-default/build/arch/s390/include/generated/asm/preempt.h:1:
include/asm-generic/preempt.h:10:42: error: no member named 'preempt_count' in 'struct thread_info'
        return READ_ONCE(current_thread_info()->preempt_count);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
include/linux/compiler.h:349:34: note: expanded from macro 'READ_ONCE'
                     ~~~~~~~~~~~~^~~~~
include/linux/compiler.h:342:17: note: expanded from macro '__READ_ONCE'
        union { typeof(x) __val; char __c[1]; } __u;
\
...
7 errors generated.

It's supposed to load "asm/preempt.h" from "source/"(*) but accidentally
loaded the one from "build/", so the error showed.
(x86_64 didn't suffer this error because it didn't install the extra
 "asm/preempt.h" to "build/".)

For the distros, e.g. SUSE/openSUSE and debian,  with separate "build/"
and "source/", all those "generated/" paths only exist in "build/". To
avoid the potential compilation issue, this commit adjusts the include
order for those with split headers to align the include order from
kernel top Makefile.

(*) /lib/modules/4.12.14-197.45-default/source/arch/s390/include/

Signed-off-by: Gary Lin <[email protected]>
  • Loading branch information
lcp authored and yonghong-song committed Jul 21, 2020
1 parent 222821c commit c31e9d6
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/cc/frontends/clang/kbuild_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,47 @@ int KBuildHelper::get_flags(const char *uname_machine, vector<string> *cflags) {
cflags->push_back("-isystem");
cflags->push_back("/virtual/lib/clang/include");

// some module build directories split headers between source/ and build/
// The include order from kernel top Makefile:
//
// # Use USERINCLUDE when you must reference the UAPI directories only.
// USERINCLUDE := \
// -I$(srctree)/arch/$(SRCARCH)/include/uapi \
// -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
// -I$(srctree)/include/uapi \
// -I$(objtree)/include/generated/uapi \
// -include $(srctree)/include/linux/kconfig.h
//
// # Use LINUXINCLUDE when you must reference the include/ directory.
// # Needed to be compatible with the O= option
// LINUXINCLUDE := \
// -I$(srctree)/arch/$(SRCARCH)/include \
// -I$(objtree)/arch/$(SRCARCH)/include/generated \
// $(if $(building_out_of_srctree),-I$(srctree)/include) \
// -I$(objtree)/include \
// $(USERINCLUDE)
//
// Some distros such as openSUSE/SUSE and Debian splits the headers between
// source/ and build/. In this case, just $(srctree) is source/ and
// $(objtree) is build/.
if (has_source_dir_) {
cflags->push_back("-I" + kdir_ + "/build/arch/"+arch+"/include");
cflags->push_back("-I" + kdir_ + "/build/arch/"+arch+"/include/generated/uapi");
cflags->push_back("-Iarch/"+arch+"/include/");
cflags->push_back("-I" + kdir_ + "/build/arch/"+arch+"/include/generated");
cflags->push_back("-Iinclude");
cflags->push_back("-I" + kdir_ + "/build/include");
cflags->push_back("-I" + kdir_ + "/build/./arch/"+arch+"/include/uapi");
cflags->push_back("-Iarch/"+arch+"/include/uapi");
cflags->push_back("-I" + kdir_ + "/build/arch/"+arch+"/include/generated/uapi");
cflags->push_back("-I" + kdir_ + "/build/include/uapi");
cflags->push_back("-I" + kdir_ + "/build/include/generated");
cflags->push_back("-Iinclude/uapi");
cflags->push_back("-I" + kdir_ + "/build/include/generated/uapi");
} else {
cflags->push_back("-Iarch/"+arch+"/include/");
cflags->push_back("-Iarch/"+arch+"/include/generated");
cflags->push_back("-Iinclude");
cflags->push_back("-Iarch/"+arch+"/include/uapi");
cflags->push_back("-Iarch/"+arch+"/include/generated/uapi");
cflags->push_back("-Iinclude/uapi");
cflags->push_back("-Iinclude/generated/uapi");
}

cflags->push_back("-I./arch/"+arch+"/include");
cflags->push_back("-Iarch/"+arch+"/include/generated/uapi");
cflags->push_back("-Iarch/"+arch+"/include/generated");
cflags->push_back("-Iinclude");
cflags->push_back("-I./arch/"+arch+"/include/uapi");
cflags->push_back("-Iarch/"+arch+"/include/generated/uapi");
cflags->push_back("-I./include/uapi");
cflags->push_back("-Iinclude/generated/uapi");
cflags->push_back("-include");
cflags->push_back("./include/linux/kconfig.h");
cflags->push_back("-D__KERNEL__");
Expand Down

0 comments on commit c31e9d6

Please sign in to comment.