Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6fc9fcb authored by Masahiro Yamada's avatar Masahiro Yamada
Browse files

kbuild: compile-test exported headers to ensure they are self-contained

Multiple people have suggested compile-testing UAPI headers to ensure
they can be really included from user-space. "make headers_check" is
obviously not enough to catch bugs, and we often leak unresolved
references to user-space.

Use the new header-test-y syntax to implement it. Please note exported
headers are compile-tested with a completely different set of compiler
flags. The header search path is set to $(objtree)/usr/include since
exported headers should not include unexported ones.

We use -std=gnu89 for the kernel space since the kernel code highly
depends on GNU extensions. On the other hand, UAPI headers should be
written in more standardized C, so they are compiled with -std=c90.
This will emit errors if C++ style comments, the keyword 'inline', etc.
are used. Please use C style comments (/* ... */), '__inline__', etc.
in UAPI headers.

There is additional compiler requirement to enable this test because
many of UAPI headers include <stdlib.h>, <sys/ioctl.h>, <sys/time.h>,
etc. directly or indirectly. You cannot use kernel.org pre-built
toolchains [1] since they lack <stdlib.h>.

I reused CONFIG_CC_CAN_LINK to check the system header availability.
The intention is slightly different, but a compiler that can link
userspace programs provide system headers.

For now, a lot of headers need to be excluded because they cannot
be compiled standalone, but this is a good start point.

[1] https://mirrors.edge.kernel.org/pub/tools/crosstool/index.html



Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent 1a927fd3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1378,7 +1378,7 @@ CLEAN_DIRS += $(MODVERDIR) include/ksym
CLEAN_FILES += modules.builtin.modinfo

# Directories & files removed with 'make mrproper'
MRPROPER_DIRS  += include/config usr/include include/generated          \
MRPROPER_DIRS  += include/config include/generated          \
		  arch/$(SRCARCH)/include/generated .tmp_objdiff
MRPROPER_FILES += .config .config.old .version \
		  Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
+10 −0
Original line number Diff line number Diff line
@@ -108,6 +108,16 @@ config HEADER_TEST
	  If you are a developer or tester and want to ensure the requested
	  headers are self-contained, say Y here. Otherwise, choose N.

config UAPI_HEADER_TEST
	bool "Compile test UAPI headers"
	depends on HEADER_TEST && HEADERS_INSTALL && CC_CAN_LINK
	help
	  Compile test headers exported to user-space to ensure they are
	  self-contained, i.e. compilable as standalone units.

	  If you are a developer or tester and want to ensure the exported
	  headers are self-contained, say Y here. Otherwise, choose N.

config LOCALVERSION
	string "Local version - append to kernel release"
	help
+0 −1
Original line number Diff line number Diff line
@@ -7,4 +7,3 @@ initramfs_data.cpio.gz
initramfs_data.cpio.bz2
initramfs_data.cpio.lzma
initramfs_list
include
+2 −0
Original line number Diff line number Diff line
@@ -56,3 +56,5 @@ $(deps_initramfs): klibcdirs
$(obj)/$(datafile_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
	$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/$(datafile_d_y)
	$(call if_changed,initfs)

subdir-$(CONFIG_UAPI_HEADER_TEST) += include

usr/include/.gitignore

0 → 100644
+3 −0
Original line number Diff line number Diff line
*
!.gitignore
!Makefile
Loading