Skip to content

Do not remove -O0 in the middle of a flag #15828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

arnaud-lb
Copy link
Member

This backports #9647 from master and improves it to avoid accidentally breaking flags ending with something looking like an optimization flag. (#9647 fixed that for flags starting with an optimization flag.)

This should fix #15826

Discard known '-O' flags, including just '-O', but do not remove only '-O' in '-Ounknown'
@cmb69 cmb69 linked an issue Sep 10, 2024 that may be closed by this pull request
@arnaud-lb arnaud-lb marked this pull request as ready for review September 10, 2024 18:25
@arnaud-lb arnaud-lb requested review from petk and nielsdos September 10, 2024 18:26
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit

@petk
Copy link
Member

petk commented Sep 10, 2024

I'll just try to reproduce here that nix shell bug with ${SED} vs $SED here what was the problem back then...

Edit: I see, got it. Relative paths were the problem back then. But that was happening only where the IFS got changed and those dots need to be used to get the version. For example, SED=../../relative/path/to/sed ./configure, meaning elsewhere the $SED can be used.

Comment on lines +2746 to +2750
changequote({,})
sed_script='s/\([\t ]\|^\)-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)/\1/g'
changequote([,])
CFLAGS=`echo "$CFLAGS" | sed -e "$sed_script"`
CXXFLAGS=`echo "$CFLAGS" | sed -e "$sed_script"`
Copy link
Member

@petk petk Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
changequote({,})
sed_script='s/\([\t ]\|^\)-O\([0-9gsz]\|fast\|\)\([\t ]\|$\)/\1/g'
changequote([,])
CFLAGS=`echo "$CFLAGS" | sed -e "$sed_script"`
CXXFLAGS=`echo "$CFLAGS" | sed -e "$sed_script"`
sed_script='s/\([[\t ]]\|^\)-O\([[0-9gsz]]\|fast\|\)\([[\t ]]\|$\)/\1/g'
CFLAGS=$(echo "$CFLAGS" | $SED -e "$sed_script")
CXXFLAGS=$(echo "$CFLAGS" | $SED -e "$sed_script")

I've removed previous suggestion and added all in one:

  • backticks command substitution replaced with $(...)
  • $SED used instead of sed direct command so SED variable can be set at the configure step SED=../path/to/sed ./configure
  • changequote builtin M4 macro is something that ideally should be avoided for the cost of duplicating the [ and ] characters in the sed_script variable a bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry and another one. Probably the most important one as CXXFLAGS should be its own variable instead.

diff --git a/build/php.m4 b/build/php.m4
index dee47f6e1a..e13fc3367e 100644
--- a/build/php.m4
+++ b/build/php.m4
@@ -2745,5 +2745,5 @@ dnl
 AC_DEFUN([PHP_REMOVE_OPTIMIZATION_FLAGS], [
   sed_script='s/\([[\t ]]\|^\)-O\([[0-9gsz]]\|fast\|\)\([[\t ]]\|$\)/\1/g'
   CFLAGS=$(echo "$CFLAGS" | $SED -e "$sed_script")
-  CXXFLAGS=$(echo "$CFLAGS" | $SED -e "$sed_script")
+  CXXFLAGS=$(echo "$CXXFLAGS" | $SED -e "$sed_script")
 ])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@arnaud-lb arnaud-lb closed this in c639614 Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler flag gets erroneously removed
3 participants