PR #26036 opened by Ramiro Polla (ramiro) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26036 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26036.patch
Based on top of !26030, which saved about 0.4s of configure's time by speeding up some shell commands, this series saves about 0.76s on Linux and almost 2 minutes on Windows 11 ARM64 by reducing the number of subshells, which are notoriously slow on Windows: https://github.com/microsoft/Windows-Dev-Performance/issues/15 I'd appreciate tests by more exotic systems, since this entire series was tested using `dash`, on Linux and on MSYS2. I'd also appreciate benchmarks on a normal x86_64 Windows system, since my tests were made on a Raspberry Pi 5. >From 8a3d77c5a690003670850cc9e730d5a355c3a1f2 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Thu, 12 Nov 2026 14:09:14 +0100 Subject: [PATCH 01/12] configure: drop empty extralibs entries before calling unique() Avoid running the quadratic unique() function over components with no extralibs. configure wall time on linux: 6.93s -> 6.77s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configure b/configure index 69793448886..544e5904ea2 100755 --- a/configure +++ b/configure @@ -972,6 +972,16 @@ resolve(){ eval $1=\$resolve_out } +# removes the names of empty variables from the list +drop_empty(){ + drop_empty_out= + eval drop_empty_in=\$$1 + for v in $drop_empty_in; do + eval test -n \"\$$v\" && drop_empty_out="$drop_empty_out$v " + done + eval $1=\$drop_empty_out +} + add_cppflags(){ append CPPFLAGS "$@" } @@ -8188,6 +8198,7 @@ flatten_extralibs(){ flatten_extralibs_wrapper(){ list_name=$1 flatten_extralibs $list_name + drop_empty $list_name unique $list_name resolve $list_name eval $list_name=\$\(\$ldflags_filter \$$list_name\) -- 2.54.0 >From 5893c0b937c02d2e33a1ab41d946c53362a1fe1e Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Thu, 12 Nov 2026 15:39:28 +0100 Subject: [PATCH 02/12] configure: read extralibs entries directly in flatten_extralibs() configure wall time on linux: 6.77s -> 6.64s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 544e5904ea2..a057e71e063 100755 --- a/configure +++ b/configure @@ -8176,10 +8176,9 @@ flatten_extralibs(){ list_name=$1 eval list=\$${1} for entry in $list; do - entry_copy=$entry - resolve entry_copy + eval entry_value=\$$entry flat_entries= - for e in $entry_copy; do + for e in $entry_value; do case $e in *_extralibs) nested_entries="$nested_entries$e ";; *) flat_entries="$flat_entries$e ";; -- 2.54.0 >From 8bd53bcb3c3af81ca2a147a7944cf663168a975c Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Thu, 12 Nov 2026 15:39:28 +0100 Subject: [PATCH 03/12] configure: skip already flattened entries in flatten_extralibs() Prevent each recursion level from re-walking entries flattened by earlier levels. configure wall time on linux: 6.64s -> 6.59s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure b/configure index a057e71e063..cacbcb9948a 100755 --- a/configure +++ b/configure @@ -8176,6 +8176,8 @@ flatten_extralibs(){ list_name=$1 eval list=\$${1} for entry in $list; do + eval test -n \"\$${entry}_flattened\" && continue + eval ${entry}_flattened=1 eval entry_value=\$$entry flat_entries= for e in $entry_value; do -- 2.54.0 >From 3e26d7e84f58d05e9366f9541e6c5c75228f23de Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Thu, 12 Nov 2026 16:02:51 +0100 Subject: [PATCH 04/12] configure: flatten extralibs level by level Walk only the entries found at the previous level instead of rescanning the whole list, and drop the forking filter check for further nesting. configure wall time on linux: 6.59s -> 6.53s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/configure b/configure index cacbcb9948a..873be1e39fe 100755 --- a/configure +++ b/configure @@ -8172,28 +8172,28 @@ if ! enabled_any memalign posix_memalign aligned_malloc; then fi flatten_extralibs(){ - nested_entries= list_name=$1 eval list=\$${1} - for entry in $list; do - eval test -n \"\$${entry}_flattened\" && continue - eval ${entry}_flattened=1 - eval entry_value=\$$entry - flat_entries= - for e in $entry_value; do - case $e in - *_extralibs) nested_entries="$nested_entries$e ";; - *) flat_entries="$flat_entries$e ";; - esac + flatten_all= + while test -n "$list"; do + flatten_all="$flatten_all$list " + nested_entries= + for entry in $list; do + eval test -n \"\$${entry}_flattened\" && continue + eval ${entry}_flattened=1 + eval entry_value=\$$entry + flat_entries= + for e in $entry_value; do + case $e in + *_extralibs) nested_entries="$nested_entries$e ";; + *) flat_entries="$flat_entries$e ";; + esac + done + eval $entry="\$flat_entries" done - eval $entry="\$flat_entries" + list=$nested_entries done - append $list_name "$nested_entries" - - resolve nested_entries - if test -n "$(filter '*_extralibs' $nested_entries)"; then - flatten_extralibs $list_name - fi + eval $list_name=\$flatten_all } flatten_extralibs_wrapper(){ -- 2.54.0 >From 474befeb124e96a0dbb1a552dde8a10aceb28c06 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Tue, 10 Nov 2026 01:14:41 +0100 Subject: [PATCH 05/12] configure: sanitize variable names without forking Replace the echo | sed subshell in sanitize_var_name(), which runs for every checked header, type and struct, with shell pattern removal. configure wall time on linux: 6.53s -> 6.28s configure wall time on win-arm64: 217s -> 195s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/configure b/configure index 873be1e39fe..01013e9eb52 100755 --- a/configure +++ b/configure @@ -676,18 +676,30 @@ set_weak(){ done } +# Replace every character that is not valid in a variable name by '_', +# storing the result in $sanitized. sanitize_var_name(){ - echo $@ | sed 's/[^A-Za-z0-9_]/_/g' + sanitize_rest=$1 + sanitized= + while :; do + sanitize_pre=${sanitize_rest%%[!A-Za-z0-9_]*} + test "$sanitize_pre" = "$sanitize_rest" && break + sanitized=$sanitized${sanitize_pre}_ + sanitize_rest=${sanitize_rest#"$sanitize_pre"?} + done + sanitized=$sanitized$sanitize_rest } set_sanitized(){ var=$1 shift - eval $(sanitize_var_name "$var")='$*' + sanitize_var_name "$var" + eval $sanitized='$*' } get_sanitized(){ - eval echo \$$(sanitize_var_name "$1") + sanitize_var_name "$1" + eval echo \$$sanitized } pushvar(){ @@ -748,13 +760,15 @@ disable_weak(){ enable_sanitized(){ for var; do - enable $(sanitize_var_name $var) + sanitize_var_name "$var" + enable $sanitized done } disable_sanitized(){ for var; do - disable $(sanitize_var_name $var) + sanitize_var_name "$var" + disable $sanitized done } -- 2.54.0 >From 785da63c8efac42942a78484b8139dc6732e51b8 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Fri, 13 Nov 2026 14:58:25 +0100 Subject: [PATCH 06/12] configure: write the test sources without forking cat All callers pass newline-terminated text. configure wall time on linux: 6.28s -> 6.14s configure wall time on win-arm64: 195s -> 177s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/configure b/configure index 01013e9eb52..6aaa09300d9 100755 --- a/configure +++ b/configure @@ -1122,30 +1122,37 @@ nvcc_o(){ eval printf '%s\\n' $NVCC_O } +# A shell-only cat for small newline-terminated text inputs. +shcat(){ + while IFS= read -r shcat_line; do + printf '%s\n' "$shcat_line" + done +} + test_cc(){ log test_cc "$@" - cat > $TMPC + shcat > $TMPC log_file $TMPC test_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $(cc_o $TMPO) $TMPC } test_cxx(){ log test_cxx "$@" - cat > $TMPCPP + shcat > $TMPCPP log_file $TMPCPP test_cmd $cxx $CPPFLAGS $CXXFLAGS "$@" $CXX_C $(cxx_o $TMPO) $TMPCPP } test_objcc(){ log test_objcc "$@" - cat > $TMPM + shcat > $TMPM log_file $TMPM test_cmd $objcc -Werror=missing-prototypes $CPPFLAGS $CFLAGS $OBJCFLAGS "$@" $OBJCC_C $(cc_o $TMPO) $TMPM } test_glslc(){ log test_glslc "$@" - cat > $TMPGLSL + shcat > $TMPGLSL log_file $TMPGLSL test_cmd $glslc $GLSLCFLAGS $glslcflags "$@" $(glslc_o $TMPO) $TMPGLSL } @@ -1165,7 +1172,7 @@ EOF test_nvcc(){ log test_nvcc "$@" - cat > $TMPCU + shcat > $TMPCU log_file $TMPCU tmpcu_=$TMPCU tmpo_=$TMPO @@ -1188,14 +1195,14 @@ EOF test_cpp(){ log test_cpp "$@" - cat > $TMPC + shcat > $TMPC log_file $TMPC test_cmd $cc $CPPFLAGS $CFLAGS "$@" $(cc_e $TMPO) $TMPC } test_as(){ log test_as "$@" - cat > $TMPS + shcat > $TMPS log_file $TMPS test_cmd $as $CPPFLAGS $ASFLAGS "$@" $AS_C $(as_o $TMPO) $TMPS } @@ -1249,7 +1256,7 @@ check_inline_asm_flags(){ shift done; disable $name - cat > $TMPC <<EOF + shcat > $TMPC <<EOF void foo(void){ __asm__ volatile($code); } EOF log_file $TMPC @@ -1850,7 +1857,7 @@ require_pkg_config_cxx(){ test_host_cc(){ log test_host_cc "$@" - cat > $TMPC + shcat > $TMPC log_file $TMPC test_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC } @@ -1867,7 +1874,7 @@ test_host_ld(){ test_host_cpp(){ log test_host_cpp "$@" - cat > $TMPC + shcat > $TMPC log_file $TMPC test_cmd $host_cc $host_cppflags $host_cflags "$@" $(hostcc_e $TMPO) $TMPC } -- 2.54.0 >From 547ccbdad863b92bf63e66c5a5dab5b4cf6669a5 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Fri, 13 Nov 2026 14:59:26 +0100 Subject: [PATCH 07/12] configure: expand the output templates without subshells configure wall time on linux: 6.14s -> 6.04s configure wall time on win-arm64: 177s -> 151s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 92 +++++++++++++++++++------------------------------------ 1 file changed, 32 insertions(+), 60 deletions(-) diff --git a/configure b/configure index 6aaa09300d9..ef9bf6deea9 100755 --- a/configure +++ b/configure @@ -1074,52 +1074,11 @@ test_stat(){ stat "$1" >> $logfile 2>&1 } -cc_e(){ - eval printf '%s\\n' $CC_E -} - -cc_o(){ - eval printf '%s\\n' $CC_O -} - -cxx_e(){ - eval printf '%s\\n' $CXX_E -} - -cxx_o(){ - eval printf '%s\\n' $CXX_O -} - -as_o(){ - eval printf '%s\\n' $AS_O -} - -x86asm_o(){ - eval printf '%s\\n' $X86ASM_O -} - -ld_o(){ - eval printf '%s\\n' $LD_O -} - -hostcc_e(){ - eval printf '%s\\n' $HOSTCC_E -} - -hostcc_o(){ - eval printf '%s\\n' $HOSTCC_O -} - -hostld_o(){ - eval printf '%s\\n' $HOSTLD_O -} - -glslc_o(){ - eval printf '%s\\n' $GLSLC_O -} - -nvcc_o(){ - eval printf '%s\\n' $NVCC_O +expand_o(){ + expand_o_var=$1 + expand_o_tmpl=$2 + shift 2 + eval $expand_o_var=\"$expand_o_tmpl\" } # A shell-only cat for small newline-terminated text inputs. @@ -1133,28 +1092,32 @@ test_cc(){ log test_cc "$@" shcat > $TMPC log_file $TMPC - test_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $(cc_o $TMPO) $TMPC + expand_o cc_out "$CC_O" $TMPO + test_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $cc_out $TMPC } test_cxx(){ log test_cxx "$@" shcat > $TMPCPP log_file $TMPCPP - test_cmd $cxx $CPPFLAGS $CXXFLAGS "$@" $CXX_C $(cxx_o $TMPO) $TMPCPP + expand_o cxx_out "$CXX_O" $TMPO + test_cmd $cxx $CPPFLAGS $CXXFLAGS "$@" $CXX_C $cxx_out $TMPCPP } test_objcc(){ log test_objcc "$@" shcat > $TMPM log_file $TMPM - test_cmd $objcc -Werror=missing-prototypes $CPPFLAGS $CFLAGS $OBJCFLAGS "$@" $OBJCC_C $(cc_o $TMPO) $TMPM + expand_o cc_out "$CC_O" $TMPO + test_cmd $objcc -Werror=missing-prototypes $CPPFLAGS $CFLAGS $OBJCFLAGS "$@" $OBJCC_C $cc_out $TMPM } test_glslc(){ log test_glslc "$@" shcat > $TMPGLSL log_file $TMPGLSL - test_cmd $glslc $GLSLCFLAGS $glslcflags "$@" $(glslc_o $TMPO) $TMPGLSL + expand_o glslc_out "$GLSLC_O" $TMPO + test_cmd $glslc $GLSLCFLAGS $glslcflags "$@" $glslc_out $TMPGLSL } check_glslc(){ @@ -1177,7 +1140,8 @@ test_nvcc(){ tmpcu_=$TMPCU tmpo_=$TMPO [ -x "$(command -v cygpath)" ] && tmpcu_=$(cygpath -m $tmpcu_) && tmpo_=$(cygpath -m $tmpo_) - test_cmd $nvcc $nvccflags "$@" $NVCC_C $(nvcc_o $tmpo_) $tmpcu_ + expand_o nvcc_out "$NVCC_O" $tmpo_ + test_cmd $nvcc $nvccflags "$@" $NVCC_C $nvcc_out $tmpcu_ } check_nvcc() { @@ -1197,14 +1161,16 @@ test_cpp(){ log test_cpp "$@" shcat > $TMPC log_file $TMPC - test_cmd $cc $CPPFLAGS $CFLAGS "$@" $(cc_e $TMPO) $TMPC + expand_o cc_out "$CC_E" $TMPO + test_cmd $cc $CPPFLAGS $CFLAGS "$@" $cc_out $TMPC } test_as(){ log test_as "$@" shcat > $TMPS log_file $TMPS - test_cmd $as $CPPFLAGS $ASFLAGS "$@" $AS_C $(as_o $TMPO) $TMPS + expand_o as_out "$AS_O" $TMPO + test_cmd $as $CPPFLAGS $ASFLAGS "$@" $AS_C $as_out $TMPS } test_x86asm(){ @@ -1212,7 +1178,8 @@ test_x86asm(){ echo "$1" > $TMPASM log_file $TMPASM shift - test_cmd $x86asmexe $X86ASMFLAGS -Werror "$@" $(x86asm_o $TMPO) $TMPASM + expand_o x86asm_out "$X86ASM_O" $TMPO + test_cmd $x86asmexe $X86ASMFLAGS -Werror "$@" $x86asm_out $TMPASM } check_cmd(){ @@ -1260,7 +1227,8 @@ check_inline_asm_flags(){ void foo(void){ __asm__ volatile($code); } EOF log_file $TMPC - test_cmd $cc $CPPFLAGS $CFLAGS $flags "$@" $CC_C $(cc_o $TMPO) $TMPC && + expand_o cc_out "$CC_O" $TMPO + test_cmd $cc $CPPFLAGS $CFLAGS $flags "$@" $CC_C $cc_out $TMPC && enable $name && add_allcflags $flags && add_asflags $flags && add_ldflags $flags } @@ -1336,8 +1304,9 @@ test_ld(){ test_$type $($cflags_filter $flags) || return flags=$($ldflags_filter $flags) libs=$($ldflags_filter $libs) - log $ld $LDFLAGS $LDEXEFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs - output=$($ld $LDFLAGS $LDEXEFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs 2>&1) + expand_o ld_out "$LD_O" $TMPE + log $ld $LDFLAGS $LDEXEFLAGS $flags $ld_out $TMPO $libs $extralibs + output=$($ld $LDFLAGS $LDEXEFLAGS $flags $ld_out $TMPO $libs $extralibs 2>&1) ret=$? echo "$output" >> $logfile # link.exe and lld-link exit 0 even for unrecognized options, emitting @@ -1859,7 +1828,8 @@ test_host_cc(){ log test_host_cc "$@" shcat > $TMPC log_file $TMPC - test_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC + expand_o hostcc_out "$HOSTCC_O" $TMPO + test_cmd $host_cc $host_cflags "$@" $HOSTCC_C $hostcc_out $TMPC } test_host_ld(){ @@ -1869,14 +1839,16 @@ test_host_ld(){ test_host_cc $($host_cflags_filter $flags) || return flags=$($host_ldflags_filter $flags) libs=$($host_ldflags_filter $libs) - test_cmd $host_ld $host_ldflags $flags $(hostld_o $TMPE) $TMPO $libs $host_extralibs + expand_o hostld_out "$HOSTLD_O" $TMPE + test_cmd $host_ld $host_ldflags $flags $hostld_out $TMPO $libs $host_extralibs } test_host_cpp(){ log test_host_cpp "$@" shcat > $TMPC log_file $TMPC - test_cmd $host_cc $host_cppflags $host_cflags "$@" $(hostcc_e $TMPO) $TMPC + expand_o hostcc_out "$HOSTCC_E" $TMPO + test_cmd $host_cc $host_cppflags $host_cflags "$@" $hostcc_out $TMPC } check_host_cppflags(){ -- 2.54.0 >From d6c22537d4904bad1349d7363d67fbdfb765a22b Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Fri, 13 Nov 2026 15:00:01 +0100 Subject: [PATCH 08/12] configure: store the flags filter results in a variable Make the flags filters store their result in $filtered_flags instead of printing it, so that applying them does not need a subshell. configure wall time on linux: 6.04s -> 5.97s configure wall time on win-arm64: 151s -> 136s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 215 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 89 deletions(-) diff --git a/configure b/configure index ef9bf6deea9..e7d1de82c52 100755 --- a/configure +++ b/configure @@ -1001,19 +1001,23 @@ add_cppflags(){ } add_cflags(){ - append CFLAGS $($cflags_filter "$@") + $cflags_filter "$@" + append CFLAGS $filtered_flags } add_cflags_headers(){ - append CFLAGS_HEADERS $($cflags_filter "$@") + $cflags_filter "$@" + append CFLAGS_HEADERS $filtered_flags } add_cxxflags(){ - append CXXFLAGS $($cflags_filter "$@") + $cflags_filter "$@" + append CXXFLAGS $filtered_flags } add_objcflags(){ - append OBJCFLAGS $($objcflags_filter "$@") + $objcflags_filter "$@" + append OBJCFLAGS $filtered_flags } # This also covers ObjC, it inherits CFLAGS. @@ -1023,23 +1027,28 @@ add_allcflags(){ } add_asflags(){ - append ASFLAGS $($asflags_filter "$@") + $asflags_filter "$@" + append ASFLAGS $filtered_flags } add_ldflags(){ - append LDFLAGS $($ldflags_filter "$@") + $ldflags_filter "$@" + append LDFLAGS $filtered_flags } add_ldexeflags(){ - append LDEXEFLAGS $($ldflags_filter "$@") + $ldflags_filter "$@" + append LDEXEFLAGS $filtered_flags } add_ldsoflags(){ - append LDSOFLAGS $($ldflags_filter "$@") + $ldflags_filter "$@" + append LDSOFLAGS $filtered_flags } add_extralibs(){ - prepend extralibs $($ldflags_filter "$@") + $ldflags_filter "$@" + prepend extralibs $filtered_flags } add_stripflags(){ @@ -1051,11 +1060,13 @@ add_host_cppflags(){ } add_host_cflags(){ - append host_cflags $($host_cflags_filter "$@") + $host_cflags_filter "$@" + append host_cflags $filtered_flags } add_host_ldflags(){ - append host_ldflags $($host_ldflags_filter "$@") + $host_ldflags_filter "$@" + append host_ldflags $filtered_flags } add_compat(){ @@ -1081,6 +1092,10 @@ expand_o(){ eval $expand_o_var=\"$expand_o_tmpl\" } +passthrough_flags(){ + filtered_flags=$* +} + # A shell-only cat for small newline-terminated text inputs. shcat(){ while IFS= read -r shcat_line; do @@ -1301,9 +1316,12 @@ test_ld(){ shift 1 flags=$(filter_out '-l*|*.so' $@) libs=$(filter '-l*|*.so' $@) - test_$type $($cflags_filter $flags) || return - flags=$($ldflags_filter $flags) - libs=$($ldflags_filter $libs) + $cflags_filter $flags + test_$type $filtered_flags || return + $ldflags_filter $flags + flags=$filtered_flags + $ldflags_filter $libs + libs=$filtered_flags expand_o ld_out "$LD_O" $TMPE log $ld $LDFLAGS $LDEXEFLAGS $flags $ld_out $TMPO $libs $extralibs output=$($ld $LDFLAGS $LDEXEFLAGS $flags $ld_out $TMPO $libs $extralibs 2>&1) @@ -1354,7 +1372,8 @@ EOF test_cflags(){ log test_cflags "$@" - set -- $($cflags_filter "$@") + $cflags_filter "$@" + set -- $filtered_flags test_cc "$@" <<EOF int x; EOF @@ -1367,7 +1386,8 @@ check_cflags(){ test_cxxflags(){ log test_cxxflags "$@" - set -- $($cflags_filter "$@") + $cflags_filter "$@" + set -- $filtered_flags test_cxx "$@" <<EOF int x; EOF @@ -1380,7 +1400,8 @@ check_cxxflags(){ test_objcflags(){ log test_objcflags "$@" - set -- $($objcflags_filter "$@") + $objcflags_filter "$@" + set -- $filtered_flags test_objcc "$@" <<EOF int x; EOF @@ -1398,7 +1419,8 @@ check_allcflags(){ test_ldflags(){ log test_ldflags "$@" - set -- $($ldflags_filter "$@") + $ldflags_filter "$@" + set -- $filtered_flags test_ld "cc" "$@" <<EOF int main(void){ return 0; } EOF @@ -1539,7 +1561,8 @@ test_cflags_cc(){ header=$2 condition=$3 shift 3 - set -- $($cflags_filter "$flags") + $cflags_filter "$flags" + set -- $filtered_flags test_cc "$@" <<EOF #include <$header> #if !($condition) @@ -1560,7 +1583,8 @@ test_cxxflags_cc(){ header=$2 condition=$3 shift 3 - set -- $($cflags_filter "$flags") + $cflags_filter "$flags" + set -- $filtered_flags test_cxx "$@" <<EOF #include <$header> #if !($condition) @@ -1836,9 +1860,12 @@ test_host_ld(){ log test_host_ld "$@" flags=$(filter_out '-l*|*.so' $@) libs=$(filter '-l*|*.so' $@) - test_host_cc $($host_cflags_filter $flags) || return - flags=$($host_ldflags_filter $flags) - libs=$($host_ldflags_filter $libs) + $host_cflags_filter $flags + test_host_cc $filtered_flags || return + $host_ldflags_filter $flags + flags=$filtered_flags + $host_ldflags_filter $libs + libs=$filtered_flags expand_o hostld_out "$HOSTLD_O" $TMPE test_cmd $host_ld $host_ldflags $flags $hostld_out $TMPO $libs $host_extralibs } @@ -1860,7 +1887,8 @@ EOF check_host_cflags(){ log check_host_cflags "$@" - set -- $($host_cflags_filter "$@") + $host_cflags_filter "$@" + set -- $filtered_flags test_host_cc "$@" <<EOF && append host_cflags "$@" int x; EOF @@ -1872,7 +1900,8 @@ test_host_cflags_cc(){ header=$2 condition=$3 shift 3 - set -- $($host_cflags_filter "$flags") + $host_cflags_filter "$flags" + set -- $filtered_flags test_host_cc "$@" <<EOF #include <$header> #if !($condition) @@ -4487,10 +4516,10 @@ SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)' SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)' VERSION_SCRIPT_POSTPROCESS_CMD="cat" -asflags_filter=echo -cflags_filter=echo -objcflags_filter=echo -ldflags_filter=echo +asflags_filter=passthrough_flags +cflags_filter=passthrough_flags +objcflags_filter=passthrough_flags +ldflags_filter=passthrough_flags AS_C='-c' AS_O='-o $@' @@ -4515,8 +4544,8 @@ NVCC_C='-c' NVCC_O='-o $@' host_extralibs= -host_cflags_filter=echo -host_ldflags_filter=echo +host_cflags_filter=passthrough_flags +host_ldflags_filter=passthrough_flags target_path='$(CURDIR)' @@ -5155,6 +5184,7 @@ EOF fi armasm_flags(){ + filtered_flags= for flag; do case $flag in # Filter out MSVC cl.exe options from cflags that shouldn't @@ -5162,12 +5192,13 @@ armasm_flags(){ -M[TD]*) ;; -guard:signret) ;; -experimental:*) ;; - *) echo $flag ;; + *) append filtered_flags $flag ;; esac done } msvc_common_flags(){ + filtered_flags= for flag; do case $flag in # In addition to specifying certain flags under the compiler @@ -5175,11 +5206,11 @@ msvc_common_flags(){ # generic catch all at the bottom will print the original flag. -Wall) ;; -Wextra) ;; - -Werror) echo -WX ;; - -std=c*) echo /std:${flag#-std=};; + -Werror) append filtered_flags -WX ;; + -std=c*) append filtered_flags /std:${flag#-std=};; # Common flags -fomit-frame-pointer) ;; - -g) echo -Z7 ;; + -g) append filtered_flags -Z7 ;; -fno-math-errno) ;; -fno-common) ;; -fno-signed-zeros) ;; @@ -5187,16 +5218,16 @@ msvc_common_flags(){ -mthumb) ;; -march=*) ;; -mfp16-format=*) ;; - -lz) echo ${zlib_msvc_lib:-zlib.lib} ;; - -lx264) echo libx264.lib ;; + -lz) append filtered_flags ${zlib_msvc_lib:-zlib.lib} ;; + -lx264) append filtered_flags libx264.lib ;; -lstdc++) ;; - -l*) echo ${flag#-l}.lib ;; - -LARGEADDRESSAWARE) echo $flag ;; - -L*) [ "$_flags_type" != "link" ] || echo -libpath:${flag#-L} ;; - -I*) [ "$_flags_type" = "link" ] || echo $flag ;; - -D*) [ "$_flags_type" = "link" ] || echo $flag ;; + -l*) append filtered_flags ${flag#-l}.lib ;; + -LARGEADDRESSAWARE) append filtered_flags $flag ;; + -L*) [ "$_flags_type" != "link" ] || append filtered_flags -libpath:${flag#-L} ;; + -I*) [ "$_flags_type" = "link" ] || append filtered_flags $flag ;; + -D*) [ "$_flags_type" = "link" ] || append filtered_flags $flag ;; -Wl,*) ;; - *) echo $flag ;; + *) append filtered_flags $flag ;; esac done } @@ -5205,13 +5236,13 @@ msvc_flags(){ msvc_common_flags "$@" for flag; do case $flag in - -Wall) echo -W3 -wd4018 -wd4146 -wd4244 -wd4305 \ - -wd4554 -wd4267 ;; - -Wextra) echo -W4 -wd4244 -wd4127 -wd4018 -wd4389 \ - -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \ - -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \ - -wd4307 \ - -wd4273 -wd4554 -wd4701 -wd4703 ;; + -Wall) append filtered_flags -W3 -wd4018 -wd4146 -wd4244 -wd4305 \ + -wd4554 -wd4267 ;; + -Wextra) append filtered_flags -W4 -wd4244 -wd4127 -wd4018 -wd4389 \ + -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \ + -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \ + -wd4307 \ + -wd4273 -wd4554 -wd4701 -wd4703 ;; esac done } @@ -5228,62 +5259,64 @@ icl_flags(){ case $flag in # Despite what Intel's documentation says -Wall, which is supported # on Windows, does enable remarks so disable them here. - -Wall) echo $flag -Qdiag-disable:remark ;; - -std=$stdc) echo -Qstd=$stdc ;; - -flto*) echo -ipo ;; + -Wall) append filtered_flags $flag -Qdiag-disable:remark ;; + -std=$stdc) append filtered_flags -Qstd=$stdc ;; + -flto*) append filtered_flags -ipo ;; esac done } icc_flags(){ + filtered_flags= for flag; do case $flag in - -flto*) echo -ipo ;; - *) echo $flag ;; + -flto*) append filtered_flags -ipo ;; + *) append filtered_flags $flag ;; esac done } suncc_flags(){ + filtered_flags= for flag; do case $flag in -march=*|-mcpu=*) case "${flag#*=}" in - native) echo -xtarget=native ;; - v9|niagara) echo -xarch=sparc ;; - ultrasparc) echo -xarch=sparcvis ;; - ultrasparc3|niagara2) echo -xarch=sparcvis2 ;; - i586|pentium) echo -xchip=pentium ;; - i686|pentiumpro|pentium2) echo -xtarget=pentium_pro ;; - pentium3*|c3-2) echo -xtarget=pentium3 ;; - pentium-m) echo -xarch=sse2 -xchip=pentium3 ;; - pentium4*) echo -xtarget=pentium4 ;; - prescott|nocona) echo -xarch=sse3 -xchip=pentium4 ;; - *-sse3) echo -xarch=sse3 ;; - core2) echo -xarch=ssse3 -xchip=core2 ;; - bonnell) echo -xarch=ssse3 ;; - corei7|nehalem) echo -xtarget=nehalem ;; - westmere) echo -xtarget=westmere ;; - silvermont) echo -xarch=sse4_2 ;; - corei7-avx|sandybridge) echo -xtarget=sandybridge ;; + native) append filtered_flags -xtarget=native ;; + v9|niagara) append filtered_flags -xarch=sparc ;; + ultrasparc) append filtered_flags -xarch=sparcvis ;; + ultrasparc3|niagara2) append filtered_flags -xarch=sparcvis2 ;; + i586|pentium) append filtered_flags -xchip=pentium ;; + i686|pentiumpro|pentium2) append filtered_flags -xtarget=pentium_pro ;; + pentium3*|c3-2) append filtered_flags -xtarget=pentium3 ;; + pentium-m) append filtered_flags -xarch=sse2 -xchip=pentium3 ;; + pentium4*) append filtered_flags -xtarget=pentium4 ;; + prescott|nocona) append filtered_flags -xarch=sse3 -xchip=pentium4 ;; + *-sse3) append filtered_flags -xarch=sse3 ;; + core2) append filtered_flags -xarch=ssse3 -xchip=core2 ;; + bonnell) append filtered_flags -xarch=ssse3 ;; + corei7|nehalem) append filtered_flags -xtarget=nehalem ;; + westmere) append filtered_flags -xtarget=westmere ;; + silvermont) append filtered_flags -xarch=sse4_2 ;; + corei7-avx|sandybridge) append filtered_flags -xtarget=sandybridge ;; core-avx*|ivybridge|haswell|broadwell|skylake*|knl) - echo -xarch=avx ;; - amdfam10|barcelona) echo -xtarget=barcelona ;; - btver1) echo -xarch=amdsse4a ;; - btver2|bdver*|znver*) echo -xarch=avx ;; - athlon-4|athlon-[mx]p) echo -xarch=ssea ;; + append filtered_flags -xarch=avx ;; + amdfam10|barcelona) append filtered_flags -xtarget=barcelona ;; + btver1) append filtered_flags -xarch=amdsse4a ;; + btver2|bdver*|znver*) append filtered_flags -xarch=avx ;; + athlon-4|athlon-[mx]p) append filtered_flags -xarch=ssea ;; k8|opteron|athlon64|athlon-fx) - echo -xarch=sse2a ;; - athlon*) echo -xarch=pentium_proa ;; + append filtered_flags -xarch=sse2a ;; + athlon*) append filtered_flags -xarch=pentium_proa ;; esac ;; - -std=$stdc) echo -x$stdc ;; - -fomit-frame-pointer) echo -xregs=frameptr ;; - -fPIC) echo -KPIC -xcode=pic32 ;; - -W*,*) echo $flag ;; - -f*-*|-W*|-mimpure-text) ;; - -shared) echo -G ;; - *) echo $flag ;; + -std=$stdc) append filtered_flags -x$stdc ;; + -fomit-frame-pointer) append filtered_flags -xregs=frameptr ;; + -fPIC) append filtered_flags -KPIC -xcode=pic32 ;; + -W*,*) append filtered_flags $flag ;; + -f*-*|-W*|-mimpure-text) ;; + -shared) append filtered_flags -G ;; + *) append filtered_flags $flag ;; esac done } @@ -5295,7 +5328,7 @@ probe_cc(){ unset _type _ident _cc_c _cc_e _cc_o _flags _cflags _cxxflags unset _ld_o _ldflags _ld_lib _ld_path unset _depflags _DEPCMD _DEPFLAGS _DEPCCFLAGS _DEPCXXFLAGS - _flags_filter=echo + _flags_filter=passthrough_flags if $_cc --version 2>&1 | grep -q '^GNU assembler'; then true # no-op to avoid reading stdin in following checks @@ -8195,7 +8228,8 @@ flatten_extralibs_wrapper(){ drop_empty $list_name unique $list_name resolve $list_name - eval $list_name=\$\(\$ldflags_filter \$$list_name\) + eval \$ldflags_filter \$$list_name + eval $list_name=\$filtered_flags eval printf \''%s'\' \""\$$list_name"\" } @@ -8478,6 +8512,9 @@ echo "config:$arch:$subarch:$cpu:$target_os:$(esc $cc_ident):$(esc $FFMPEG_CONFI enabled stripping || striptype="nostrip" enabled stripping || ASMSTRIPFLAGS="" +$ldflags_filter $SHFLAGS +SHFLAGS=$filtered_flags + config_files="$TMPH ffbuild/config.mak doc/config.texi" cat > ffbuild/config.mak <<EOF @@ -8564,7 +8601,7 @@ MAKEINFO=$makeinfo LDFLAGS=$LDFLAGS LDEXEFLAGS=$LDEXEFLAGS LDSOFLAGS=$LDSOFLAGS -SHFLAGS=$(echo $($ldflags_filter $SHFLAGS)) +SHFLAGS=$SHFLAGS ASMSTRIPFLAGS=$ASMSTRIPFLAGS X86ASMFLAGS=$X86ASMFLAGS MSAFLAGS=$MSAFLAGS -- 2.54.0 >From fb6de429f767b04ff655fc4155a3ee8ab2824c10 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Fri, 13 Nov 2026 15:00:24 +0100 Subject: [PATCH 09/12] configure: split the link arguments without subshells configure wall time on linux: 5.97s -> 5.92s configure wall time on win-arm64: 136s -> 124s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/configure b/configure index e7d1de82c52..f101e43d4eb 100755 --- a/configure +++ b/configure @@ -1096,6 +1096,18 @@ passthrough_flags(){ filtered_flags=$* } +# Split the arguments into libraries and other flags. +split_link_args(){ + split_libs= + split_flags= + for v; do + case $v in + -l*|*.so) split_libs="$split_libs$v " ;; + *) split_flags="$split_flags$v " ;; + esac + done +} + # A shell-only cat for small newline-terminated text inputs. shcat(){ while IFS= read -r shcat_line; do @@ -1314,13 +1326,12 @@ test_ld(){ log test_ld "$@" type=$1 shift 1 - flags=$(filter_out '-l*|*.so' $@) - libs=$(filter '-l*|*.so' $@) - $cflags_filter $flags + split_link_args $@ + $cflags_filter $split_flags test_$type $filtered_flags || return - $ldflags_filter $flags + $ldflags_filter $split_flags flags=$filtered_flags - $ldflags_filter $libs + $ldflags_filter $split_libs libs=$filtered_flags expand_o ld_out "$LD_O" $TMPE log $ld $LDFLAGS $LDEXEFLAGS $flags $ld_out $TMPO $libs $extralibs @@ -1858,13 +1869,12 @@ test_host_cc(){ test_host_ld(){ log test_host_ld "$@" - flags=$(filter_out '-l*|*.so' $@) - libs=$(filter '-l*|*.so' $@) - $host_cflags_filter $flags + split_link_args $@ + $host_cflags_filter $split_flags test_host_cc $filtered_flags || return - $host_ldflags_filter $flags + $host_ldflags_filter $split_flags flags=$filtered_flags - $host_ldflags_filter $libs + $host_ldflags_filter $split_libs libs=$filtered_flags expand_o hostld_out "$HOSTLD_O" $TMPE test_cmd $host_ld $host_ldflags $flags $hostld_out $TMPO $libs $host_extralibs -- 2.54.0 >From 6c553d014a8d898f3412a0a11fef6366de6086b6 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Fri, 13 Nov 2026 15:00:51 +0100 Subject: [PATCH 10/12] configure: check the linker output for warnings without calling grep Also stop dash's echo from cutting the output at a "\c", e.g. in a Windows path, before the warning check sees it. configure wall time on linux: 5.92s -> 5.86s configure wall time on win-arm64: 124s -> 119s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure b/configure index f101e43d4eb..e266295e7eb 100755 --- a/configure +++ b/configure @@ -1341,7 +1341,10 @@ test_ld(){ # link.exe and lld-link exit 0 even for unrecognized options, emitting # only a warning (LNK4044 / "ignoring unknown argument"). Treat such # output as failure so check_ldflags rejects those flags correctly. - test $ret -eq 0 && ! echo "$output" | grep -qE 'LNK4044|lld-link: warning: ignoring unknown argument' + test $ret -eq 0 || return + case $output in + *LNK4044*|*"lld-link: warning: ignoring unknown argument"*) return 1 ;; + esac } check_ld(){ -- 2.54.0 >From 90c507470ed64d3387466911d75a55541bd8e2e2 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Fri, 13 Nov 2026 15:01:56 +0100 Subject: [PATCH 11/12] configure: pass the test_code and check_header* programs without a pipe configure wall time on linux: 5.86s -> 5.81s configure wall time on win-arm64: 119s -> 111s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/configure b/configure index e266295e7eb..7bca3cd3c74 100755 --- a/configure +++ b/configure @@ -1374,7 +1374,8 @@ test_code(){ print_include $hdr done echo "int main(void) { $code; return 0; }" - } | test_$check "$@" + } > $TMPSRC + test_$check "$@" < $TMPSRC } check_cppflags(){ @@ -1469,7 +1470,8 @@ check_headers(){ print_include $hdr done echo "int x;" - } | test_cpp "$@" && enable_sanitized $headers + } > $TMPSRC + test_cpp "$@" < $TMPSRC && enable_sanitized $headers } check_header_objcc(){ @@ -1481,7 +1483,8 @@ check_header_objcc(){ { echo "#include <$header>" echo "int main(void) { return 0; }" - } | test_objcc && test_stat "$TMPO" && enable_sanitized $header + } > $TMPSRC + test_objcc < $TMPSRC && test_stat "$TMPO" && enable_sanitized $header } check_apple_framework(){ @@ -5176,6 +5179,7 @@ tmpfile TMPGLSL .comp.glsl tmpfile TMPO .o tmpfile TMPS .S tmpfile TMPSH .sh +tmpfile TMPSRC .src tmpfile TMPV .ver tmpfile TMPRSP .rsp -- 2.54.0 >From f9547e2617b2262189b7be20a007c419d31ce639 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Fri, 13 Nov 2026 15:02:20 +0100 Subject: [PATCH 12/12] configure: pass the function and class test programs without a pipe configure wall time on linux: 5.81s -> 5.77s configure wall time on win-arm64: 111s -> 106s Signed-off-by: Ramiro Polla <[email protected]> --- configure | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 7bca3cd3c74..de49509d54e 100755 --- a/configure +++ b/configure @@ -1528,7 +1528,8 @@ check_func_headers(){ headers=$1 funcs=$2 shift 2 - print_func_headers_test "$headers" "$funcs" | test_ld "cc" "$@" && + print_func_headers_test "$headers" "$funcs" > $TMPSRC + test_ld "cc" "$@" < $TMPSRC && enable $funcs && enable_sanitized $headers } @@ -1548,7 +1549,8 @@ check_class_headers_cxx(){ i=$(expr $i + 1) done echo "return 0; }" - } | test_ld "cxx" "$@" && enable_sanitized $headers + } > $TMPSRC + test_ld "cxx" "$@" < $TMPSRC && enable_sanitized $headers } test_cpp_condition(){ @@ -1958,7 +1960,8 @@ check_host_lib(){ headers=$1 funcs=$2 shift 2 - print_func_headers_test "$headers" "$funcs" | test_host_ld "$@" && + print_func_headers_test "$headers" "$funcs" > $TMPSRC + test_host_ld "$@" < $TMPSRC && append host_extralibs "$@" } -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
