Parallel make bug in busybox

Denys Vlasenko vda.linux at googlemail.com
Sun Aug 21 20:03:03 UTC 2016


On Fri, Aug 19, 2016 at 3:47 PM, Richard Purdie <rpurdie at rpsys.net> wrote:
> I think I have got to the bottom of the problem. applet_tables only
> rewrites NUM_APPLETS.h if the file changes. This leads to make
> repeatedly trying to rewrite it since the compiled binary itself can be
> newer that the header, amongst other issues.
>
> There is also the issue I mentioned previously, that the command can be
> executed for both headers in parallel and this leads to double
> execution and races. The simplest thing to do seems to be to make
> applet_tables always rewrite the file and make include/applet_tables.h:
> depend on include/NUM_APPLETS.h which in turn runs the generation
> script.
>
> I'd therefore propose the following patch which should resolve the
> issues:
>
> Index: busybox-1.24.1/applets/Kbuild.src
> ===================================================================
> --- busybox-1.24.1.orig/applets/Kbuild.src
> +++ busybox-1.24.1/applets/Kbuild.src
> @@ -29,7 +29,7 @@ applets/applets.o: include/usage_compres
>
>  applets/applet_tables: .config include/applets.h
>  applets/usage:         .config include/applets.h
> -applets/usage_pod:     .config include/applets.h include/applet_tables.h include/NUM_APPLETS.h
> +applets/usage_pod:     .config include/applets.h include/applet_tables.h
>
>  quiet_cmd_gen_usage_compressed = GEN     include/usage_compressed.h
>        cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
> @@ -40,5 +40,7 @@ include/usage_compressed.h: applets/usag
>  quiet_cmd_gen_applet_tables = GEN     include/applet_tables.h
>        cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h include/NUM_APPLETS.h
>
> -include/applet_tables.h include/NUM_APPLETS.h: applets/applet_tables
> +include/NUM_APPLETS.h: applets/applet_tables
>         $(call cmd,gen_applet_tables)
> +
> +include/applet_tables.h: include/NUM_APPLETS.h


Without command, the second rule does not rebuild include/applet_tables.h
if it is deleted.

I gave it "$(call cmd,gen_applet_tables)"

Applied to git.
Now it seems to work.


> Index: busybox-1.24.1/applets/applet_tables.c
> ===================================================================
> --- busybox-1.24.1.orig/applets/applet_tables.c
> +++ busybox-1.24.1/applets/applet_tables.c
> @@ -151,23 +151,15 @@ int main(int argc, char **argv)
>  //     printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
>
>         if (argv[2]) {
> -               char line_old[80];
>                 char line_new[80];
>                 FILE *fp;
>
> -               line_old[0] = 0;
> -               fp = fopen(argv[2], "r");
> -               if (fp) {
> -                       fgets(line_old, sizeof(line_old), fp);
> -                       fclose(fp);
> -               }
>                 sprintf(line_new, "#define NUM_APPLETS %u\n", NUM_APPLETS);
> -               if (strcmp(line_old, line_new) != 0) {
> -                       fp = fopen(argv[2], "w");
> -                       if (!fp)
> -                               return 1;
> -                       fputs(line_new, fp);
> -               }
> +               fp = fopen(argv[2], "w");
> +               if (!fp)
> +                       return 1;
> +               fputs(line_new, fp);
> +               fclose(fp);

This is done on purpose: if number of applets did not change, no need
to rebuild files which depend on NUM_APPLETS.h


More information about the busybox mailing list