Skip to content

Commit a866a05

Browse files
jurobystrickyrpurdie
authored andcommitted
busybox: Avoid race building libbb
When building busybox, an occasional error was observed. The error is consistently the same: libbb/appletlib.c:164:13: error: 'NUM_APPLETS' undeclared (first use in this function) while (i < NUM_APPLETS) { The reason is the include file where NUM_APPLETS is defined is not yet generated (or is being modified) at the time libbb/appletlib.c is compiled. The attached patchset fixes the problem by assuring libb is compiled as the last directory. [YOCTO#10116] Signed-off-by: Juro Bystricky <[email protected]> Signed-off-by: Richard Purdie <[email protected]>
1 parent d3d2d21 commit a866a05

File tree

5 files changed

+151
-66
lines changed

5 files changed

+151
-66
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Upstream-Status: Backport
2+
3+
Patch addressing a parallel make race in Busybox
4+
5+
http://git.busybox.net/busybox/commit/?id=d8e61bbf13d0cf38d477255cfd5dc71c5d51d575
6+
7+
Signed-off-by: Juro Bystricky <[email protected]>
8+
9+
From d8e61bbf13d0cf38d477255cfd5dc71c5d51d575 Mon Sep 17 00:00:00 2001
10+
From: Denys Vlasenko <[email protected]>
11+
Date: Sun, 21 Aug 2016 22:00:20 +0200
12+
Subject: build system: different fix for
13+
include/applet_tables.h/include/NUM_APPLETS.h
14+
15+
Signed-off-by: Denys Vlasenko <[email protected]>
16+
17+
diff --git a/applets/Kbuild.src b/applets/Kbuild.src
18+
index 5cc1827..3aedbbf 100644
19+
--- a/applets/Kbuild.src
20+
+++ b/applets/Kbuild.src
21+
@@ -29,7 +29,7 @@ applets/applets.o: include/usage_compressed.h include/applet_tables.h
22+
23+
applets/applet_tables: .config include/applets.h
24+
applets/usage: .config include/applets.h
25+
-applets/usage_pod: .config include/applets.h include/applet_tables.h include/NUM_APPLETS.h
26+
+applets/usage_pod: .config include/applets.h include/applet_tables.h
27+
28+
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
29+
cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
30+
@@ -37,8 +37,21 @@ quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
31+
include/usage_compressed.h: applets/usage $(srctree_slash)applets/usage_compressed
32+
$(call cmd,gen_usage_compressed)
33+
34+
-quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
35+
+quiet_cmd_gen_applet_tables = GEN include/applet_tables.h include/NUM_APPLETS.h
36+
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h include/NUM_APPLETS.h
37+
38+
-include/applet_tables.h include/NUM_APPLETS.h: applets/applet_tables
39+
+include/NUM_APPLETS.h: applets/applet_tables
40+
+ $(call cmd,gen_applet_tables)
41+
+
42+
+# In fact, include/applet_tables.h depends only on applets/applet_tables,
43+
+# and is generated by it. But specifying only it can run
44+
+# applets/applet_tables twice, possibly in parallel.
45+
+# We say that it also needs NUM_APPLETS.h
46+
+#
47+
+# Unfortunately, we need to list the same command,
48+
+# and it can be executed twice (sequentially).
49+
+# The alternative is to not list any command,
50+
+# and then if include/applet_tables.h is deleted, it won't be rebuilt.
51+
+#
52+
+include/applet_tables.h: include/NUM_APPLETS.h applets/applet_tables
53+
$(call cmd,gen_applet_tables)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Upstream-Status: Backport
2+
3+
Patch addressing a parallel make race in Busybox
4+
5+
http://git.busybox.net/busybox/commit/?id=0dddbc1a59795a77679d8c5ef48a2795cb470563
6+
7+
Signed-off-by: Juro Bystricky <[email protected]>
8+
9+
From 0dddbc1a59795a77679d8c5ef48a2795cb470563 Mon Sep 17 00:00:00 2001
10+
From: Denys Vlasenko <[email protected]>
11+
Date: Tue, 23 Aug 2016 20:21:36 +0200
12+
Subject: build system: always rewrite NUM_APPLETS.h
13+
14+
Conditional rewrite can keep NUM_APPLETS.h mtime old,
15+
this causes make to try to regenerate it at every invocation.
16+
17+
Signed-off-by: Denys Vlasenko <[email protected]>
18+
19+
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
20+
index 8401a15..ef911a4 100644
21+
--- a/applets/applet_tables.c
22+
+++ b/applets/applet_tables.c
23+
@@ -192,27 +192,28 @@ int main(int argc, char **argv)
24+
printf("};\n");
25+
#endif
26+
//printf("#endif /* SKIP_definitions */\n");
27+
+
28+
// printf("\n");
29+
// printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
30+
31+
if (argv[2]) {
32+
- char line_old[80];
33+
- char line_new[80];
34+
FILE *fp;
35+
+ char line_new[80];
36+
+// char line_old[80];
37+
38+
- line_old[0] = 0;
39+
- fp = fopen(argv[2], "r");
40+
- if (fp) {
41+
- fgets(line_old, sizeof(line_old), fp);
42+
- fclose(fp);
43+
- }
44+
sprintf(line_new, "#define NUM_APPLETS %u\n", NUM_APPLETS);
45+
- if (strcmp(line_old, line_new) != 0) {
46+
+// line_old[0] = 0;
47+
+// fp = fopen(argv[2], "r");
48+
+// if (fp) {
49+
+// fgets(line_old, sizeof(line_old), fp);
50+
+// fclose(fp);
51+
+// }
52+
+// if (strcmp(line_old, line_new) != 0) {
53+
fp = fopen(argv[2], "w");
54+
if (!fp)
55+
return 1;
56+
fputs(line_new, fp);
57+
- }
58+
+// }
59+
}
60+
61+
return 0;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
There is a potential race when building libbb, as some header files
2+
needed by libbb are not generated yet (or are being modified) at the time
3+
libbb is compiled.
4+
This patch avoids this scenario by building libbb as the last directory.
5+
6+
Upstream-Status: Submitted
7+
Signed-off-by: Juro Bystricky <[email protected]>
8+
9+
Index: busybox-1.24.1/Makefile
10+
===================================================================
11+
diff --git a/Makefile b/Makefile
12+
index 5cfc763..69f3831 100644
13+
--- a/Makefile
14+
+++ b/Makefile
15+
@@ -738,9 +738,18 @@ $(sort $(busybox-all)): $(busybox-dirs) ;
16+
# Error messages still appears in the original language
17+
18+
PHONY += $(busybox-dirs)
19+
-$(busybox-dirs): prepare scripts
20+
+
21+
+libbb-dir = $(filter libbb,$(busybox-dirs))
22+
+busybox-dirs1 = $(filter-out libbb,$(busybox-dirs))
23+
+
24+
+$(busybox-dirs1): prepare scripts
25+
$(Q)$(MAKE) $(build)=$@
26+
27+
+ifneq ($(libbb-dir),)
28+
+$(libbb-dir): | $(busybox-dirs1)
29+
+ $(Q)$(MAKE) $(build)=$@
30+
+endif
31+
+
32+
# Build the kernel release string
33+
# The KERNELRELEASE is stored in a file named .kernelrelease
34+
# to be used when executing for example make install or make modules_install

meta/recipes-core/busybox/busybox/parallel-make-fix.patch

Lines changed: 0 additions & 65 deletions
This file was deleted.

meta/recipes-core/busybox/busybox_1.24.1.bb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ SRC_URI = "http://www.busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
4949
file://CVE-2016-2147_2.patch \
5050
file://ip_fix_problem_on_mips64_n64_big_endian_musl_systems.patch \
5151
file://makefile-fix-backport.patch \
52-
file://parallel-make-fix.patch \
5352
file://0001-sed-fix-sed-n-flushes-pattern-space-terminates-early.patch \
53+
file://busybox-kbuild-race-fix-commit-d8e61bb.patch \
54+
file://commit-applet_tables-fix-commit-0dddbc1.patch \
55+
file://makefile-libbb-race.patch \
5456
"
5557
SRC_URI_append_libc-musl = " file://musl.cfg "
5658

0 commit comments

Comments
 (0)