Skip to content

Commit da4288b

Browse files
committed
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: 31cb50b ("kbuild: check static EXPORT_SYMBOL* by script instead of modpost") Reported-by: Tetsuo Handa <[email protected]> Reported-by: Michael Ellerman <[email protected]> Reported-by: Wang Yugui <[email protected]> Tested-by: Tetsuo Handa <[email protected]> Tested-by: Jon Hunter <[email protected]> Acked-by: Nick Desaulniers <[email protected]> Tested-by: Sedat Dilek <[email protected]> # LLVM-14 (x86-64) Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 49c3ca3 commit da4288b

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

Documentation/process/changes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ you probably needn't concern yourself with pcmciautils.
3232
GNU C 5.1 gcc --version
3333
Clang/LLVM (optional) 11.0.0 clang --version
3434
GNU make 3.81 make --version
35+
bash 4.2 bash --version
3536
binutils 2.23 ld -v
3637
flex 2.5.35 flex --version
3738
bison 2.0 bison --version
@@ -84,6 +85,12 @@ Make
8485

8586
You will need GNU make 3.81 or later to build the kernel.
8687

88+
Bash
89+
----
90+
91+
Some bash scripts are used for the kernel build.
92+
Bash 4.2 or newer is needed.
93+
8794
Binutils
8895
--------
8996

@@ -362,6 +369,11 @@ Make
362369

363370
- <ftp://ftp.gnu.org/gnu/make/>
364371

372+
Bash
373+
----
374+
375+
- <ftp://ftp.gnu.org/gnu/bash/>
376+
365377
Binutils
366378
--------
367379

scripts/check-local-export

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,31 @@
88

99
set -e
1010

11+
# catch errors from ${NM}
12+
set -o pipefail
13+
14+
# Run the last element of a pipeline in the current shell.
15+
# Without this, the while-loop would be executed in a subshell, and
16+
# the changes made to 'symbol_types' and 'export_symbols' would be lost.
17+
shopt -s lastpipe
18+
1119
declare -A symbol_types
1220
declare -a export_symbols
1321

1422
exit_code=0
1523

24+
# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) shows
25+
# 'no symbols' diagnostic (but exits with 0). It is harmless and hidden by
26+
# '2>/dev/null'. However, it suppresses real error messages as well. Add a
27+
# hand-crafted error message here.
28+
#
29+
# TODO:
30+
# Use --quiet instead of 2>/dev/null when we upgrade the minimum version of
31+
# binutils to 2.37, llvm to 13.0.0.
32+
# Then, the following line will be really simple:
33+
# ${NM} --quiet ${1} |
34+
35+
{ ${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } } |
1636
while read value type name
1737
do
1838
# Skip the line if the number of fields is less than 3.
@@ -37,21 +57,7 @@ do
3757
if [[ ${name} == __ksymtab_* ]]; then
3858
export_symbols+=(${name#__ksymtab_})
3959
fi
40-
41-
# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm)
42-
# shows 'no symbols' diagnostic (but exits with 0). It is harmless and
43-
# hidden by '2>/dev/null'. However, it suppresses real error messages
44-
# as well. Add a hand-crafted error message here.
45-
#
46-
# Use --quiet instead of 2>/dev/null when we upgrade the minimum version
47-
# of binutils to 2.37, llvm to 13.0.0.
48-
#
49-
# Then, the following line will be really simple:
50-
# done < <(${NM} --quiet ${1})
51-
done < <(${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } )
52-
53-
# Catch error in the process substitution
54-
wait $!
60+
done
5561

5662
for name in "${export_symbols[@]}"
5763
do

0 commit comments

Comments
 (0)