Compare commits

...

2 Commits

Author SHA1 Message Date
David Abdurachmanov ea923090ec
Apply riscv64 fixes
Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com>
2023-08-25 09:32:21 +03:00
Charalampos Stratakis 7331757cf1 Strip all extension builder flags except -fexceptions and -fcf-protection
This preserves binary compatibility with the main interpreters
the extensions are built against while removing Fedora's flags
that are not required to be inherited on user built extensions.

This implements https://fedoraproject.org/wiki/Changes/Python_Extension_Flags_Reduction
2023-08-04 12:58:12 +02:00
8 changed files with 48 additions and 21 deletions

View File

@ -660,16 +660,11 @@ 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.
toolchains.
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.
Currently the -fexceptions and -fcf-protection flags are preserved
for binary compatibility with the languages the extensions are
built against.
Extension builders should detect whether they are performing a regular
RPM build (e.g., by looking for an `RPM_OPT_FLAGS` variable). In this

21
macros
View File

@ -113,13 +113,19 @@
# Internal-only. Do not use. Expand a variable and strip the flags
# not suitable to extension builders.
%__extension_strip_flags() %{lua:
--the only argument to this macro is the "name" of the flags we strip (e.g. cflags, ldflags, etc.)
local name = rpm.expand("%{1}")
local value = " " .. rpm.expand("%{build_" .. name .. "}")
local specs_pattern = "%s+-specs=[^%s]+"
local lto_flags_pattern = rpm.expand("%{?_lto_cflags}"):gsub("[%-%.]", "%%%1")
local package_note_flags_pattern = "%-Wl,%S*package_note%S*"
local result = value:gsub(specs_pattern, " "):gsub(lto_flags_pattern, ""):gsub(package_note_flags_pattern, "")
print(result)
--store all the individual flags in a variable as a continuous string
local flags = rpm.expand("%{build_" .. name .. "}")
--create an empty table for the minimal set of flags we wanna preserve
local stripped_flags = { }
--iterate over the individual flags and store the ones we want in the table as unique keys
for flag in flags:gmatch("%S+") do
if flag:find("^%-fexceptions") or flag:find("^%-fcf%-protection") then
stripped_flags[flag] = true end
end
--print out the finalized set of flags for use by the extension builders
for k,_ in pairs(stripped_flags) do print(k .. " ") end
}
# Variants of CFLAGS, CXXFLAGS, FFLAGS, LDFLAGS for use within
@ -372,7 +378,8 @@ print(result)
# way we can detect installing an unusable .o/.a file. This is on the TODO
# list for F34.
%_gcc_lto_cflags -flto=auto -ffat-lto-objects
%_clang_lto_cflags -flto=thin
# riscv64 does not have ld.gold support needed for LTO with Clang.
%_clang_lto_cflags %{nil}
%_lto_cflags %{expand:%%{_%{toolchain}_lto_cflags}}
# Default fortification level.

View File

@ -1,2 +1,2 @@
# Arches that GAP runs on
%gap_arches aarch64 ppc64le s390x x86_64
%gap_arches aarch64 ppc64le s390x x86_64 riscv64

View File

@ -1,2 +1,2 @@
# Arches that OpenJDK and dependent packages run on
%java_arches aarch64 ppc64le s390x x86_64
%java_arches aarch64 ppc64le s390x x86_64 riscv64

View File

@ -4,4 +4,4 @@
# those arches. Support for POWER and aarch64 arrived in nodejs v4. Support
# for s390x arrived in nodejs v6
%nodejs_arches %{ix86} x86_64 %{arm} aarch64 %{power64} s390x
%nodejs_arches %{ix86} x86_64 %{arm} aarch64 %{power64} s390x riscv64

View File

@ -4,12 +4,12 @@
# 2) When making changes, increment the version (in baserelease) by 1.
# rpmdev-bumpspec and other tools update the macro below, which is used
# in Version: to get the desired effect.
%global baserelease 261
%global baserelease 262
Summary: Red Hat specific rpm configuration files
Name: redhat-rpm-config
Version: %{baserelease}
Release: 1%{?dist}
Release: 1.0.riscv64%{?dist}
# No version specified.
License: GPL+
URL: https://src.fedoraproject.org/rpms/redhat-rpm-config
@ -254,6 +254,15 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua
%doc buildflags.md
%changelog
* Fri Aug 25 2023 David Abdurachmanov <davidlt@rivosinc.com> - 262-1.0.riscv64
- Add riscv64 to %%gap_arches, %%java_arches, and %%nodejs_arches
- Set %%_clang_lto_cflags to %%nil as ld.gold is not implemented for riscv64
and thus LTO with Clang doesn't work.
* Wed Aug 02 2023 Charalampos Stratakis <cstratak@redhat.com> - 262-1
- Strip all extension builder flags except -fexceptions and -fcf-protection
- https://fedoraproject.org/wiki/Changes/Python_Extension_Flags_Reduction
* Fri Jul 7 2023 Florian Weimer <fweimer@redhat.com> - 261-1
- Fix warnings that appear during the build of the llvm package

View File

@ -0,0 +1,5 @@
summary: Test that the extension builder flags contain the proper flags
require:
- redhat-rpm-config
test: ./runtest.sh

View File

@ -0,0 +1,11 @@
#!/bin/bash
set -ex
# Verify that the extension builder flags are stripped of non-required flags.
# The flags may appear in random order due to being accessed through a lua
# associative array.
for f in %{extension_cflags} %{extension_cxxflags} %{extension_fflags}; do
[[ $(rpm --eval "$f") =~ ^[[:space:]]*(-fexceptions -fcf-protection|-fcf-protection -fexceptions)[[:space:]]*$ ]]
done
# The extension ldflag should always be empty
[[ -z $(rpm --eval "%extension_ldflags") ]]