[PATCH] gcc: configure: Fix the optimization flags cleanup

Currently sed command in flag cleanup removes all the -O[0-9] flags, ignoring
the context. This leads to issues when the optimization flags is passed to
linker:

CFLAGS="-Os -Wl,-O1 -Wl,--hash-style=gnu"
is converted into
CFLAGS="-Os -Wl,-Wl,--hash-style=gnu"

Which leads to configure failure with ld: unrecognized option '-Wl,-Wl'.

gcc/
	* configure.ac: Only remove -O[0-9] if not preceded with comma
	* configure: Regenerated
This commit is contained in:
Slava Barinov 2024-12-01 11:59:13 -07:00 committed by Jeff Law
parent 999aad44aa
commit 721a38add9
2 changed files with 4 additions and 4 deletions

4
gcc/configure vendored
View file

@ -5477,8 +5477,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
# optimizations to be activated explicitly by the toplevel.
case "$CC" in
*/prev-gcc/xgcc*) ;;
*) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[ ]//" -e "s/-O[gs][ ]//" -e "s/-O[0-9]*[ ]//" `
CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[ ]//" -e "s/-O[gs][ ]//" -e "s/-O[0-9]*[ ]//" ` ;;
*) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[ ]//" -e "s/-O[gs][ ]//" -e "s/[^,]-O[0-9]*[ ]//" `
CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[ ]//" -e "s/-O[gs][ ]//" -e "s/[^,]-O[0-9]*[ ]//" ` ;;
esac

View file

@ -467,8 +467,8 @@ AC_LANG(C++)
# optimizations to be activated explicitly by the toplevel.
case "$CC" in
*/prev-gcc/xgcc*) ;;
*) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[ ]]//" -e "s/-O[[gs]][[ ]]//" -e "s/-O[[0-9]]*[[ ]]//" `
CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[ ]]//" -e "s/-O[[gs]][[ ]]//" -e "s/-O[[0-9]]*[[ ]]//" ` ;;
*) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[ ]]//" -e "s/-O[[gs]][[ ]]//" -e "s/[[^,]]-O[[0-9]]*[[ ]]//" `
CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[ ]]//" -e "s/-O[[gs]][[ ]]//" -e "s/[[^,]]-O[[0-9]]*[[ ]]//" ` ;;
esac
AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)