Imagine you have set GRAPHITE="-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block" SPECTREV2="-mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register" CFLAGS="-O2 -pipe -march=native -flto=8 ${GRAPHITE} -ftree-vectorize -fstack-protector-strong ${SPECTREV2}" After processing CFLAGS with > local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \ > -e 's:^CFLAGS=::' \ > -e 's:-fomit-frame-pointer ::g' \ > -e 's:-O[0-9] ::g' \ > -e 's:-march=[-a-z0-9]* ::g' \ > -e 's:-mcpu=[-a-z0-9]* ::g' \ > -e 's:-m[a-z0-9]* ::g' \ > -e 's:\\:\\\\:g' \ > ) you will end up with "-floop-strip-floop-block" somehow, which is invalid: > x86_64-pc-linux-gnu-gcc: error: unrecognized command line option ‘-floop-strip-floop-block’; did you mean ‘-fno-loop-block’? Looks like changing > -e 's:-m[a-z0-9]* ::g' \ into > -e 's: -m[a-z0-9]* : :g' \ will fix it (thanks to Ian (_AxS_)).
(In reply to Thomas Deutschmann from comment #0) > Imagine you have set > > GRAPHITE="-floop-interchange -ftree-loop-distribution -floop-strip-mine > -floop-block" > SPECTREV2="-mfunction-return=thunk -mindirect-branch=thunk > -mindirect-branch-register" > CFLAGS="-O2 -pipe -march=native -flto=8 ${GRAPHITE} -ftree-vectorize > -fstack-protector-strong ${SPECTREV2}" > > After processing CFLAGS with > > > local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \ > > -e 's:^CFLAGS=::' \ > > -e 's:-fomit-frame-pointer ::g' \ > > -e 's:-O[0-9] ::g' \ > > -e 's:-march=[-a-z0-9]* ::g' \ > > -e 's:-mcpu=[-a-z0-9]* ::g' \ > > -e 's:-m[a-z0-9]* ::g' \ > > -e 's:\\:\\\\:g' \ > > ) > > you will end up with "-floop-strip-floop-block" somehow -m was matching -m part of -floop-strip-mine > Looks like changing > > > -e 's:-m[a-z0-9]* ::g' \ > > into > > > -e 's: -m[a-z0-9]* : :g' \ > > will fix it It would not work if -m... flag is at the beginning (i.e. there is no space before it). It also does not match -m... flags which include _ or - or = character in the middle (e.g. -mfunction-return=thunk or -marclinux_prof or -mdivsi3_libfunc=NAME or -minline-ic_invalidate). It also does not match -m... flags which include upper-case letters (e.g. -mARC700). It seems that the solution would be: -e 's:\(^\| \)-m[^ ]*::g' Other lines also have problems: 's:-O[0-9] ::g' does not match -Ofast, -Og and Os flag. 's:-march=[-a-z0-9]* ::g' does not match -march=armv8.4-a flag. All of previous patterns do not match a flag at the end (not followed by space). So I suggest to: - Use \(^\| \) at the beginning of each pattern - Replace [...]* patterns with [^ ]* - Drop final space from patterns - Drop space from substitution strings - Add separate pass for dropping of final whitespace: 's: *$::' local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \ -e 's:^CFLAGS=::' \ -e 's:\(^\| \)-fomit-frame-pointer::g' \ -e 's:\(^\| \)-O[^ ]*::g' \ -e 's:\(^\| \)-march=[^ ]*::g' \ -e 's:\(^\| \)-mcpu=[^ ]*::g' \ -e 's:\(^\| \)-m[^ ]*::g' \ -e 's: *$::' \ -e 's:\\:\\\\:g' )
In case there were initial spaces or multiple consecutive spaces in the middle: -e 's:^ *::' -e 's: \+: :g' local DEFAULT_CFLAGS=$(grep ^CFLAGS= Makefile | LC_ALL=C sed \ -e 's:^CFLAGS=::' \ -e 's:\(^\| \)-fomit-frame-pointer::g' \ -e 's:\(^\| \)-O[^ ]*::g' \ -e 's:\(^\| \)-march=[^ ]*::g' \ -e 's:\(^\| \)-mcpu=[^ ]*::g' \ -e 's:\(^\| \)-m[^ ]*::g' \ -e 's:^ *::' \ -e 's: *$::' \ -e 's: \+: :g' \ -e 's:\\:\\\\:g' )
*** Bug 677020 has been marked as a duplicate of this bug. ***
This works cleanly for me including tests. Is there something preventing this from being merged? If not I will write up a PR soon.
*** Bug 678870 has been marked as a duplicate of this bug. ***
The same thing can happen when -Wl,-O1 is added to the CFLAGS for some reason. The "-O1" is getting removed and the "-Wl," is attached to the flag that follows. This happens for example when using portage-bashrc-mv from the mv overlay, which by default adds all LDFLAGS to CFLAGS and and CXXFLAGS. You could argue that this is non-standard behavior and does not need to be supported, but -Wl,-O1 is a perfectly valid flag for GCC during the compile step, it just usually gets ignored, when linking happens in a different step. So I'd argue for also changing -e 's:-O[0-9] ::g' to -e 's: -O[0-9] : :g'
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=975f55449d9ecbac24beb97081273946083168b4 commit 975f55449d9ecbac24beb97081273946083168b4 Author: Thomas Deutschmann <whissi@gentoo.org> AuthorDate: 2019-08-23 17:44:30 +0000 Commit: Thomas Deutschmann <whissi@gentoo.org> CommitDate: 2019-08-23 18:10:20 +0000 dev-libs/openssl: don't destroy user flags Thanks-to: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org> Closes: https://bugs.gentoo.org/671016 Package-Manager: Portage-2.3.72, Repoman-2.3.17 Signed-off-by: Thomas Deutschmann <whissi@gentoo.org> dev-libs/openssl/openssl-1.0.2s-r1.ebuild | 26 +++++++++++++++++--------- dev-libs/openssl/openssl-1.0.2s-r200.ebuild | 26 +++++++++++++++++--------- dev-libs/openssl/openssl-1.1.0k-r1.ebuild | 22 ++++++++++++++-------- dev-libs/openssl/openssl-1.1.1c-r1.ebuild | 22 ++++++++++++++-------- 4 files changed, 62 insertions(+), 34 deletions(-)