From 5fca01af521462ee2cd2b29963312890512c288a Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 2 Jan 2024 16:44:30 +0100 Subject: [PATCH] Pack relative ELF relocations by default Leftover from the Fedora 39 toolchain changes. --- buildflags.md | 13 +++++++++++++ macros | 5 ++++- redhat-rpm-config.spec | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/buildflags.md b/buildflags.md index 1a13c60..811e1cb 100644 --- a/buildflags.md +++ b/buildflags.md @@ -290,6 +290,16 @@ For example, this can be required if shared objects are used for their side effects in ELF constructors, or for making them available to dynamically loaded plugins. +### Switching to legacy relative relocations + +By default, ELF objects use the architecture-independent `DT_RELR` +mechanism for relative relocations. To switch to the older, +architecture-specific relocation scheme, add this to the RPM spec file: + + %undefine _ld_pack_relocs + +This adds `-Wl,-z,pack-relative-relocs` to the linker flags (`LDFLAGS`). + ### Specifying the build-id algorithm If you want to specify a different build-id algorithm for your builds, you @@ -631,6 +641,9 @@ to the compiler driver `gcc`, and not directly to the link editor for shared objects that actually provide symbols required by the link. Shared objects which are not needed to fulfill symbol dependencies are essentially ignored due to this flag. +* `-z pack-relative-relocs`: Use the portable `DT_RELR` scheme for + relative relocations, resulting in reduced startup time compared to + legacy architecture-specific relocations. * `-z defs`: Refuse to link shared objects (DSOs) with undefined symbols (optional, see above). diff --git a/macros b/macros index 0e75747..95b5ceb 100644 --- a/macros +++ b/macros @@ -79,7 +79,7 @@ # the flags, while intended for ld, are still passed through the gcc # compiler driver. At the beginning of %%build, the environment # variable RPM_LD_FLAGS to this value. -%build_ldflags -Wl,-z,relro %{_ld_as_needed_flags} %{_ld_symbols_flags} %{_hardened_ldflags} %{_annotation_ldflags} %[ "%{toolchain}" == "clang" ? "%{?_clang_extra_ldflags}" : "" ] %{_build_id_flags} %{?_package_note_flags} %{?_distro_extra_ldflags} +%build_ldflags -Wl,-z,relro %{_ld_as_needed_flags} %{_ld_symbols_flags} %{_ld_pack_relocs_flags} %{_hardened_ldflags} %{_annotation_ldflags} %[ "%{toolchain}" == "clang" ? "%{?_clang_extra_ldflags}" : "" ] %{_build_id_flags} %{?_package_note_flags} %{?_distro_extra_ldflags} # Expands to shell code to set the compiler/linker environment # variables CFLAGS, CXXFLAGS, FFLAGS, FCFLAGS, VALAFLAGS, LDFLAGS if they @@ -372,6 +372,9 @@ for k,_ in pairs(stripped_flags) do print(k .. " ") end %_ld_as_needed 1 %_ld_as_needed_flags %{?_ld_as_needed:-Wl,--as-needed} +%_ld_pack_relocs 1 +%_ld_pack_relocs_flags %{?_ld_pack_relocs:-Wl,-z,pack-relative-relocs} + # LTO is the default in Fedora. # "%define _lto_cflags %{nil}" to opt out # diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index 0e8c200..49169d1 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -4,7 +4,7 @@ # 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 272 +%global baserelease 273 Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config @@ -256,6 +256,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora common.lua %doc buildflags.md %changelog +* Tue Jan 2 2024 Florian Weimer - 273-1 +- Pack relative ELF relocations by default + * Tue Dec 26 2023 Jan Drögehoff - 272-1 - Add zig-srpm-macros