bash: Fix a rare make race build failure

There is a rare make race that occurs in bash due to the way it constructs
certain headers and a build tool. Restructure the creation to remove
the race.

[YOCTO #14227]

(From OE-Core rev: 6f683cf21630142e82cc37d79f3d797d179d8d12)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2021-06-30 12:54:17 +01:00
parent 1f3094e775
commit 68a4cbb7b2
2 changed files with 99 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
The main makefile can call mkbuiltins from multiple different codepaths in parallel.
When called, it moves the existing files out the way and creates new ones, then
compares which will break the build if timing is unlucky.
The root of the problem is mkbuiltins.c creating a file but also referencing that
file under the same name. By modifing it to allow the final name and the temp name
to be specified, we can avoid the original reason for the moving of files around.
This allows them to be created under a new name and then replaced if changed,
removing any race windows around accessing the files whilst they've been
moved or are being rewritten.
See [YOCTO #14227]
Upstream-Status: Pending
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Index: bash-5.1.8/builtins/Makefile.in
===================================================================
--- bash-5.1.8.orig/builtins/Makefile.in
+++ bash-5.1.8/builtins/Makefile.in
@@ -185,19 +185,17 @@ gen-helpfiles: tmpbuiltins.o gen-helpfil
$(CC_FOR_BUILD) ${CCFLAGS_FOR_BUILD} $(LDFLAGS_FOR_BUILD) -o $@ gen-helpfiles.o tmpbuiltins.o $(LIBS_FOR_BUILD)
builtext.h builtins.c: $(MKBUILTINS) $(DEFSRC)
- @-if test -f builtins.c; then mv -f builtins.c old-builtins.c; fi
- @-if test -f builtext.h; then mv -f builtext.h old-builtext.h; fi
- ./$(MKBUILTINS) -externfile builtext.h -structfile builtins.c \
+ ./$(MKBUILTINS) -externfile builtext-new.h -externfinalfile builtext.h -structfile builtins-new.c \
-noproduction $(DIRECTDEFINE) $(HELPDIRDEFINE) $(HELPSTRINGS) $(DEFSRC)
- @-if cmp -s old-builtext.h builtext.h 2>/dev/null; then \
- mv old-builtext.h builtext.h; \
+ @-if ! cmp -s builtext.h builtext-new.h 2>/dev/null; then \
+ mv builtext-new.h builtext.h; \
else \
- $(RM) old-builtext.h; \
+ $(RM) builtext-new.h; \
fi
- @-if cmp -s old-builtins.c builtins.c 2>/dev/null; then \
- mv old-builtins.c builtins.c; \
+ @-if ! cmp -s builtins.c builtins-new.c 2>/dev/null; then \
+ mv builtins-new.c builtins.c; \
else \
- $(RM) old-builtins.c; \
+ $(RM) builtins-new.c; \
fi
helpdoc: gen-helpfiles
Index: bash-5.1.8/builtins/mkbuiltins.c
===================================================================
--- bash-5.1.8.orig/builtins/mkbuiltins.c
+++ bash-5.1.8/builtins/mkbuiltins.c
@@ -113,6 +113,9 @@ char *struct_filename = (char *)NULL;
/* The name of the external declaration file. */
char *extern_filename = (char *)NULL;
+/* The final name of the external declaration file. */
+char *extern_final_filename = (char *)NULL;
+
/* Here is a structure for manipulating arrays of data. */
typedef struct {
int size; /* Number of slots allocated to array. */
@@ -230,6 +233,8 @@ main (argc, argv)
if (strcmp (arg, "-externfile") == 0)
extern_filename = argv[arg_index++];
+ else if (strcmp (arg, "-externfinalfile") == 0)
+ extern_final_filename = argv[arg_index++];
else if (strcmp (arg, "-structfile") == 0)
struct_filename = argv[arg_index++];
else if (strcmp (arg, "-noproduction") == 0)
@@ -273,6 +278,9 @@ main (argc, argv)
}
}
+ if (!extern_final_filename)
+ extern_final_filename = extern_filename;
+
/* If there are no files to process, just quit now. */
if (arg_index == argc)
exit (0);
@@ -1174,7 +1182,7 @@ write_file_headers (structfile, externfi
fprintf (structfile, "%s\n", structfile_header[i]);
fprintf (structfile, "#include \"%s\"\n",
- extern_filename ? extern_filename : "builtext.h");
+ extern_final_filename ? extern_final_filename : "builtext.h");
fprintf (structfile, "#include \"bashintl.h\"\n");
@@ -1184,7 +1192,7 @@ write_file_headers (structfile, externfi
if (externfile)
fprintf (externfile,
"/* %s - The list of builtins found in libbuiltins.a. */\n",
- extern_filename ? extern_filename : "builtext.h");
+ extern_final_filename ? extern_final_filename : "builtext.h");
}
/* Write out any necessary closing information for

View File

@@ -14,6 +14,7 @@ SRC_URI = "${GNU_MIRROR}/bash/${BP}.tar.gz;name=tarball \
file://fix-run-builtins.patch \
file://use_aclocal.patch \
file://makerace.patch \
file://makerace2.patch \
"
SRC_URI[tarball.sha256sum] = "0cfb5c9bb1a29f800a97bd242d19511c997a1013815b805e0fdd32214113d6be"