From e80fa1344a49662fec08d650debf793048c87429 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Thu, 20 Dec 2018 11:34:27 +0100 Subject: [PATCH] Build flags: Add support for extension builders (#1543394) --- buildflags.md | 41 +++++++++++++++++++++++++++++++++++++++++ macros | 16 ++++++++++++++++ redhat-rpm-config.spec | 5 ++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/buildflags.md b/buildflags.md index 06b41e6..541f562 100644 --- a/buildflags.md +++ b/buildflags.md @@ -332,3 +332,44 @@ linker flags: security exploits, redirecting execution). Therefore, it is preferable to turn of lazy binding, although it increases startup time. + +# Support for extension builders + +Some packages include extension builders that allow users to build +extension modules (which are usually written in C and C++) under the +control of a special-purpose build system. This is a common +functionality provided by scripting languages such as Python and Perl. +Traditionally, such extension builders captured the Fedora build flags +when these extension were built. However, these compiler flags are +adjusted for a specific Fedora release and toolchain version and +therefore do not work with a custom toolchain (e.g., different C/C++ +compilers), and users might want to build their own extension modules +with such toolchains. + +The macros `%{extension_cflags}`, `%{extension_cxxflags}`, +`%{extension_fflags}`, `%{extension_ldflags}` contain a subset of +flags that have been adjusted for compatibility with alternative +toolchains, while still preserving some of the compile-time security +hardening that the standard Fedora build flags provide. + +The current set of differences are: + +* No GCC plugins (such as annobin) are activated. +* No GCC spec files (`-specs=` arguments) are used. + +Additional flags may be removed in the future if they prove to be +incompatible with alternative toolchains. + +Extension builders should detect whether they are performing a regular +RPM build (e.g., by looking for an `RPM_OPT_FLAGS` variable). In this +case, they should use the *current* set of Fedora build flags (that +is, the output from `rpm --eval '%{build_cflags}'` and related +commands). Otherwise, when not performing an RPM build, they can +either use hard-coded extension builder flags (thus avoiding a +run-time dependency on `redhat-rpm-config`), or use the current +extension builder flags (with a run-time dependency on +`redhat-rpm-config`). + +As a result, extension modules built for Fedora will use the official +Fedora build flags, while users will still be able to build their own +extension modules with custom toolchains. diff --git a/macros b/macros index d87c0fc..5f083ce 100644 --- a/macros +++ b/macros @@ -57,6 +57,22 @@ FCFLAGS="${FCFLAGS:-%{build_fflags}}" ; export FCFLAGS ; \ LDFLAGS="${LDFLAGS:-%{build_ldflags}}" ; export LDFLAGS +# Internal-only. Do not use. Expand a variable and strip the flags +# not suitable to extension builders. +%__extension_strip_flags() %{lua: +local name = rpm.expand("%{1}") +local value = " " .. rpm.expand("%{build_" .. name .. "}") +local result = string.gsub(value, "%s+-specs=[^%s]+", " ") +print(result) +} + +# Variants of CFLAGS, CXXFLAGS, FFLAGS, LDFLAGS for use within +# extension builders. +%extension_cflags %{__extension_strip_flags cflags} +%extension_cxxflags %{__extension_strip_flags cxxflags} +%extension_fflags %{__extension_strip_flags fflags} +%extension_ldflags %{__extension_strip_flags ldflags} + # Deprecated names. For backwards compatibility only. %__global_cflags %{build_cflags} %__global_cxxflags %{build_cxxflags} diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index c908540..64b1674 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -6,7 +6,7 @@ Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config -Version: 126 +Version: 127 Release: 1%{?dist} # No version specified. License: GPL+ @@ -199,6 +199,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua %{_rpmconfigdir}/macros.d/macros.kmp %changelog +* Thu Dec 20 2018 Florian Weimer - 127-1 +- Build flags: Add support for extension builders (#1543394) + * Mon Dec 17 2018 Panu Matilainen - 126-1 - Silence the annoying warning from ldconfig brp-script (#1540971)