Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 31cb50b5590f ("kbuild: check static EXPORT_SYMBOL* by script instead of modpost")
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Reported-by: Wang Yugui <wangyugui@e16-tech.com>
Tested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+33 -15
+12
Documentation/process/changes.rst
··· 32 32 GNU C 5.1 gcc --version 33 33 Clang/LLVM (optional) 11.0.0 clang --version 34 34 GNU make 3.81 make --version 35 + bash 4.2 bash --version 35 36 binutils 2.23 ld -v 36 37 flex 2.5.35 flex --version 37 38 bison 2.0 bison --version ··· 84 83 ---- 85 84 86 85 You will need GNU make 3.81 or later to build the kernel. 86 + 87 + Bash 88 + ---- 89 + 90 + Some bash scripts are used for the kernel build. 91 + Bash 4.2 or newer is needed. 87 92 88 93 Binutils 89 94 -------- ··· 368 361 ---- 369 362 370 363 - <ftp://ftp.gnu.org/gnu/make/> 364 + 365 + Bash 366 + ---- 367 + 368 + - <ftp://ftp.gnu.org/gnu/bash/> 371 369 372 370 Binutils 373 371 --------
+21 -15
scripts/check-local-export
··· 8 8 9 9 set -e 10 10 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 + 11 19 declare -A symbol_types 12 20 declare -a export_symbols 13 21 14 22 exit_code=0 15 23 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; } } | 16 36 while read value type name 17 37 do 18 38 # Skip the line if the number of fields is less than 3. ··· 57 37 if [[ ${name} == __ksymtab_* ]]; then 58 38 export_symbols+=(${name#__ksymtab_}) 59 39 fi 60 - 61 - # If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) 62 - # shows 'no symbols' diagnostic (but exits with 0). It is harmless and 63 - # hidden by '2>/dev/null'. However, it suppresses real error messages 64 - # as well. Add a hand-crafted error message here. 65 - # 66 - # Use --quiet instead of 2>/dev/null when we upgrade the minimum version 67 - # of binutils to 2.37, llvm to 13.0.0. 68 - # 69 - # Then, the following line will be really simple: 70 - # done < <(${NM} --quiet ${1}) 71 - done < <(${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } ) 72 - 73 - # Catch error in the process substitution 74 - wait $! 40 + done 75 41 76 42 for name in "${export_symbols[@]}" 77 43 do