Bug 2184340

Summary: _distro_extra_cflags is ignored if _auto_set_build_flags is enabled
Product: [Fedora] Fedora Reporter: Dominik 'Rathann' Mierzejewski <dominik>
Component: redhat-rpm-configAssignee: Tom Stellard <tstellar>
Status: CLOSED INSUFFICIENT_DATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: ajax, carl, ffesti, fweimer, igor.raits, j, maxwell, mhroncok, ngompa13, nickc, pmatilai, sipoyare, torsava, tstellar
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-06-13 13:08:14 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2100610    

Description Dominik 'Rathann' Mierzejewski 2023-04-04 11:00:02 UTC
Description of problem:
build_cflags is defined as:

build_cflags       %{optflags} %{?_distro_extra_cflags}

suggesting that extra flags can be added by defining _distro_extra_cflags.
However, doing

%global _distro_extra_cflags -Wno-error=stringop-overflow

has no effect on build_cflags unless I disable _auto_set_build_flags using

%undefine _auto_set_build_flags

and add %set_build_flags to %build manually.

Version-Release number of selected component (if applicable):
redhat-rpm-config-254-1.fc39.noarch

How reproducible:
Always.

Steps to Reproduce:
1. Add %global _distro_extra_cflags -Wno-error=stringop-overflow to your spec file
2. rpmbuild -bc foo.spec

Actual results:
...
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64   -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer'
...

Expected results:
...
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64   -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wno-error=stringop-overflow'
...

Comment 1 Dominik 'Rathann' Mierzejewski 2023-04-04 11:19:19 UTC
Additional info:

rpm -D '_distro_extra_cflags -Wall' -E '%build_cflags' | grep -e '\-Wall$'

does work. Doing the same in a spec file doesn't.

Comment 2 Florian Weimer 2023-04-04 13:36:19 UTC
(In reply to Dominik 'Rathann' Mierzejewski from comment #0)
> Steps to Reproduce:
> 1. Add %global _distro_extra_cflags -Wno-error=stringop-overflow to your
> spec file

If that doesn't work, this is actually a good thing. %_distro_extra_cflags must not be changed in individual spec files, it's reserved for use by the distribution.

That being said, I cannot reproduce this issue.

Comment 3 Dominik 'Rathann' Mierzejewski 2023-04-05 09:38:18 UTC
(In reply to Florian Weimer from comment #2)
> (In reply to Dominik 'Rathann' Mierzejewski from comment #0)
> > Steps to Reproduce:
> > 1. Add %global _distro_extra_cflags -Wno-error=stringop-overflow to your
> > spec file
> 
> If that doesn't work, this is actually a good thing. %_distro_extra_cflags
> must not be changed in individual spec files, it's reserved for use by the
> distribution.

Well, _distro_extra_cflags is undefined at the moment, so I thought it'd be ok to use.

What is the "official" way of adding some extra CFLAGS, then?

> That being said, I cannot reproduce this issue.

Odd. It's 100% reproducible in rawhide mock for me.

Comment 4 Florian Weimer 2023-04-05 09:47:48 UTC
(In reply to Dominik 'Rathann' Mierzejewski from comment #3)
> (In reply to Florian Weimer from comment #2)
> > (In reply to Dominik 'Rathann' Mierzejewski from comment #0)
> > > Steps to Reproduce:
> > > 1. Add %global _distro_extra_cflags -Wno-error=stringop-overflow to your
> > > spec file
> > 
> > If that doesn't work, this is actually a good thing. %_distro_extra_cflags
> > must not be changed in individual spec files, it's reserved for use by the
> > distribution.
> 
> Well, _distro_extra_cflags is undefined at the moment, so I thought it'd be
> ok to use.
> 
> What is the "official" way of adding some extra CFLAGS, then?

Do it at the shell level (CFLAGS="$CFLAGS -Wno-error=stringop-overflow"), I think.

> > That being said, I cannot reproduce this issue.
> 
> Odd. It's 100% reproducible in rawhide mock for me.

I tried with the lua spec file and it worked for me. So we'd need to see your spec file.