From 39d9c7ad8acd469a58327fa957080928700445ae Mon Sep 17 00:00:00 2001 From: wangding16 Date: Sun, 25 Aug 2024 17:23:20 +0800 Subject: [PATCH] Backport: Fix gold linker relocation offset (cherry picked from commit bfd4551d9fc304ec47580ce7b419ebc73520f265) --- Fix-gold-linker-relocation-offset.patch | 52 +++++++++++++++++++++++++ binutils.spec | 9 ++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 Fix-gold-linker-relocation-offset.patch diff --git a/Fix-gold-linker-relocation-offset.patch b/Fix-gold-linker-relocation-offset.patch new file mode 100644 index 0000000..4ff9ee9 --- /dev/null +++ b/Fix-gold-linker-relocation-offset.patch @@ -0,0 +1,52 @@ +From 3d84bd3df6cd5741b575cb454933a3c414c4a5d5 Mon Sep 17 00:00:00 2001 +From: wangding16 +Date: Sun, 25 Aug 2024 16:51:53 +0800 +Subject: [PATCH] Fix gold linker relocation offset + +Reference: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=c441a361287ca98aa7a4ac1ff02d12d138b289dc + +--- + gold/aarch64.cc | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +diff --git a/gold/aarch64.cc b/gold/aarch64.cc +index 7f95c0cf..6004118a 100644 +--- a/gold/aarch64.cc ++++ b/gold/aarch64.cc +@@ -2916,6 +2916,7 @@ class Target_aarch64 : public Sized_target + Section_id_hash> AArch64_input_section_map; + typedef AArch64_insn_utilities Insn_utilities; + const static int TCB_SIZE = size / 8 * 2; ++ static const Address invalid_address = static_cast
(-1); + + Target_aarch64(const Target::Target_info* info = &aarch64_info) + : Sized_target(info), +@@ -8286,6 +8287,25 @@ Target_aarch64::relocate_relocs( + + gold_assert(sh_type == elfcpp::SHT_RELA); + ++ if (offset_in_output_section == this->invalid_address) { ++ const Output_relaxed_input_section* poris = ++ output_section->find_relaxed_input_section(relinfo->object, ++ relinfo->data_shndx); ++ if (poris != NULL) { ++ Address section_address = poris->address(); ++ section_size_type section_size = poris->data_size(); ++ ++ gold_assert(section_address >= view_address ++ && (section_address + section_size ++ <= view_address + view_size)); ++ ++ off_t offset = section_address - view_address; ++ view += offset; ++ view_address += offset; ++ view_size = section_size; ++ } ++ } ++ + gold::relocate_relocs( + relinfo, + prelocs, +-- +2.23.0 + diff --git a/binutils.spec b/binutils.spec index b1a64f6..e5eeb12 100644 --- a/binutils.spec +++ b/binutils.spec @@ -2,7 +2,7 @@ Summary: A GNU collection of binary utilities Name: binutils%{?_with_debug:-debug} Version: 2.41 -Release: 9 +Release: 10 License: GPL-3.0-or-later AND (GPL-3.0-or-later WITH Bison-exception-2.2) AND (LGPL-2.0-or-later WITH GCC-exception-2.0) AND BSD-3-Clause AND GFDL-1.3-or-later AND GPL-2.0-or-later AND LGPL-2.1-or-later AND LGPL-2.0-or-later URL: https://sourceware.org/binutils @@ -229,6 +229,10 @@ Patch5007: binutils-update-linker-manual.patch # Lifetime: Fixed in 2.42 (maybe) Patch5008: binutils-gold-empty-dwp.patch +# Purpose: Fix gold linker relocation offset. +# Lifetime: Permanent +Patch5009: Fix-gold-linker-relocation-offset.patch + #---------------------------------------------------------------------------- Provides: bundled(libiberty) @@ -1243,6 +1247,9 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Thu Sep 26 2024 wangding - 2.41-10 +- fix gold linker relocation offset + * Thu Sep 19 2024 huyubiao - 2.41-9 - add binutils-help to keep consistent with the old version -- Gitee