Commit da4288b9 authored by Masahiro Yamada's avatar Masahiro Yamada

scripts/check-local-export: avoid 'wait $!' for process substitution

Bash 4.4, released in 2016, supports 'wait $!' to check the exit status
of a process substitution, but it seems too new.

Some people using older bash versions (on CentOS 7, Ubuntu 16.04, etc.)
reported an error like this:

  ./scripts/check-local-export: line 54: wait: pid 17328 is not a child of this shell

I used the process substitution to avoid a pipeline, which executes each
command in a subshell. If the while-loop is executed in the subshell
context, variable changes within are lost after the subshell terminates.

Fortunately, Bash 4.2, released in 2011, supports the 'lastpipe' option,
which makes the last element of a pipeline run in the current shell process.

Switch to the pipeline with 'lastpipe' solution, and also set 'pipefail'
to catch errors from ${NM}.

Add the bash requirement to Documentation/process/changes.rst.

Fixes: 31cb50b5 ("kbuild: check static EXPORT_SYMBOL* by script instead of modpost")
Reported-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Reported-by: default avatarWang Yugui <wangyugui@e16-tech.com>
Tested-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: default avatarJon Hunter <jonathanh@nvidia.com>
Acked-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 49c3ca34
...@@ -32,6 +32,7 @@ you probably needn't concern yourself with pcmciautils. ...@@ -32,6 +32,7 @@ you probably needn't concern yourself with pcmciautils.
GNU C 5.1 gcc --version GNU C 5.1 gcc --version
Clang/LLVM (optional) 11.0.0 clang --version Clang/LLVM (optional) 11.0.0 clang --version
GNU make 3.81 make --version GNU make 3.81 make --version
bash 4.2 bash --version
binutils 2.23 ld -v binutils 2.23 ld -v
flex 2.5.35 flex --version flex 2.5.35 flex --version
bison 2.0 bison --version bison 2.0 bison --version
...@@ -84,6 +85,12 @@ Make ...@@ -84,6 +85,12 @@ Make
You will need GNU make 3.81 or later to build the kernel. You will need GNU make 3.81 or later to build the kernel.
Bash
----
Some bash scripts are used for the kernel build.
Bash 4.2 or newer is needed.
Binutils Binutils
-------- --------
...@@ -362,6 +369,11 @@ Make ...@@ -362,6 +369,11 @@ Make
- <ftp://ftp.gnu.org/gnu/make/> - <ftp://ftp.gnu.org/gnu/make/>
Bash
----
- <ftp://ftp.gnu.org/gnu/bash/>
Binutils Binutils
-------- --------
......
...@@ -8,11 +8,31 @@ ...@@ -8,11 +8,31 @@
set -e set -e
# catch errors from ${NM}
set -o pipefail
# Run the last element of a pipeline in the current shell.
# Without this, the while-loop would be executed in a subshell, and
# the changes made to 'symbol_types' and 'export_symbols' would be lost.
shopt -s lastpipe
declare -A symbol_types declare -A symbol_types
declare -a export_symbols declare -a export_symbols
exit_code=0 exit_code=0
# 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.
#
# TODO:
# 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:
# ${NM} --quiet ${1} |
{ ${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } } |
while read value type name while read value type name
do do
# Skip the line if the number of fields is less than 3. # Skip the line if the number of fields is less than 3.
...@@ -37,21 +57,7 @@ do ...@@ -37,21 +57,7 @@ do
if [[ ${name} == __ksymtab_* ]]; then if [[ ${name} == __ksymtab_* ]]; then
export_symbols+=(${name#__ksymtab_}) export_symbols+=(${name#__ksymtab_})
fi fi
done
# 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 $!
for name in "${export_symbols[@]}" for name in "${export_symbols[@]}"
do do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment