0002-libfwtsiasl-fix-parallel-build-with-GNU-Make-4.4.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. From 65a89b6253ef527ab4bc951eb8f9deba12f0121a Mon Sep 17 00:00:00 2001
  2. From: Julien Olivain <ju.o@free.fr>
  3. Date: Mon, 20 May 2024 11:14:02 +0200
  4. Subject: [PATCH] libfwtsiasl: fix parallel build with GNU Make >= 4.4
  5. When a build host has a large number of cores (like 20+) and GNU Make
  6. version is >= 4.4, fwts randomly fail to build in parallel, with a
  7. "make -j$(nproc)" command, with error:
  8. mv: cannot stat 'dtcompilerparser.tab.c': No such file or directory
  9. mv: cannot stat 'prparser.tab.c': No such file or directory
  10. This issue has been reported here:
  11. https://github.com/fwts/fwts/issues/7
  12. The Makefile.am of libfwtsiasl is using the GNU Make ".NOTPARALLEL"
  13. special target with prerequisites to handle commands generating
  14. multiple outputs (like lex/yacc invocations). See:
  15. https://github.com/fwts/fwts/blob/V24.03.00/src/libfwtsiasl/Makefile.am#L61
  16. First, the .NOTPARALLEL special target _with_ prerequisites is a
  17. feature added in GNU Make 4.4. See:
  18. https://git.savannah.gnu.org/cgit/make.git/commit/?id=f6ea899d83bf00fe9201fde0ca9cf7af8e443677
  19. https://lists.gnu.org/archive/html/help-make/2022-10/msg00020.html
  20. GNU Make version < 4.4 will interpret it as if it was written without
  21. prerequisite (as a standalone ".NOTPARALLEL:"). The effect is that the
  22. parallel compilation is disabled for the whole libfwtsiasl. The
  23. standalone .NOTPARALLEL special target was introduced in GNU Make 3.79
  24. in 2000. This is why parallel builds are working with Make older than
  25. version 4.4.
  26. Secondly, the reason why the build is failing on GNU Make >= 4.4 is
  27. because the usage of .NOTPARALLEL in incorrect.
  28. Quoting the Make manual:
  29. https://www.gnu.org/software/make/manual/html_node/Parallel-Disable.html
  30. """
  31. If the .NOTPARALLEL special target has prerequisites, then each of those
  32. prerequisites will be considered a target and all prerequisites of these
  33. targets will be run serially.
  34. """
  35. Note the serialization will happen on the prerequisites of the targets
  36. set as prerequisites of .NOTPARALLEL.
  37. The targets will not be correctly marked to disable parallel
  38. execution.
  39. Thirdly, the use of multiple targets in a rule is incorrect here. See
  40. Make manual:
  41. https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html
  42. The construct used in Makefile.am of libfwtsiasl for lex/yacc parsers
  43. assumes they are independant targets (so they can be executed in
  44. parallel). Finally, the "mv" command is failing, because there will be
  45. one parallel execution per target, the first mv will suceed and the
  46. other ones will fail. Multiple independant targets are often used in
  47. Makefiles for lex/yacc, they are working because they are not using
  48. "mv". Even in multiple execution, files are just overwritten.
  49. Fixing this .NOTPARALLEL usage with prerequisites would require Make
  50. version 4.4 or greater. This is a strong requirement, as there is
  51. still many Linux distros with older Make version (as an example Ubuntu
  52. 22.04 LTS has Make 4.3).
  53. The .WAIT special target could be used, but was also introduced in
  54. Make version 4.4. See:
  55. https://git.savannah.gnu.org/cgit/make.git/commit/?id=f6ea899d83bf00fe9201fde0ca9cf7af8e443677
  56. GNU Make 4.3 also introduced "Grouped Targets" for that purpose. See:
  57. https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html
  58. But this would add a requirement on a recent Make version.
  59. This commit fixes the issue by declaring the first generated file as a
  60. dependency of the other extra generated files. This has the effect of
  61. completely solving the parallel build for all GNU Make versions. Also,
  62. this enables parallel build for libfwtsiasl (except for the parser
  63. generation) and makes the whole build faster.
  64. Signed-off-by: Julien Olivain <ju.o@free.fr>
  65. Upstream: https://github.com/fwts/fwts/commit/c0962cd74c725418523c46ca44101e0e70201f81
  66. ---
  67. src/libfwtsiasl/Makefile.am | 16 ++++++++--------
  68. 1 file changed, 8 insertions(+), 8 deletions(-)
  69. diff --git a/src/libfwtsiasl/Makefile.am b/src/libfwtsiasl/Makefile.am
  70. index cb10bc58..ac54f621 100644
  71. --- a/src/libfwtsiasl/Makefile.am
  72. +++ b/src/libfwtsiasl/Makefile.am
  73. @@ -58,32 +58,32 @@ aslcompiler.y: $(ASL_PARSER)
  74. aslcompilerlex.c: $(ASL_LEXER)
  75. ${LEX} ${AM_LFLAGS} -PAslCompiler -o$@ $(top_srcdir)/src/acpica/source/compiler/aslcompiler.l
  76. -.NOTPARALLEL: aslcompiler.c
  77. -aslcompiler.c aslcompiler.y.h: aslcompiler.y
  78. +aslcompiler.c: aslcompiler.y
  79. ${YACC} ${AM_YFLAGS} -d -baslcompiler -pAslCompiler $^
  80. mv aslcompiler.tab.c aslcompiler.c
  81. cp aslcompiler.tab.h aslcompiler.y.h
  82. +aslcompiler.y.h: aslcompiler.c
  83. -.NOTPARALLEL: dtcompilerparserlex.c
  84. -dtcompilerparserlex.c dtcompilerparser.c dtcompilerparser.y.h: $(top_srcdir)/src/acpica/source/compiler/dtcompilerparser.l $(top_srcdir)/src/acpica/source/compiler/dtcompilerparser.y
  85. +dtcompilerparserlex.c: $(top_srcdir)/src/acpica/source/compiler/dtcompilerparser.l $(top_srcdir)/src/acpica/source/compiler/dtcompilerparser.y
  86. ${LEX} ${AM_LFLAGS} -PDtCompilerParser -odtcompilerparserlex.c $<
  87. ${YACC} ${AM_YFLAGS} -bdtcompilerparser -pDtCompilerParser $(top_srcdir)/src/acpica/source/compiler/dtcompilerparser.y
  88. mv dtcompilerparser.tab.c dtcompilerparser.c
  89. cp dtcompilerparser.tab.h dtcompilerparser.y.h
  90. +dtcompilerparser.c dtcompilerparser.y.h: dtcompilerparserlex.c
  91. -.NOTPARALLEL: dtparserlex.c
  92. -dtparserlex.c dtparser.c dtparser.y.h: $(top_srcdir)/src/acpica/source/compiler/dtparser.l $(top_srcdir)/src/acpica/source/compiler/dtparser.y
  93. +dtparserlex.c: $(top_srcdir)/src/acpica/source/compiler/dtparser.l $(top_srcdir)/src/acpica/source/compiler/dtparser.y
  94. ${LEX} ${AM_LFLAGS} -PDtParser -odtparserlex.c $<
  95. ${YACC} ${AM_YFLAGS} -bdtparser -pDtParser $(top_srcdir)/src/acpica/source/compiler/dtparser.y
  96. mv dtparser.tab.c dtparser.c
  97. cp dtparser.tab.h dtparser.y.h
  98. +dtparser.c dtparser.y.h: dtparserlex.c
  99. -.NOTPARALLEL: prparserlex.c
  100. -prparserlex.c prparser.c prparser.y.h: $(top_srcdir)/src/acpica/source/compiler/prparser.l $(top_srcdir)/src/acpica/source/compiler/prparser.y
  101. +prparserlex.c: $(top_srcdir)/src/acpica/source/compiler/prparser.l $(top_srcdir)/src/acpica/source/compiler/prparser.y
  102. ${LEX} ${AM_LFLAGS} -PPrParser -oprparserlex.c $<
  103. ${YACC} ${AM_YFLAGS} -bprparser -pPrParser $(top_srcdir)/src/acpica/source/compiler/prparser.y
  104. mv prparser.tab.c prparser.c
  105. cp prparser.tab.h prparser.y.h
  106. +prparser.c prparser.y.h: prparserlex.c
  107. pkglib_LTLIBRARIES = libfwtsiasl.la
  108. --
  109. 2.45.1