* [PATCH v2 0/4] Compile-test UAPI and kernel headers
@ 2019-06-27 1:46 Masahiro Yamada
2019-06-27 1:46 ` [PATCH v2 2/4] kbuild: do not create wrappers for header-test-y Masahiro Yamada
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Masahiro Yamada @ 2019-06-27 1:46 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Masahiro Yamada, Tony Luck, linux-doc,
John Fastabend, Jonathan Corbet, Jakub Kicinski, linux-riscv,
Daniel Borkmann, xdp-newbies, Anton Vorontsov, Palmer Dabbelt,
Matthias Brugger, Song Liu, Yonghong Song, Michal Marek,
Jesper Dangaard Brouer, Martin KaFai Lau, linux-mediatek,
linux-arm-kernel, Albert Ou, Colin Cross, David S. Miller,
Kees Cook, Alexei Starovoitov, netdev, linux-kernel, bpf
1/4: reworked v2.
2/4: fix a flaw I noticed when I was working on this series
3/4: maybe useful for 4/4 and in some other places
4/4: v2. compile as many headers as possible.
Changes in v2:
- Add CONFIG_CPU_{BIG,LITTLE}_ENDIAN guard to avoid build error
- Use 'header-test-' instead of 'no-header-test'
- Avoid weird 'find' warning when cleaning
- New patch
- New patch
- Add everything to test coverage, and exclude broken ones
- Rename 'Makefile' to 'Kbuild'
- Add CONFIG_KERNEL_HEADER_TEST option
Masahiro Yamada (4):
kbuild: compile-test UAPI headers to ensure they are self-contained
kbuild: do not create wrappers for header-test-y
kbuild: support header-test-pattern-y
kbuild: compile-test kernel headers to ensure they are self-contained
.gitignore | 1 -
Documentation/dontdiff | 1 -
Documentation/kbuild/makefiles.txt | 13 +-
Makefile | 4 +-
include/Kbuild | 1134 ++++++++++++++++++++++++++++
init/Kconfig | 22 +
scripts/Makefile.build | 10 +-
scripts/Makefile.lib | 12 +-
scripts/cc-system-headers.sh | 8 +
usr/.gitignore | 1 -
usr/Makefile | 2 +
usr/include/.gitignore | 3 +
usr/include/Makefile | 133 ++++
13 files changed, 1331 insertions(+), 13 deletions(-)
create mode 100644 include/Kbuild
create mode 100755 scripts/cc-system-headers.sh
create mode 100644 usr/include/.gitignore
create mode 100644 usr/include/Makefile
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/4] kbuild: do not create wrappers for header-test-y
2019-06-27 1:46 [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
@ 2019-06-27 1:46 ` Masahiro Yamada
2019-06-27 11:25 ` Jani Nikula
2019-06-27 1:46 ` [PATCH v2 3/4] kbuild: support header-test-pattern-y Masahiro Yamada
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Masahiro Yamada @ 2019-06-27 1:46 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Masahiro Yamada, linux-doc, Jonathan Corbet,
linux-kernel, Michal Marek
header-test-y does not work with headers in sub-directories.
For example, you can write a Makefile, like this:
include/linux/Kbuild:
header-test-y += mtd/nand.h
This entry creates 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.
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
I chose %.h.s instead of %.h.o because it was a little bit faster.
Also, 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 not good 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@socionext.com>
---
Changes in v2:
- New patch
.gitignore | 1 -
Documentation/dontdiff | 1 -
Documentation/kbuild/makefiles.txt | 3 +--
Makefile | 1 -
scripts/Makefile.build | 10 +++++-----
scripts/Makefile.lib | 2 +-
6 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/.gitignore b/.gitignore
index 4bb60f0fa23b..7587ef56b92d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,7 +22,6 @@
*.elf
*.gcno
*.gz
-*.hdrtest.c
*.i
*.ko
*.lex.c
diff --git a/Documentation/dontdiff b/Documentation/dontdiff
index 554dfe4883d2..5eba889ea84d 100644
--- a/Documentation/dontdiff
+++ b/Documentation/dontdiff
@@ -19,7 +19,6 @@
*.grep
*.grp
*.gz
-*.hdrtest.c
*.html
*.i
*.jpeg
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index ca4b24ec0399..5080fec34609 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1023,8 +1023,7 @@ When kbuild executes, the following steps are followed (roughly):
header-test-y specifies headers (*.h) in the current directory that
should be compile tested to ensure they are self-contained,
i.e. compilable as standalone units. If CONFIG_HEADER_TEST is enabled,
- this autogenerates dummy sources to include the headers, and builds them
- as part of extra-y.
+ this builds them as part of extra-y.
--- 6.7 Commands useful for building a boot image
diff --git a/Makefile b/Makefile
index f23516980796..7f293b0431fe 100644
--- a/Makefile
+++ b/Makefile
@@ -1648,7 +1648,6 @@ clean: $(clean-dirs)
-o -name '*.dwo' -o -name '*.lst' \
-o -name '*.su' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
- -o -name '*.hdrtest.c' \
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
-o -name '*.asn1.[ch]' \
-o -name '*.symtypes' -o -name 'modules.order' \
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index ee0319560513..776842b7e6a3 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -294,14 +294,14 @@ quiet_cmd_cc_lst_c = MKLST $@
$(obj)/%.lst: $(src)/%.c FORCE
$(call if_changed_dep,cc_lst_c)
-# Dummy C sources for header test (header-test-y target)
+# header test (header-test-y target)
# ---------------------------------------------------------------------------
-quiet_cmd_header_test = HDRTEST $@
- cmd_header_test = echo "\#include \"$*.h\"" > $@
+quiet_cmd_cc_s_h = CC $@
+ cmd_cc_s_h = $(CC) $(c_flags) -S -o $@ -x c /dev/null -include $<
-$(obj)/%.hdrtest.c:
- $(call cmd,header_test)
+$(obj)/%.h.s: $(src)/%.h FORCE
+ $(call if_changed_dep,cc_s_h)
# Compile assembler sources (.S)
# ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 3e630fcaffd1..55ae1ec65342 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -67,7 +67,7 @@ extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
endif
# Test self-contained headers
-extra-$(CONFIG_HEADER_TEST) += $(patsubst %.h,%.hdrtest.o,$(header-test-y))
+extra-$(CONFIG_HEADER_TEST) += $(addsuffix .s, $(header-test-y))
# Add subdir path
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/4] kbuild: support header-test-pattern-y
2019-06-27 1:46 [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
2019-06-27 1:46 ` [PATCH v2 2/4] kbuild: do not create wrappers for header-test-y Masahiro Yamada
@ 2019-06-27 1:46 ` Masahiro Yamada
2019-06-27 11:28 ` Jani Nikula
2019-06-27 3:12 ` [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
2019-06-27 11:39 ` Jani Nikula
3 siblings, 1 reply; 8+ messages in thread
From: Masahiro Yamada @ 2019-06-27 1:46 UTC (permalink / raw)
To: linux-kbuild
Cc: Sam Ravnborg, Masahiro Yamada, linux-doc, linux-kernel,
Jonathan Corbet, Michal Marek
In my view, most of headers can be self-contained. So, it would be
tedious to add every header to header-test-y explicitly. We usually
end up with "all headers with some exceptions".
There are two types in exceptions:
[1] headers that are never compiled as standalone units
For examples, include/linux/compiler-gcc.h is not intended to be
included directly. We should always exclude such ones.
[2] headers that are conditionally compiled as standalone units
Some headers can be compiled only for particular architectures.
For example, include/linux/arm-cci.h can be compiled only for
arm/arm64 because it requires <asm/arm-cci.h> to exist.
Clang can compile include/soc/nps/mtm.h only for arc because
it contains an arch-specific register in inline assembler.
For [2], we can write Makefile like this:
header-test-$(CONFIG_ARM) += linux/arm-cci.h
The new syntax header-test-pattern-y will be useful to specify
"the rest".
The typical usage is like this:
header-test-pattern-y += */*.h
This adds all the headers in sub-directories to the test coverage,
but headers added to header-test- are excluded. In this regards,
header-test-pattern-y behaves like a weaker variant of header-test-y.
Caveat:
The patterns in header-test-pattern-y are prefixed with $(srctree)/$(src)/
but not $(objtree)/$(obj)/. Stale generated patterns are often left over.
For example, you will have ones when you traverse the git history for
'git bisect' without cleaning. If a wildcard is used for generated
headers, it may match to stale headers.
If you really want to compile-test generated headers, I recommend to
add them to header-test-y explicitly. One pitfall is $(srctree)/$(src)/
and $(objtree)/$(obj)/ point to the same directory for in-tree building.
So, header-test-pattern-y should be used with care. It can potentially
match to generated headers, which may be stale and fail to compile.
Caveat2:
You could use wildcard for header-test-. For example,
header-test- += asm-generic/%
... will exclude headers in asm-generic directory. Unfortunately, the
wildcard character is '%' instead of '*' because this is evaluated by
$(filter-out ...) whereas header-test-pattern-y is evaluated by
$(wildcard ...). This is a kludge, but seems useful in some places...
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
Changes in v2:
- New patch
Documentation/kbuild/makefiles.txt | 10 ++++++++++
scripts/Makefile.lib | 10 ++++++++++
2 files changed, 20 insertions(+)
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 5080fec34609..b817e6cefb77 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1025,6 +1025,16 @@ When kbuild executes, the following steps are followed (roughly):
i.e. compilable as standalone units. If CONFIG_HEADER_TEST is enabled,
this builds them as part of extra-y.
+ header-test-pattern-y
+
+ This works as a weaker version of header-test-y, and accepts wildcard
+ patterns. The typical usage is:
+
+ header-test-pattern-y += *.h
+
+ This specifies all the files that matches to '*.h' in the current
+ directory, but the files in 'header-test-' are excluded.
+
--- 6.7 Commands useful for building a boot image
Kbuild provides a few macros that are useful when building a
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 55ae1ec65342..54444933bbab 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -67,6 +67,16 @@ extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
endif
# Test self-contained headers
+
+# Wildcard searches in $(srctree)/$(src)/, but not in $(objtree)/$(obj)/.
+# Stale generated headers are often left over, so wildcard matching should
+# be avoided. Please notice $(srctree)/$(src)/ and $(objtree)/$(obj) point
+# to the same location for in-tree building.
+header-test-y += $(filter-out $(header-test-), \
+ $(patsubst $(srctree)/$(src)/%, %, \
+ $(wildcard $(addprefix $(srctree)/$(src)/, \
+ $(header-test-pattern-y)))))
+
extra-$(CONFIG_HEADER_TEST) += $(addsuffix .s, $(header-test-y))
# Add subdir path
--
2.17.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/4] Compile-test UAPI and kernel headers
2019-06-27 1:46 [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
2019-06-27 1:46 ` [PATCH v2 2/4] kbuild: do not create wrappers for header-test-y Masahiro Yamada
2019-06-27 1:46 ` [PATCH v2 3/4] kbuild: support header-test-pattern-y Masahiro Yamada
@ 2019-06-27 3:12 ` Masahiro Yamada
2019-06-27 11:39 ` Jani Nikula
3 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2019-06-27 3:12 UTC (permalink / raw)
To: Linux Kbuild mailing list
Cc: Sam Ravnborg, Tony Luck, open list:DOCUMENTATION, John Fastabend,
Jonathan Corbet, Jakub Kicinski, linux-riscv, Daniel Borkmann,
xdp-newbies, Anton Vorontsov, Palmer Dabbelt, Matthias Brugger,
Song Liu, Yonghong Song, Michal Marek, Jesper Dangaard Brouer,
Martin KaFai Lau, moderated list:ARM/Mediatek SoC support,
linux-arm-kernel, Albert Ou, Colin Cross, David S. Miller,
Kees Cook, Alexei Starovoitov, Networking,
Linux Kernel Mailing List, bpf
On Thu, Jun 27, 2019 at 10:49 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
>
> 1/4: reworked v2.
>
> 2/4: fix a flaw I noticed when I was working on this series
>
> 3/4: maybe useful for 4/4 and in some other places
>
> 4/4: v2. compile as many headers as possible.
>
If you want to test this series,
please check:
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git
header-test-v2
> Changes in v2:
> - Add CONFIG_CPU_{BIG,LITTLE}_ENDIAN guard to avoid build error
> - Use 'header-test-' instead of 'no-header-test'
> - Avoid weird 'find' warning when cleaning
> - New patch
> - New patch
> - Add everything to test coverage, and exclude broken ones
> - Rename 'Makefile' to 'Kbuild'
> - Add CONFIG_KERNEL_HEADER_TEST option
>
> Masahiro Yamada (4):
> kbuild: compile-test UAPI headers to ensure they are self-contained
> kbuild: do not create wrappers for header-test-y
> kbuild: support header-test-pattern-y
> kbuild: compile-test kernel headers to ensure they are self-contained
>
> .gitignore | 1 -
> Documentation/dontdiff | 1 -
> Documentation/kbuild/makefiles.txt | 13 +-
> Makefile | 4 +-
> include/Kbuild | 1134 ++++++++++++++++++++++++++++
> init/Kconfig | 22 +
> scripts/Makefile.build | 10 +-
> scripts/Makefile.lib | 12 +-
> scripts/cc-system-headers.sh | 8 +
> usr/.gitignore | 1 -
> usr/Makefile | 2 +
> usr/include/.gitignore | 3 +
> usr/include/Makefile | 133 ++++
> 13 files changed, 1331 insertions(+), 13 deletions(-)
> create mode 100644 include/Kbuild
> create mode 100755 scripts/cc-system-headers.sh
> create mode 100644 usr/include/.gitignore
> create mode 100644 usr/include/Makefile
>
> --
> 2.17.1
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/4] kbuild: do not create wrappers for header-test-y
2019-06-27 1:46 ` [PATCH v2 2/4] kbuild: do not create wrappers for header-test-y Masahiro Yamada
@ 2019-06-27 11:25 ` Jani Nikula
0 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2019-06-27 11:25 UTC (permalink / raw)
To: Masahiro Yamada, linux-kbuild
Cc: Sam Ravnborg, Masahiro Yamada, linux-doc, Jonathan Corbet,
linux-kernel, Michal Marek
On Thu, 27 Jun 2019, Masahiro Yamada <yamada.masahiro@socionext.com> wrote:
> header-test-y does not work with headers in sub-directories.
>
> For example, you can write a Makefile, like this:
>
> include/linux/Kbuild:
>
> header-test-y += mtd/nand.h
>
> This entry creates 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.
>
> 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
>
> I chose %.h.s instead of %.h.o because it was a little bit faster.
> Also, 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 not good 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@socionext.com>
> ---
>
> Changes in v2:
> - New patch
>
> .gitignore | 1 -
> Documentation/dontdiff | 1 -
> Documentation/kbuild/makefiles.txt | 3 +--
> Makefile | 1 -
> scripts/Makefile.build | 10 +++++-----
> scripts/Makefile.lib | 2 +-
> 6 files changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index 4bb60f0fa23b..7587ef56b92d 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -22,7 +22,6 @@
> *.elf
> *.gcno
> *.gz
> -*.hdrtest.c
> *.i
> *.ko
> *.lex.c
> diff --git a/Documentation/dontdiff b/Documentation/dontdiff
> index 554dfe4883d2..5eba889ea84d 100644
> --- a/Documentation/dontdiff
> +++ b/Documentation/dontdiff
> @@ -19,7 +19,6 @@
> *.grep
> *.grp
> *.gz
> -*.hdrtest.c
> *.html
> *.i
> *.jpeg
> diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
> index ca4b24ec0399..5080fec34609 100644
> --- a/Documentation/kbuild/makefiles.txt
> +++ b/Documentation/kbuild/makefiles.txt
> @@ -1023,8 +1023,7 @@ When kbuild executes, the following steps are followed (roughly):
> header-test-y specifies headers (*.h) in the current directory that
> should be compile tested to ensure they are self-contained,
> i.e. compilable as standalone units. If CONFIG_HEADER_TEST is enabled,
> - this autogenerates dummy sources to include the headers, and builds them
> - as part of extra-y.
> + this builds them as part of extra-y.
>
> --- 6.7 Commands useful for building a boot image
>
> diff --git a/Makefile b/Makefile
> index f23516980796..7f293b0431fe 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1648,7 +1648,6 @@ clean: $(clean-dirs)
> -o -name '*.dwo' -o -name '*.lst' \
> -o -name '*.su' \
> -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
> - -o -name '*.hdrtest.c' \
> -o -name '*.lex.c' -o -name '*.tab.[ch]' \
> -o -name '*.asn1.[ch]' \
> -o -name '*.symtypes' -o -name 'modules.order' \
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index ee0319560513..776842b7e6a3 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -294,14 +294,14 @@ quiet_cmd_cc_lst_c = MKLST $@
> $(obj)/%.lst: $(src)/%.c FORCE
> $(call if_changed_dep,cc_lst_c)
>
> -# Dummy C sources for header test (header-test-y target)
> +# header test (header-test-y target)
> # ---------------------------------------------------------------------------
>
> -quiet_cmd_header_test = HDRTEST $@
> - cmd_header_test = echo "\#include \"$*.h\"" > $@
> +quiet_cmd_cc_s_h = CC $@
> + cmd_cc_s_h = $(CC) $(c_flags) -S -o $@ -x c /dev/null -include $<
I think I'd prefer HDRTEST or something more informative than just CC in
the quiet cmd to distinguish this from the usual build lines. Especially
now that the file name is also just .h.s.
Other than that, good job getting rid of the intermediate file. I
couldn't figure it out when I did the original.
Acked-by: Jani Nikula <jani.nikula@intel.com>
Tested-by: Jani Nikula <jani.nikula@intel.com>
>
> -$(obj)/%.hdrtest.c:
> - $(call cmd,header_test)
> +$(obj)/%.h.s: $(src)/%.h FORCE
> + $(call if_changed_dep,cc_s_h)
>
> # Compile assembler sources (.S)
> # ---------------------------------------------------------------------------
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 3e630fcaffd1..55ae1ec65342 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -67,7 +67,7 @@ extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
> endif
>
> # Test self-contained headers
> -extra-$(CONFIG_HEADER_TEST) += $(patsubst %.h,%.hdrtest.o,$(header-test-y))
> +extra-$(CONFIG_HEADER_TEST) += $(addsuffix .s, $(header-test-y))
>
> # Add subdir path
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 3/4] kbuild: support header-test-pattern-y
2019-06-27 1:46 ` [PATCH v2 3/4] kbuild: support header-test-pattern-y Masahiro Yamada
@ 2019-06-27 11:28 ` Jani Nikula
0 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2019-06-27 11:28 UTC (permalink / raw)
To: Masahiro Yamada, linux-kbuild
Cc: Sam Ravnborg, Masahiro Yamada, linux-doc, linux-kernel,
Jonathan Corbet, Michal Marek
On Thu, 27 Jun 2019, Masahiro Yamada <yamada.masahiro@socionext.com> wrote:
> In my view, most of headers can be self-contained. So, it would be
> tedious to add every header to header-test-y explicitly. We usually
> end up with "all headers with some exceptions".
>
> There are two types in exceptions:
>
> [1] headers that are never compiled as standalone units
>
> For examples, include/linux/compiler-gcc.h is not intended to be
> included directly. We should always exclude such ones.
>
> [2] headers that are conditionally compiled as standalone units
>
> Some headers can be compiled only for particular architectures.
> For example, include/linux/arm-cci.h can be compiled only for
> arm/arm64 because it requires <asm/arm-cci.h> to exist.
> Clang can compile include/soc/nps/mtm.h only for arc because
> it contains an arch-specific register in inline assembler.
>
> For [2], we can write Makefile like this:
>
> header-test-$(CONFIG_ARM) += linux/arm-cci.h
>
> The new syntax header-test-pattern-y will be useful to specify
> "the rest".
>
> The typical usage is like this:
>
> header-test-pattern-y += */*.h
>
> This adds all the headers in sub-directories to the test coverage,
> but headers added to header-test- are excluded. In this regards,
> header-test-pattern-y behaves like a weaker variant of header-test-y.
>
> Caveat:
> The patterns in header-test-pattern-y are prefixed with $(srctree)/$(src)/
> but not $(objtree)/$(obj)/. Stale generated patterns are often left over.
> For example, you will have ones when you traverse the git history for
> 'git bisect' without cleaning. If a wildcard is used for generated
> headers, it may match to stale headers.
>
> If you really want to compile-test generated headers, I recommend to
> add them to header-test-y explicitly. One pitfall is $(srctree)/$(src)/
> and $(objtree)/$(obj)/ point to the same directory for in-tree building.
> So, header-test-pattern-y should be used with care. It can potentially
> match to generated headers, which may be stale and fail to compile.
>
> Caveat2:
> You could use wildcard for header-test-. For example,
>
> header-test- += asm-generic/%
>
> ... will exclude headers in asm-generic directory. Unfortunately, the
> wildcard character is '%' instead of '*' because this is evaluated by
> $(filter-out ...) whereas header-test-pattern-y is evaluated by
> $(wildcard ...). This is a kludge, but seems useful in some places...
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Awesome! This will let us get rid of our local $(wildcard) hacks.
Tested-by: Jani Nikula <jani.nikula@intel.com>
> ---
>
> Changes in v2:
> - New patch
>
> Documentation/kbuild/makefiles.txt | 10 ++++++++++
> scripts/Makefile.lib | 10 ++++++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
> index 5080fec34609..b817e6cefb77 100644
> --- a/Documentation/kbuild/makefiles.txt
> +++ b/Documentation/kbuild/makefiles.txt
> @@ -1025,6 +1025,16 @@ When kbuild executes, the following steps are followed (roughly):
> i.e. compilable as standalone units. If CONFIG_HEADER_TEST is enabled,
> this builds them as part of extra-y.
>
> + header-test-pattern-y
> +
> + This works as a weaker version of header-test-y, and accepts wildcard
> + patterns. The typical usage is:
> +
> + header-test-pattern-y += *.h
> +
> + This specifies all the files that matches to '*.h' in the current
> + directory, but the files in 'header-test-' are excluded.
> +
> --- 6.7 Commands useful for building a boot image
>
> Kbuild provides a few macros that are useful when building a
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 55ae1ec65342..54444933bbab 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -67,6 +67,16 @@ extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
> endif
>
> # Test self-contained headers
> +
> +# Wildcard searches in $(srctree)/$(src)/, but not in $(objtree)/$(obj)/.
> +# Stale generated headers are often left over, so wildcard matching should
> +# be avoided. Please notice $(srctree)/$(src)/ and $(objtree)/$(obj) point
> +# to the same location for in-tree building.
> +header-test-y += $(filter-out $(header-test-), \
> + $(patsubst $(srctree)/$(src)/%, %, \
> + $(wildcard $(addprefix $(srctree)/$(src)/, \
> + $(header-test-pattern-y)))))
> +
> extra-$(CONFIG_HEADER_TEST) += $(addsuffix .s, $(header-test-y))
>
> # Add subdir path
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/4] Compile-test UAPI and kernel headers
2019-06-27 1:46 [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
` (2 preceding siblings ...)
2019-06-27 3:12 ` [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
@ 2019-06-27 11:39 ` Jani Nikula
2019-06-27 16:42 ` Masahiro Yamada
3 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2019-06-27 11:39 UTC (permalink / raw)
To: Masahiro Yamada, linux-kbuild
Cc: Sam Ravnborg, Masahiro Yamada, Tony Luck, linux-doc,
John Fastabend, Jonathan Corbet, Jakub Kicinski, linux-riscv,
Daniel Borkmann, xdp-newbies, Anton Vorontsov, Palmer Dabbelt,
Matthias Brugger, Song Liu, Yonghong Song, Michal Marek,
Jesper Dangaard Brouer, Martin KaFai Lau, linux-mediatek,
linux-arm-kernel, Albert Ou, Colin Cross, David S. Miller,
Kees Cook, Alexei Starovoitov, netdev, linux-kernel, bpf
On Thu, 27 Jun 2019, Masahiro Yamada <yamada.masahiro@socionext.com> wrote:
> 1/4: reworked v2.
>
> 2/4: fix a flaw I noticed when I was working on this series
>
> 3/4: maybe useful for 4/4 and in some other places
>
> 4/4: v2. compile as many headers as possible.
>
>
> Changes in v2:
> - Add CONFIG_CPU_{BIG,LITTLE}_ENDIAN guard to avoid build error
> - Use 'header-test-' instead of 'no-header-test'
> - Avoid weird 'find' warning when cleaning
> - New patch
> - New patch
> - Add everything to test coverage, and exclude broken ones
> - Rename 'Makefile' to 'Kbuild'
> - Add CONFIG_KERNEL_HEADER_TEST option
>
> Masahiro Yamada (4):
> kbuild: compile-test UAPI headers to ensure they are self-contained
> kbuild: do not create wrappers for header-test-y
> kbuild: support header-test-pattern-y
> kbuild: compile-test kernel headers to ensure they are self-contained
[responding here because I didn't receive the actual patch]
This looks like it's doing what it's supposed to, but I ran into a bunch
of build fails with CONFIG_OF=n. Sent a fix to one [1], but stopped at
the next. Looks like you'll have to exclude more. And I'm pretty sure
we'll uncover more configurations where this will fail.
But I do applaud the goal, and I'm committed to making all include/drm
headers self-contained. I wouldn't block this based on the issues, it's
pretty much the only way to expose them and get them fixed/excluded, and
it's behind a config knob after all.
With the caveat that I didn't finish the build, but OTOH tested the
rainy day scenario and had the patch find issues it's meant to find:
Tested-by: Jani Nikula <jani.nikula@intel.com>
[1] http://patchwork.freedesktop.org/patch/msgid/20190627110103.7539-1-jani.nikula@intel.com
>
> .gitignore | 1 -
> Documentation/dontdiff | 1 -
> Documentation/kbuild/makefiles.txt | 13 +-
> Makefile | 4 +-
> include/Kbuild | 1134 ++++++++++++++++++++++++++++
> init/Kconfig | 22 +
> scripts/Makefile.build | 10 +-
> scripts/Makefile.lib | 12 +-
> scripts/cc-system-headers.sh | 8 +
> usr/.gitignore | 1 -
> usr/Makefile | 2 +
> usr/include/.gitignore | 3 +
> usr/include/Makefile | 133 ++++
> 13 files changed, 1331 insertions(+), 13 deletions(-)
> create mode 100644 include/Kbuild
> create mode 100755 scripts/cc-system-headers.sh
> create mode 100644 usr/include/.gitignore
> create mode 100644 usr/include/Makefile
--
Jani Nikula, Intel Open Source Graphics Center
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/4] Compile-test UAPI and kernel headers
2019-06-27 11:39 ` Jani Nikula
@ 2019-06-27 16:42 ` Masahiro Yamada
0 siblings, 0 replies; 8+ messages in thread
From: Masahiro Yamada @ 2019-06-27 16:42 UTC (permalink / raw)
To: Jani Nikula
Cc: Linux Kbuild mailing list, Sam Ravnborg, Tony Luck,
open list:DOCUMENTATION, John Fastabend, Jonathan Corbet,
Jakub Kicinski, linux-riscv, Daniel Borkmann, xdp-newbies,
Anton Vorontsov, Palmer Dabbelt, Matthias Brugger, Song Liu,
Yonghong Song, Michal Marek, Jesper Dangaard Brouer,
Martin KaFai Lau, moderated list:ARM/Mediatek SoC support,
linux-arm-kernel, Albert Ou, Colin Cross, David S. Miller,
Kees Cook, Alexei Starovoitov, Networking,
Linux Kernel Mailing List, bpf
On Thu, Jun 27, 2019 at 8:36 PM Jani Nikula <jani.nikula@linux.intel.com> wrote:
>
> On Thu, 27 Jun 2019, Masahiro Yamada <yamada.masahiro@socionext.com> wrote:
> > 1/4: reworked v2.
> >
> > 2/4: fix a flaw I noticed when I was working on this series
> >
> > 3/4: maybe useful for 4/4 and in some other places
> >
> > 4/4: v2. compile as many headers as possible.
> >
> >
> > Changes in v2:
> > - Add CONFIG_CPU_{BIG,LITTLE}_ENDIAN guard to avoid build error
> > - Use 'header-test-' instead of 'no-header-test'
> > - Avoid weird 'find' warning when cleaning
> > - New patch
> > - New patch
> > - Add everything to test coverage, and exclude broken ones
> > - Rename 'Makefile' to 'Kbuild'
> > - Add CONFIG_KERNEL_HEADER_TEST option
> >
> > Masahiro Yamada (4):
> > kbuild: compile-test UAPI headers to ensure they are self-contained
> > kbuild: do not create wrappers for header-test-y
> > kbuild: support header-test-pattern-y
> > kbuild: compile-test kernel headers to ensure they are self-contained
>
> [responding here because I didn't receive the actual patch]
>
> This looks like it's doing what it's supposed to, but I ran into a bunch
> of build fails with CONFIG_OF=n. Sent a fix to one [1], but stopped at
> the next. Looks like you'll have to exclude more. And I'm pretty sure
> we'll uncover more configurations where this will fail.
Thanks for testing.
I did more compile-tests, and excluded more headers in v3.
Thanks.
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-06-27 16:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-27 1:46 [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
2019-06-27 1:46 ` [PATCH v2 2/4] kbuild: do not create wrappers for header-test-y Masahiro Yamada
2019-06-27 11:25 ` Jani Nikula
2019-06-27 1:46 ` [PATCH v2 3/4] kbuild: support header-test-pattern-y Masahiro Yamada
2019-06-27 11:28 ` Jani Nikula
2019-06-27 3:12 ` [PATCH v2 0/4] Compile-test UAPI and kernel headers Masahiro Yamada
2019-06-27 11:39 ` Jani Nikula
2019-06-27 16:42 ` Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).