diff mbox series

samples: run headers_install for host arch instead of target arch

Message ID 1538117388-11945-1-git-send-email-yamada.masahiro@socionext.com
State New
Headers show
Series samples: run headers_install for host arch instead of target arch | expand

Commit Message

Masahiro Yamada Sept. 28, 2018, 6:49 a.m. UTC
Some samples search headers in $(objtree)/usr/include, which is made
available by "make headers_install".  It is not kernel-space code but
host programs that need this header search path.

Commit 3fca1700c4c3 ("kbuild: make samples really depend on
headers_install") is wrong because it installs headers of the target
architecture.  Besides, UML fails to build with CONFIG_SAMPLES=y
because UML does not support headers_install.

Invoke "make headers_install" for the _host_ architecture in the
prepare stage.  Introduce CONFIG_HOST_HEADERS_INSTALL so that this
happens only for samples that need it.

I also removed 'Documentation/: headers_install', which I guess is
stale code.

Fixes: 3fca1700c4c3 ("kbuild: make samples really depend on headers_install")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Cc: David Howells <dhowells@redhat.com>
---

 Makefile        | 8 ++++----
 samples/Kconfig | 6 ++++++
 2 files changed, 10 insertions(+), 4 deletions(-)

-- 
2.7.4

Comments

Arnd Bergmann Sept. 28, 2018, 7:36 p.m. UTC | #1
On Fri, Sep 28, 2018 at 8:51 AM Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>

> Some samples search headers in $(objtree)/usr/include, which is made

> available by "make headers_install".  It is not kernel-space code but

> host programs that need this header search path.

>

> Commit 3fca1700c4c3 ("kbuild: make samples really depend on

> headers_install") is wrong because it installs headers of the target

> architecture.  Besides, UML fails to build with CONFIG_SAMPLES=y

> because UML does not support headers_install.

>

> Invoke "make headers_install" for the _host_ architecture in the

> prepare stage.  Introduce CONFIG_HOST_HEADERS_INSTALL so that this

> happens only for samples that need it.

>

> I also removed 'Documentation/: headers_install', which I guess is

> stale code.

>

> Fixes: 3fca1700c4c3 ("kbuild: make samples really depend on headers_install")

> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

> Cc: David Howells <dhowells@redhat.com>


I don't understand this one. Why would we want to build the samples for
the host architecture rather than the target architecture?

I would think that the bug is that we try to build them using
HOSTCC, and they end up being unusable on the target as
a consequence.

        Arnd
Masahiro Yamada Sept. 29, 2018, 4:52 p.m. UTC | #2
2018年9月29日(土) 4:38 Arnd Bergmann <arnd@arndb.de>:
>

> On Fri, Sep 28, 2018 at 8:51 AM Masahiro Yamada

> <yamada.masahiro@socionext.com> wrote:

> >

> > Some samples search headers in $(objtree)/usr/include, which is made

> > available by "make headers_install".  It is not kernel-space code but

> > host programs that need this header search path.

> >

> > Commit 3fca1700c4c3 ("kbuild: make samples really depend on

> > headers_install") is wrong because it installs headers of the target

> > architecture.  Besides, UML fails to build with CONFIG_SAMPLES=y

> > because UML does not support headers_install.

> >

> > Invoke "make headers_install" for the _host_ architecture in the

> > prepare stage.  Introduce CONFIG_HOST_HEADERS_INSTALL so that this

> > happens only for samples that need it.

> >

> > I also removed 'Documentation/: headers_install', which I guess is

> > stale code.

> >

> > Fixes: 3fca1700c4c3 ("kbuild: make samples really depend on headers_install")

> > Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

> > Cc: David Howells <dhowells@redhat.com>

>

> I don't understand this one. Why would we want to build the samples for

> the host architecture rather than the target architecture?

>

> I would think that the bug is that we try to build them using

> HOSTCC, and they end up being unusable on the target as

> a consequence.



I just read Makefiles under samples/, and
all that require -I$(objtree)/usr/include
are listed in hostprogs-y,
so they are built for host architectures.

If this is different from our intent,
we need to fix this first.




-- 
Best Regards
Masahiro Yamada
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 0c90c43..f04564c 100644
--- a/Makefile
+++ b/Makefile
@@ -1029,10 +1029,9 @@  ifdef CONFIG_GDB_SCRIPTS
 endif
 	+$(call if_changed,link-vmlinux)
 
-# Build samples along the rest of the kernel. This needs headers_install.
+# Build samples along the rest of the kernel.
 ifdef CONFIG_SAMPLES
 vmlinux-dirs += samples
-samples: headers_install
 endif
 
 # The actual objects are generated when descending,
@@ -1098,6 +1097,9 @@  archprepare: archheaders archscripts prepare1 scripts_basic
 
 prepare0: archprepare gcc-plugins
 	$(Q)$(MAKE) $(build)=.
+ifdef CONFIG_HOST_HEADERS_INSTALL
+	$(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(SUBARCH) headers_install
+endif
 
 # All the preparing..
 prepare: prepare0 prepare-objtool
@@ -1682,8 +1684,6 @@  endif
 	$(cmd_crmodverdir)
 	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
 	$(build)=$(build-dir)
-# Make sure the latest headers are built for Documentation
-Documentation/ samples/: headers_install
 %/: prepare scripts FORCE
 	$(cmd_crmodverdir)
 	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
diff --git a/samples/Kconfig b/samples/Kconfig
index bd133ef..fcd6b7c 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -1,3 +1,6 @@ 
+config HOST_HEADERS_INSTALL
+	bool
+
 menuconfig SAMPLES
 	bool "Sample kernel code"
 	help
@@ -95,6 +98,7 @@  config SAMPLE_CONFIGFS
 config SAMPLE_CONNECTOR
 	tristate "Build connector sample -- loadable modules only"
 	depends on CONNECTOR && m
+	select HOST_HEADERS_INSTALL
 	help
 	  When enabled, this builds both a sample kernel module for
 	  the connector interface and a user space tool to communicate
@@ -104,6 +108,7 @@  config SAMPLE_CONNECTOR
 config SAMPLE_SECCOMP
 	tristate "Build seccomp sample code -- loadable modules only"
 	depends on SECCOMP_FILTER && m
+	select HOST_HEADERS_INSTALL
 	help
 	  Build samples of seccomp filters using various methods of
 	  BPF filter construction.
@@ -149,6 +154,7 @@  config SAMPLE_VFIO_MDEV_MBOCHS
 config SAMPLE_STATX
 	bool "Build example extended-stat using code"
 	depends on BROKEN
+	select HOST_HEADERS_INSTALL
 	help
 	  Build example userspace program to use the new extended-stat syscall.