|
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.
|
|
37 | 57 | if [[ ${name} == __ksymtab_* ]]; then
|
38 | 58 | export_symbols+=(${name#__ksymtab_})
|
39 | 59 | 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 |
55 | 61 |
|
56 | 62 | for name in "${export_symbols[@]}"
|
57 | 63 | do
|
|
0 commit comments