Re: [PATCH] kbuild/x86: Use $(KBUILD_AFLAGS) in Kbuild's version of $(as-instr)
From: Dmitry Safonov
Date: Thu Apr 11 2024 - 00:35:11 EST
On Thu, 11 Apr 2024 at 00:41, Dmitry Safonov <0x7f454c46@xxxxxxxxx> wrote:
>
> Please, ignore this version.
>
> the previous one was to add a helper function and that seemed to work,
> but on rework to actually use KBUILD_AFLAGS instead of adding a new
> function I certainly haven't tested it enough.
> Going to prepare version 2, sorry for the noise.
Yeah, in the end I debugged why it doesn't work, for the same machine
as in the patch message:
$ grep KBUILD_AFLAGS include/config/auto.conf.cmd
ifneq "$(KBUILD_AFLAGS)" "-D__ASSEMBLY__ -fno-PIE -m64 "
Notice the trailing space? That's the thing that doesn't match with
the $(KBUILD_AFLAGS) in top-level Makefile.
Adding some more debug:
> --- a/scripts/kconfig/Makefile
> +++ b/scripts/kconfig/Makefile
> @@ -80,8 +80,10 @@ simple-targets := oldconfig allnoconfig allyesconfig allmodconfig \
> helpnewconfig yes2modconfig mod2yesconfig mod2noconfig
>
>
> PHONY += $(simple-targets)
> +$(info KBUILD_AFLAGS is "$(KBUILD_AFLAGS)")
>
> $(simple-targets): $(obj)/conf
> + $(info KBUILD_AFLAGS for $@ "$(KBUILD_AFLAGS)")
> $(Q)$< $(silent) --$@ $(Kconfig)
>
> PHONY += savedefconfig defconfig
> --- a/scripts/kconfig/preprocess.c
> +++ b/scripts/kconfig/preprocess.c
> @@ -79,6 +79,8 @@ static char *env_expand(const char *name)
> if (!value)
> return NULL;
>
> + fprintf(stderr, "\tvariable '%s' = '%s'\n", name, value);
> +
> /*
> * We need to remember all referenced environment variables.
> * They will be written out to include/config/auto.conf.cmd
Results in
> variable 'KBUILD_AFLAGS' = '-D__ASSEMBLY__ -fno-PIE -m64 '
(with the trailing space),
> KBUILD_AFLAGS is "-D__ASSEMBLY__ -fno-PIE -m64"
> KBUILD_AFLAGS for syncconfig "-D__ASSEMBLY__ -fno-PIE -m64 "
Ok, so the variable is actually being updated by a common rule in
> scripts/Makefile.lib:KBUILD_AFLAGS += $(subdir-asflags-y)
Which adds a trailing space to $(KBUILD_AFLAGS) and as a result breaks
the comparison in include/config/auto.conf.cmd
So, I see 3 options for the patch in the thread:
1. Simple and ugly: add ifneq to scripts/Makefile.lib and update
KBUILD_AFLAGS only if $(subdir-asflags-y) is not empty.
2. Maybe a better one: remove trailing (and potentially leading, and
duplicate) spaces for expanded variables in
scripts/kconfig/preprocess.c
3. If the issue in the patch description is not worth it: I could just
work that around in the build system.
Please, advise what's your opinion/views.
Thanks,
Dmitry