scripts/check-local-export | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
scripts/check-local-export fails with some versions of bash.
CC scripts/mod/empty.o
./scripts/check-local-export: line 54: wait: pid 17328 is not a child of this shell
make[2]: *** [scripts/mod/empty.o] Error 127
make[2]: *** Deleting file `scripts/mod/empty.o'
make[1]: *** [prepare0] Error 2
make: *** [__sub-make] Error 2
Avoid use of bash's built-in wait command, by saving the output from
nm command into a temporary variable.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 31cb50b5590fe911 ("kbuild: check static EXPORT_SYMBOL* by script instead of modpost")
---
Changes in v2:
llvm-nm can't use end-of-options argument, reported-by kernel test robot <lkp@intel.com>
scripts/check-local-export | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/scripts/check-local-export b/scripts/check-local-export
index da745e2743b7..850abc150855 100755
--- a/scripts/check-local-export
+++ b/scripts/check-local-export
@@ -11,9 +11,20 @@ set -e
declare -A symbol_types
declare -a export_symbols
+function die
+{
+ echo "$1" >&2
+ exit 1
+}
+
exit_code=0
-while read value type name
+# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm)
+# shows 'no symbols' diagnostic and exits with 0. Saving such line into
+# symbol_types is fine because export_symbols will remain empty.
+result=$(${NM} ${1} 2>&1) || die "${result}"
+
+echo "${result}" | while read value type name
do
# Skip the line if the number of fields is less than 3.
#
@@ -37,21 +48,7 @@ do
if [[ ${name} == __ksymtab_* ]]; then
export_symbols+=(${name#__ksymtab_})
fi
-
- # If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm)
- # shows 'no symbols' diagnostic (but exits with 0). It is harmless and
- # hidden by '2>/dev/null'. However, it suppresses real error messages
- # as well. Add a hand-crafted error message here.
- #
- # Use --quiet instead of 2>/dev/null when we upgrade the minimum version
- # of binutils to 2.37, llvm to 13.0.0.
- #
- # Then, the following line will be really simple:
- # done < <(${NM} --quiet ${1})
-done < <(${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } )
-
-# Catch error in the process substitution
-wait $!
+done
for name in "${export_symbols[@]}"
do
--
2.18.4
On Tue, Jun 7, 2022 at 7:13 AM Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> scripts/check-local-export fails with some versions of bash.
>
> CC scripts/mod/empty.o
> ./scripts/check-local-export: line 54: wait: pid 17328 is not a child of this shell
> make[2]: *** [scripts/mod/empty.o] Error 127
> make[2]: *** Deleting file `scripts/mod/empty.o'
> make[1]: *** [prepare0] Error 2
> make: *** [__sub-make] Error 2
>
> Avoid use of bash's built-in wait command, by saving the output from
> nm command into a temporary variable.
This patch does not work because you did not avoid
running the while-loop in a subshell.
It is well described in this page:
https://riptutorial.com/bash/example/26955/to-avoid-usage-of-a-sub-shell
I will send a working patch with a proper commit log.
The part "Saving such line into symbol_types is fine because export_symbols
will remain empty." seems OK with me.
(I was searching for an elegant solution for this, but
I could not come up with a better one.)
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Fixes: 31cb50b5590fe911 ("kbuild: check static EXPORT_SYMBOL* by script instead of modpost")
> ---
--
Best Regards
Masahiro Yamada
On 2022/06/07 17:34, Masahiro Yamada wrote:
> This patch does not work because you did not avoid
> running the while-loop in a subshell.
>
> It is well described in this page:
> https://riptutorial.com/bash/example/26955/to-avoid-usage-of-a-sub-shell
>
I didn't know that. Then, adding below diff will work.
@@ -24,7 +24,7 @@ exit_code=0
# symbol_types is fine because export_symbols will remain empty.
result=$(${NM} ${1} 2>&1) || die "${result}"
-echo "${result}" | while read value type name
+while read value type name
do
# Skip the line if the number of fields is less than 3.
#
@@ -48,7 +48,9 @@ do
if [[ ${name} == __ksymtab_* ]]; then
export_symbols+=(${name#__ksymtab_})
fi
-done
+done <<EOF
+"${result}"
+EOF
for name in "${export_symbols[@]}"
do
>
>
> I will send a working patch with a proper commit log.
OK. "[PATCH] scripts/check-local-export: avoid 'wait $!' for process substitution" works.
Thank you.
© 2016 - 2026 Red Hat, Inc.