Re: [PATCH 3/7] kbuild: do not create wrappers for header-test-y

From: Masahiro Yamada
Date: Mon Jul 08 2019 - 21:10:59 EST


On Mon, Jul 1, 2019 at 10:00 AM Masahiro Yamada
<yamada.masahiro@xxxxxxxxxxxxx> wrote:
>
> header-test-y does not work with headers in sub-directories.
>
> For example, you may want to write a Makefile, like this:
>
> include/linux/Kbuild:
>
> header-test-y += mtd/nand.h
>
> This entry will create a wrapper include/linux/mtd/nand.hdrtest.c
> with the following content:
>
> #include "mtd/nand.h"
>
> To make this work, we need to add $(srctree)/include/linux to the
> header search path. It would be tedious to add ccflags-y.
>
> Instead, we could change the *.hdrtest.c rule to wrap:
>
> #include "nand.h"
>
> This works for in-tree build since #include "..." searches in the
> relative path from the header with this directive. For O=... build,
> we need to add $(srctree)/include/linux/mtd to the header search path,
> which will be even more tedious.
>
> After all, I thought it would be handier to compile headers directly
> without creating wrappers.
>
> I added a new build rule to compile %.h into %.h.s
>
> The target is %.h.s instead of %.h.o because it is slightly faster.
> Also, as for GCC, an empty assembly is smaller than an empty object.
>
> I wrote the build rule:
>
> $(CC) $(c_flags) -S -o $@ -x c /dev/null -include $<
>
> instead of:
>
> $(CC) $(c_flags) -S -o $@ -x c $<
>
> Both work fine with GCC, but the latter is bad for Clang.
>
> This comes down to the difference in the -Wunused-function policy.
> GCC does not warn about unused 'static inline' functions at all.
> Clang does not warn about the ones in included headers, but does
> about the ones in the source. So, we should handle headers as
> headers, not as source files.
>
> In fact, this has been hidden since commit abb2ea7dfd82 ("compiler,
> clang: suppress warning for unused static inline functions"), but we
> should not rely on that.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@xxxxxxxxxxxxx>
> Acked-by: Jani Nikula <jani.nikula@xxxxxxxxx>
> Tested-by: Jani Nikula <jani.nikula@xxxxxxxxx>
> ---

To exclude *.h.s from kernel-devel rpm,
I will squash the following change:

diff --git a/scripts/package/mkspec b/scripts/package/mkspec
index 009147d4718e..2d29df4a0a53 100755
--- a/scripts/package/mkspec
+++ b/scripts/package/mkspec
@@ -31,7 +31,7 @@ PROVIDES="$PROVIDES kernel-$KERNELRELEASE"
__KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g")
EXCLUDES="$RCS_TAR_IGNORE --exclude=.tmp_versions --exclude=*vmlinux* \
--exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \
---exclude=.config.old --exclude=.missing-syscalls.d"
+--exclude=.config.old --exclude=.missing-syscalls.d --exclude=*.s"

# We can label the here-doc lines for conditional output to the spec file
#







--
Best Regards
Masahiro Yamada