xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-extended/bash/bash/makerace2.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1The main makefile can call mkbuiltins from multiple different codepaths in parallel.
2When called, it moves the existing files out the way and creates new ones, then
3compares which will break the build if timing is unlucky.
4
5The root of the problem is mkbuiltins.c creating a file but also referencing that
6file under the same name. By modifing it to allow the final name and the temp name
7to be specified, we can avoid the original reason for the moving of files around.
8This allows them to be created under a new name and then replaced if changed,
9removing any race windows around accessing the files whilst they've been
10moved or are being rewritten.
11
12See [YOCTO #14227]
13
14Upstream-Status: Submitted [https://savannah.gnu.org/patch/index.php?10210]
15Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
16
17Index: bash-5.1.8/builtins/Makefile.in
18===================================================================
19--- bash-5.1.8.orig/builtins/Makefile.in
20+++ bash-5.1.8/builtins/Makefile.in
21@@ -185,19 +185,17 @@ gen-helpfiles:	tmpbuiltins.o gen-helpfil
22 	$(CC_FOR_BUILD) ${CCFLAGS_FOR_BUILD} $(LDFLAGS_FOR_BUILD) -o $@ gen-helpfiles.o tmpbuiltins.o $(LIBS_FOR_BUILD)
23
24 builtext.h builtins.c: $(MKBUILTINS) $(DEFSRC)
25-	@-if test -f builtins.c; then mv -f builtins.c old-builtins.c; fi
26-	@-if test -f builtext.h; then mv -f builtext.h old-builtext.h; fi
27-	./$(MKBUILTINS) -externfile builtext.h -structfile builtins.c \
28+	./$(MKBUILTINS) -externfile builtext-new.h -externfinalfile builtext.h -structfile builtins-new.c \
29 	    -noproduction $(DIRECTDEFINE) $(HELPDIRDEFINE) $(HELPSTRINGS) $(DEFSRC)
30-	@-if cmp -s old-builtext.h builtext.h 2>/dev/null; then \
31-		mv old-builtext.h builtext.h; \
32+	@-if ! cmp -s builtext.h builtext-new.h 2>/dev/null; then \
33+		mv builtext-new.h builtext.h; \
34 	 else \
35-		$(RM) old-builtext.h; \
36+		$(RM) builtext-new.h; \
37 	 fi
38-	@-if cmp -s old-builtins.c builtins.c 2>/dev/null; then \
39-		mv old-builtins.c builtins.c; \
40+	@-if ! cmp -s builtins.c builtins-new.c 2>/dev/null; then \
41+		mv builtins-new.c builtins.c; \
42 	 else \
43-		$(RM) old-builtins.c; \
44+		$(RM) builtins-new.c; \
45 	 fi
46
47 helpdoc:	gen-helpfiles
48Index: bash-5.1.8/builtins/mkbuiltins.c
49===================================================================
50--- bash-5.1.8.orig/builtins/mkbuiltins.c
51+++ bash-5.1.8/builtins/mkbuiltins.c
52@@ -113,6 +113,9 @@ char *struct_filename = (char *)NULL;
53 /* The name of the external declaration file. */
54 char *extern_filename = (char *)NULL;
55
56+/* The final name of the external declaration file. */
57+char *extern_final_filename = (char *)NULL;
58+
59 /* Here is a structure for manipulating arrays of data. */
60 typedef struct {
61   int size;		/* Number of slots allocated to array. */
62@@ -230,6 +233,8 @@ main (argc, argv)
63
64       if (strcmp (arg, "-externfile") == 0)
65 	extern_filename = argv[arg_index++];
66+      else if (strcmp (arg, "-externfinalfile") == 0)
67+	extern_final_filename = argv[arg_index++];
68       else if (strcmp (arg, "-structfile") == 0)
69 	struct_filename = argv[arg_index++];
70       else if (strcmp (arg, "-noproduction") == 0)
71@@ -273,6 +278,9 @@ main (argc, argv)
72 	}
73     }
74
75+  if (!extern_final_filename)
76+    extern_final_filename = extern_filename;
77+
78   /* If there are no files to process, just quit now. */
79   if (arg_index == argc)
80     exit (0);
81@@ -1174,7 +1182,7 @@ write_file_headers (structfile, externfi
82 	fprintf (structfile, "%s\n", structfile_header[i]);
83
84       fprintf (structfile, "#include \"%s\"\n",
85-	       extern_filename ? extern_filename : "builtext.h");
86+	       extern_final_filename ? extern_final_filename : "builtext.h");
87
88       fprintf (structfile, "#include \"bashintl.h\"\n");
89
90@@ -1184,7 +1192,7 @@ write_file_headers (structfile, externfi
91   if (externfile)
92     fprintf (externfile,
93 	     "/* %s - The list of builtins found in libbuiltins.a. */\n",
94-	     extern_filename ? extern_filename : "builtext.h");
95+	     extern_final_filename ? extern_final_filename : "builtext.h");
96 }
97
98 /* Write out any necessary closing information for
99