mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kbuild: make clean rule robust against too long argument error
@ 2023-06-17 15:30 Masahiro Yamada
  2023-06-17 20:07 ` Eugeniu Rosca
  0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2023-06-17 15:30 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, Masahiro Yamada, Eugeniu Rosca

Commit cd968b97c492 ("kbuild: make built-in.a rule robust against too
long argument error") made a build rule robust against "Argument list
too long" error.

Eugeniu Rosca reported the same error occurred when cleaning an external
module.

The $(obj)/ prefix can be a very long path for external modules.

Apply a similar solution to 'make clean'.

Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/Makefile.clean | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 3649900696dd..235408a44f90 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -37,8 +37,9 @@ __clean-files   := $(wildcard $(addprefix $(obj)/, $(__clean-files)))
 
 # ==========================================================================
 
+# Use xargs to make this robust against "Argument list too long" error
 quiet_cmd_clean = CLEAN   $(obj)
-      cmd_clean = rm -rf $(__clean-files)
+      cmd_clean = printf '$(obj)/%s ' $(patsubst $(obj)/%,%,$(__clean-files)) | xargs rm -rf
 
 __clean: $(subdir-ymn)
 ifneq ($(strip $(__clean-files)),)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: make clean rule robust against too long argument error
  2023-06-17 15:30 [PATCH] kbuild: make clean rule robust against too long argument error Masahiro Yamada
@ 2023-06-17 20:07 ` Eugeniu Rosca
  2023-06-18 15:50   ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Eugeniu Rosca @ 2023-06-17 20:07 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-kbuild, linux-kernel, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, Eugeniu Rosca, Eugeniu Rosca

Hello Yamada-san,

Many thanks for your feedback and for your patch.
It indeed addresses the issue I have reported in [1].

On Sun, Jun 18, 2023 at 12:30:25AM +0900, Masahiro Yamada wrote:
> Commit cd968b97c492 ("kbuild: make built-in.a rule robust against too
> long argument error") made a build rule robust against "Argument list
> too long" error.
> 
> Eugeniu Rosca reported the same error occurred when cleaning an external
> module.
> 
> The $(obj)/ prefix can be a very long path for external modules.

Confirmed. I am seeing an instance of $(obj) being 150 characters long,
due to an out-of-tree module deeply buried in a specific Yocto build.

In the current vanilla version of 'make clean' (w/o this patch), the
$(obj) prefix is applied to each and every file being removed,
dramatically increasing the strlen of arguments passed to 'rm -rf'.

> 
> Apply a similar solution to 'make clean'.
> 
> Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  scripts/Makefile.clean | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
> index 3649900696dd..235408a44f90 100644
> --- a/scripts/Makefile.clean
> +++ b/scripts/Makefile.clean
> @@ -37,8 +37,9 @@ __clean-files   := $(wildcard $(addprefix $(obj)/, $(__clean-files)))
>  
>  # ==========================================================================
>  
> +# Use xargs to make this robust against "Argument list too long" error

Please, correct me if I am wrong, but it looks like the magic/brilliance
is in the 'patsubst' function, since below version also fails for me:

NOK: cmd_clean = printf '%s ' $(__clean-files) | xargs rm -rf

When running 'make clean' for my particular out-of-tree kernel module,
'patsubst' is able to decrease the total number of characters passed
to the shell's argument list from ~204k to ~47k, which elegantly
prevents the "Argument list too long" error.

>  quiet_cmd_clean = CLEAN   $(obj)
> -      cmd_clean = rm -rf $(__clean-files)
> +      cmd_clean = printf '$(obj)/%s ' $(patsubst $(obj)/%,%,$(__clean-files)) | xargs rm -rf
>  
>  __clean: $(subdir-ymn)
>  ifneq ($(strip $(__clean-files)),)
> -- 
> 2.39.2
> 

Since it fixes the problem reported in [1] (much appreciated):

Reviewed-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Tested-by: Eugeniu Rosca <erosca@de.adit-jv.com>

[1] https://lore.kernel.org/linux-kbuild/20230616194505.GA27753@lxhi-065/

-- 
Best regards,
Eugeniu Rosca

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: make clean rule robust against too long argument error
  2023-06-17 20:07 ` Eugeniu Rosca
@ 2023-06-18 15:50   ` Masahiro Yamada
  2023-06-19  9:32     ` Eugeniu Rosca
  0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2023-06-18 15:50 UTC (permalink / raw)
  To: Eugeniu Rosca
  Cc: linux-kbuild, linux-kernel, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, Eugeniu Rosca

On Sun, Jun 18, 2023 at 5:07 AM Eugeniu Rosca <erosca@de.adit-jv.com> wrote:
>
> Hello Yamada-san,
>
> Many thanks for your feedback and for your patch.
> It indeed addresses the issue I have reported in [1].
>
> On Sun, Jun 18, 2023 at 12:30:25AM +0900, Masahiro Yamada wrote:
> > Commit cd968b97c492 ("kbuild: make built-in.a rule robust against too
> > long argument error") made a build rule robust against "Argument list
> > too long" error.
> >
> > Eugeniu Rosca reported the same error occurred when cleaning an external
> > module.
> >
> > The $(obj)/ prefix can be a very long path for external modules.
>
> Confirmed. I am seeing an instance of $(obj) being 150 characters long,
> due to an out-of-tree module deeply buried in a specific Yocto build.
>
> In the current vanilla version of 'make clean' (w/o this patch), the
> $(obj) prefix is applied to each and every file being removed,
> dramatically increasing the strlen of arguments passed to 'rm -rf'.
>
> >
> > Apply a similar solution to 'make clean'.
> >
> > Reported-by: Eugeniu Rosca <erosca@de.adit-jv.com>
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
> >
> >  scripts/Makefile.clean | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
> > index 3649900696dd..235408a44f90 100644
> > --- a/scripts/Makefile.clean
> > +++ b/scripts/Makefile.clean
> > @@ -37,8 +37,9 @@ __clean-files   := $(wildcard $(addprefix $(obj)/, $(__clean-files)))
> >
> >  # ==========================================================================
> >
> > +# Use xargs to make this robust against "Argument list too long" error
>
> Please, correct me if I am wrong, but it looks like the magic/brilliance
> is in the 'patsubst' function, since below version also fails for me:
>
> NOK: cmd_clean = printf '%s ' $(__clean-files) | xargs rm -rf

Right.
Now, 'printf' (instead of 'rm') failed with the too long argument list.

GNU Make does not have the length limit, but shell does.
So, the full-path list must be passed via stdout
instead of the command line.


The comment might be confusing.

I will repeat the same comment written in scripts/Makefile.build:

  # To make this rule robust against "Argument list too long" error,
  # remove $(obj)/ prefix, and restore it by a shell command.




-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: make clean rule robust against too long argument error
  2023-06-18 15:50   ` Masahiro Yamada
@ 2023-06-19  9:32     ` Eugeniu Rosca
  0 siblings, 0 replies; 4+ messages in thread
From: Eugeniu Rosca @ 2023-06-19  9:32 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Eugeniu Rosca, linux-kbuild, linux-kernel, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, Eugeniu Rosca

Hello Yamada-san,

On Mon, Jun 19, 2023 at 12:50:48AM +0900, Masahiro Yamada wrote:
> On Sun, Jun 18, 2023 at 5:07 AM Eugeniu Rosca <erosca@de.adit-jv.com> wrote:

[snip]

> > Please, correct me if I am wrong, but it looks like the magic/brilliance
> > is in the 'patsubst' function, since below version also fails for me:
> >
> > NOK: cmd_clean = printf '%s ' $(__clean-files) | xargs rm -rf
> 
> Right.
> Now, 'printf' (instead of 'rm') failed with the too long argument list.
> 
> GNU Make does not have the length limit, but shell does.
> So, the full-path list must be passed via stdout
> instead of the command line.
> 
> 
> The comment might be confusing.
> 
> I will repeat the same comment written in scripts/Makefile.build:
> 
>   # To make this rule robust against "Argument list too long" error,
>   # remove $(obj)/ prefix, and restore it by a shell command.

Sounds good to me. No open questions from my end :)

-- 
Best regards,
Eugeniu Rosca

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-19  9:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-17 15:30 [PATCH] kbuild: make clean rule robust against too long argument error Masahiro Yamada
2023-06-17 20:07 ` Eugeniu Rosca
2023-06-18 15:50   ` Masahiro Yamada
2023-06-19  9:32     ` Eugeniu Rosca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®