Skip to content

Commit

Permalink
kbuild: do not create wrappers for header-test-y
Browse files Browse the repository at this point in the history
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 abb2ea7 ("compiler,
clang: suppress warning for unused static inline functions"), but we
should not rely on that.

Signed-off-by: Masahiro Yamada <[email protected]>
Acked-by: Jani Nikula <[email protected]>
Tested-by: Jani Nikula <[email protected]>
  • Loading branch information
masahir0y committed Jul 9, 2019
1 parent d6fc9fc commit c93a036
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*.elf
*.gcno
*.gz
*.hdrtest.c
*.i
*.ko
*.lex.c
Expand Down
1 change: 0 additions & 1 deletion Documentation/dontdiff
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*.grep
*.grp
*.gz
*.hdrtest.c
*.html
*.i
*.jpeg
Expand Down
3 changes: 1 addition & 2 deletions Documentation/kbuild/makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,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' \
Expand Down
10 changes: 5 additions & 5 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
# ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.lib
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion scripts/package/mkspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down

0 comments on commit c93a036

Please sign in to comment.