On Thu, Aug 4, 2022 at 5:12 AM Owen Rafferty <owen@xxxxxxxxxxxxxxxx> wrote: > > On 22/08/03 12:40PM, Masahiro Yamada wrote: > > On Wed, Aug 3, 2022 at 3:49 AM Owen Rafferty <owen@xxxxxxxxxxxxxxxx> wrote: > > > > > > Remove the bash build dependency for those who otherwise do not have it > > > installed. This should also provide a slight speedup. > > > > I do not know if this is worth the effort, > > but do you have any benchmark on how fast it is? > > To be clear, I'm not asking for every single bash script in the tree to be > rewritten in posix shell -- it was only this script that made bash a hard > dependency (on x86 at least). > > For a configuration suitable for my system w/ 4 HT cores: > > bash > real8m 47.79s user54m 30.91s sys13m 56.88s > > sh (dash) > real7m 34.94s user46m 42.63s sys11m 54.02s You need to explain what command you measured. But, never mind. I did it by myself. With x86_64 defconfig build, I got 2824 objects. $ find . -name "*.o" | grep -v vmlinux | wc 2824 2824 78929 Without your patch, $ export NM=nm $ time sh -c 'find . -name "*.o" | grep -v vmlinux | xargs -n1 ./scripts/check-local-export' real 0m58.816s user 0m30.772s sys 0m31.420s With your patch $ export NM=nm $ time sh -c 'find . -name "*.o" | grep -v vmlinux | xargs -n1 ./scripts/check-local-export' real 8m22.922s user 7m53.015s sys 0m30.147s So, it is the opposite. Your patch makes the code extremely slow. More than 8x slower. + type="${symbol_types##* $name,}" + type="${type%% *}" This code is really slow. > > > -# the changes made to 'symbol_types' and 'export_symbols' would be lost. > > > -shopt -s lastpipe > > > - > > > -declare -A symbol_types > > > -declare -a export_symbols > > > +symbol_types="" > > > +export_symbols="" > > > > > > 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 > > > do > > > # Skip the line if the number of fields is less than 3. > > > @@ -46,26 +26,40 @@ do > > > # case 2) > > > # For Clang LTO, llvm-nm outputs a line with type 't' but empty name: > > > # "---------------- t" > > > - if [[ -z ${name} ]]; then > > > + if [ -z ${name} ]; then > > > continue > > > fi > > > > > > - # save (name, type) in the associative array > > > - symbol_types[${name}]=${type} > > > + # save (name, type) in "associative array" > > > + symbol_types="$symbol_types ${name},${type}" > > > > > > # append the exported symbol to the array > > > - if [[ ${name} == __ksymtab_* ]]; then > > > - export_symbols+=(${name#__ksymtab_}) > > > - fi > > > -done > > > + case ${name} in __ksymtab_*) > > > + export_symbols="$export_symbols ${name#__ksymtab_}" > > > + esac > > > > > > -for name in "${export_symbols[@]}" > > > +# 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 simple: > > > +# $(${NM} --quiet ${1} || kill -INT $$) > > > +done <<EOF > > > +$( ${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; kill -INT $$; }) > > > +EOF > > > + > > > +for name in $export_symbols > > > do > > > - # nm(3) says "If lowercase, the symbol is usually local" > > > - if [[ ${symbol_types[$name]} =~ [a-z] ]]; then > > > + type="${symbol_types##* $name,}" > > > + type="${type%% *}" > > > + case ${type} in [a-z]) > > > echo "$@: error: local symbol '${name}' was exported" >&2 > > > exit_code=1 > > > - fi > > > + esac > > > done > > > > > > exit ${exit_code} > > > -- > > > 2.37.1 > > > > > > > > > -- > > Best Regards > > Masahiro Yamada -- Best Regards Masahiro Yamada