Re: [PATCH v2 3/6] bootconfig: render embedded bootconfig as a kernel cmdline at build time

From: Google

Date: Sun Jun 07 2026 - 22:29:24 EST


Hi Breno,

On Fri, 05 Jun 2026 05:03:34 -0700
Breno Leitao <leitao@xxxxxxxxxx> wrote:

> diff --git a/tools/bootconfig/Makefile b/tools/bootconfig/Makefile
> index 90eb47c9d8de..aa75a7828685 100644
> --- a/tools/bootconfig/Makefile
> +++ b/tools/bootconfig/Makefile
> @@ -15,10 +15,14 @@ override CFLAGS += -Wall -g -I$(CURDIR)/include
> ALL_TARGETS := bootconfig
> ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
>
> -all: $(ALL_PROGRAMS) test
> +all: $(ALL_PROGRAMS)
>
> +# bootconfig is a build host tool: Kbuild's prepare hook runs it on the
> +# build machine to render the embedded cmdline, so always compile it with
> +# $(HOSTCC). Using $(CC) would cross-compile it under ARCH=... builds and
> +# fail to exec on the host ("Exec format error").
> $(OUTPUT)bootconfig: main.c include/linux/bootconfig.h $(LIBSRC)
> - $(CC) $(filter %.c,$^) $(CFLAGS) $(LDFLAGS) -o $@
> + $(HOSTCC) $(filter %.c,$^) $(CFLAGS) $(LDFLAGS) -o $@


> Is it safe to pass $(CFLAGS) and $(LDFLAGS) to $(HOSTCC) here?
> When cross-compiling, $(CFLAGS) and $(LDFLAGS) often contain target-specific
> flags. Passing these target flags to the host compiler might cause it to fail,
> or incorrectly generate binaries for the target architecture that fail to
> execute on the build host.

Sashiko found a problem here. Hmm, I would like to build the bootconfig
tool just as a tool. (like `cd tools/bootconfig; make`)
Can we identify the build (make) is called from kernel build process or not
and switching CC/CFLAGS/LDFLAGS?

>
> Additionally, since bootconfig is an administrative utility meant to be
> deployed on the target system, will permanently hardcoding $(HOSTCC) prevent
> users from cross-compiling it for their target devices?

This is also a good point. We need cros build binary and host binary.

Thank you,

--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>