From Fedora Project Wiki
Line 64: Line 64:
The proposed new macros macros for adding new flags are:
The proposed new macros macros for adding new flags are:


%_package_extra_cflags %{nil}
%_pkg_extra_cflags %{nil}
%_package_extra_cxxflags %{nil}
%_pkg_extra_cxxflags %{nil}
%_package_extra_fflags %{nil}
%_pkg_extra_fflags %{nil}
%_package_extra_ldflags %{nil}
%_pkg_extra_ldflags %{nil}


These will be added to %{build_cflags}, %{build_cxxflags}, %{build_fflags}, and %{build_ldflags} respectively to allow packges to add their own flags to the default list: e.g.
These will be added to %{build_cflags}, %{build_cxxflags}, %{build_fflags}, and %{build_ldflags} respectively to allow packges to add their own flags to the default list: e.g.
Line 74: Line 74:


The proposed new macros to represent existing flags are:
The proposed new macros to represent existing flags are:
%_flag_fstack_protector_strong -fstack-protector-strong
%_flag_z_now    -Wl,-z,now
%_flag_z_defs -Wl,-z,defs
%_flag_flto_auto        -flto=auto
%_flag_ffat_lto_objects -ffat-lto-objects
%_flag_o                -O2
%_flag_f_exceptions    -fexceptions
%_flag_g                -g
%_flag_grecord_gcc_switches -grecord-gcc-switches
%_flag_pipe            -pipe
%_flag_wall            -Wall
%_flag_werror_format_security -Werror=format-security
%_flag_fortify_source  -Wp,-D_FORTIFY_SOURCE=2
%_flag_glibcxx_assertions  -Wp,-D_GLIBCXX_ASSERTIONS
%_flag_asynchronous_unwind_tables -fasynchronous-unwind-tables
%_flag_fstack_clash_protection  -fstack-clash-protection
%_flag_fcf_protection          -fcf-protection
%_flag_mbranch_protection_standard -mbranch-protection=standard
In addition to adding these new macros, there would be a policy that requires all new flags to have their own RPM macro.


== Feedback ==
== Feedback ==

Revision as of 02:22, 1 June 2022

Important.png
Comments and Explanations
The page source contains comments providing guidance to fill out each section. They are invisible when viewing this page. To read it, choose the "view source" link.
Copy the source to a new page before making changes! DO NOT EDIT THIS TEMPLATE FOR YOUR CHANGE PROPOSAL.
Idea.png
Guidance
For details on how to fill out this form, see the documentation.


RPM Macros for Build Flags

Important.png
This is a proposed Change for Fedora Linux.
This document represents a proposed Change. As part of the Changes process, proposals are publicly announced in order to receive community feedback. This proposal will only be implemented if approved by the Fedora Engineering Steering Committee.

Summary

Create a corresponding macro for each compiler flag in the redhat-rpm-config macro file and create "extra flag" macros to make it easier for packages to control the set of default flags.

Owner

Current status

  • Targeted release: Fedora Linux 37
  • Last updated: 2022-06-01
  • FESCo issue: <will be assigned by the Wrangler>
  • Tracker bug: <will be assigned by the Wrangler>
  • Release notes tracker: <will be assigned by the Wrangler>

Detailed Description

Detailed Description

The macros file in the redhat-rpm-config package contains a list of default compiler flags for packages to use when compiling C,C++, and Fortran packages. There is currently no standard way to remove or add to the set of default flags. Most packages use a combination of echo and sed to remove unwanted flags or add new ones. Some examples:

ghdl: OPT_FLAGS=echo %{optflags}|sed -e 's/\(-Wp,\)\?-D_FORTIFY_SOURCE=[12]//g' julia: %global optflags %(echo %{optflags} | sed 's/-Wp,-D_GLIBCXX_ASSERTIONS //') compiler-rt: global optflags %(echo %{optflags} -D_DEFAULT_SOURCE)

This change will add new macros which will make it easier for packages to add and remove their own compiler flags. This strategy is already used to some extent with feature macros like %{_lto_cflags}, %{_hardening_cflags}, etc, but these new flags will give packagers more fine-grained control over the options.

The proposed new macros macros for adding new flags are:

%_pkg_extra_cflags %{nil} %_pkg_extra_cxxflags %{nil} %_pkg_extra_fflags %{nil} %_pkg_extra_ldflags %{nil}

These will be added to %{build_cflags}, %{build_cxxflags}, %{build_fflags}, and %{build_ldflags} respectively to allow packges to add their own flags to the default list: e.g.

%build_cflags %{optflags} %{_package_extra_cflags}

The proposed new macros to represent existing flags are:

%_flag_fstack_protector_strong -fstack-protector-strong %_flag_z_now -Wl,-z,now %_flag_z_defs -Wl,-z,defs %_flag_flto_auto -flto=auto %_flag_ffat_lto_objects -ffat-lto-objects %_flag_o -O2 %_flag_f_exceptions -fexceptions %_flag_g -g %_flag_grecord_gcc_switches -grecord-gcc-switches %_flag_pipe -pipe %_flag_wall -Wall %_flag_werror_format_security -Werror=format-security %_flag_fortify_source -Wp,-D_FORTIFY_SOURCE=2 %_flag_glibcxx_assertions -Wp,-D_GLIBCXX_ASSERTIONS %_flag_asynchronous_unwind_tables -fasynchronous-unwind-tables %_flag_fstack_clash_protection -fstack-clash-protection %_flag_fcf_protection -fcf-protection %_flag_mbranch_protection_standard -mbranch-protection=standard

In addition to adding these new macros, there would be a policy that requires all new flags to have their own RPM macro.

Feedback

Benefit to Fedora

Scope

  • Proposal owners:
  • Other developers:
  • Policies and guidelines: N/A (not needed for this Change)
  • Trademark approval: N/A (not needed for this Change)
  • Alignment with Objectives:

Upgrade/compatibility impact

How To Test

User Experience

Dependencies

Contingency Plan

  • Contingency mechanism: (What to do? Who will do it?) N/A (not a System Wide Change)
  • Contingency deadline: N/A (not a System Wide Change)
  • Blocks release? N/A (not a System Wide Change), Yes/No


Documentation

N/A (not a System Wide Change)

Release Notes