Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 671016 - dev-libs/openssl: CFLAGS are getting destroyed
Summary: dev-libs/openssl: CFLAGS are getting destroyed
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
: 677020 678870 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-11-12 19:58 UTC by Thomas Deutschmann (RETIRED)
Modified: 2019-08-23 18:10 UTC (History)
8 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Deutschmann (RETIRED) gentoo-dev 2018-11-12 19:58:45 UTC
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_)).
Comment 1 Arfrever Frehtes Taifersar Arahesis 2018-11-12 21:06:28 UTC
(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'
)
Comment 2 Arfrever Frehtes Taifersar Arahesis 2018-11-12 21:21:55 UTC
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'
)
Comment 3 Thomas Deutschmann (RETIRED) gentoo-dev 2019-02-01 00:04:13 UTC
*** Bug 677020 has been marked as a duplicate of this bug. ***
Comment 4 matoro archtester 2019-02-01 17:20:32 UTC
This works cleanly for me including tests.  Is there something preventing this from being merged?  If not I will write up a PR soon.
Comment 5 Arfrever Frehtes Taifersar Arahesis 2019-02-27 02:16:37 UTC
*** Bug 678870 has been marked as a duplicate of this bug. ***
Comment 6 Johannes Schmidt 2019-08-22 06:00:31 UTC
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'
Comment 7 Larry the Git Cow gentoo-dev 2019-08-23 18:10:46 UTC
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(-)