From 5aee897b5c05dcec7fd0679aa5b5cb394d4abc23 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 4 Jan 2021 16:31:41 +0000 Subject: [PATCH] Fix linking with multiple same-name sections. (PR 27100) --- binutils-duplicate-sections.patch | 34 +++++++++++++++++++++++++++++++ binutils.spec | 9 +++++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 binutils-duplicate-sections.patch diff --git a/binutils-duplicate-sections.patch b/binutils-duplicate-sections.patch new file mode 100644 index 0000000..441bb2e --- /dev/null +++ b/binutils-duplicate-sections.patch @@ -0,0 +1,34 @@ +diff -rup binutils.orig/ld/ldlang.c binutils-2.35.1/ld/ldlang.c +--- binutils.orig/ld/ldlang.c 2021-01-04 15:20:32.901498036 +0000 ++++ binutils-2.35.1/ld/ldlang.c 2021-01-04 15:22:03.151916333 +0000 +@@ -1529,6 +1529,8 @@ lang_output_section_statement_lookup (co + + entry->s.output_section_statement.name = name; + entry->s.output_section_statement.constraint = constraint; ++ entry->s.output_section_statement.dup_output = (create == 2 ++ || constraint == SPECIAL); + return &entry->s.output_section_statement; + } + +@@ -2390,7 +2392,7 @@ init_os (lang_output_section_statement_t + if (strcmp (s->name, DISCARD_SECTION_NAME) == 0) + einfo (_("%F%P: illegal use of `%s' section\n"), DISCARD_SECTION_NAME); + +- if (s->constraint != SPECIAL) ++ if (!s->dup_output) + s->bfd_section = bfd_get_section_by_name (link_info.output_bfd, s->name); + if (s->bfd_section == NULL) + s->bfd_section = bfd_make_section_anyway_with_flags (link_info.output_bfd, +diff -rup binutils.orig/ld/ldlang.h binutils-2.35.1/ld/ldlang.h +--- binutils.orig/ld/ldlang.h 2021-01-04 15:20:32.627499830 +0000 ++++ binutils-2.35.1/ld/ldlang.h 2021-01-04 15:21:06.688277003 +0000 +@@ -173,6 +173,9 @@ typedef struct lang_output_section_state + unsigned int after_end : 1; + /* If this section uses the alignment of its input sections. */ + unsigned int align_lma_with_input : 1; ++ /* If script has duplicate output section statements of the same name ++ create duplicate output sections. */ ++ unsigned int dup_output : 1; + } lang_output_section_statement_type; + + typedef struct diff --git a/binutils.spec b/binutils.spec index f82e5e9..7567e80 100644 --- a/binutils.spec +++ b/binutils.spec @@ -39,7 +39,7 @@ Summary: A GNU collection of binary utilities Name: binutils%{?name_cross}%{?_with_debug:-debug} Version: 2.35.1 -Release: 17%{?dist} +Release: 18%{?dist} License: GPLv3+ URL: https://sourceware.org/binutils @@ -291,6 +291,10 @@ Patch27: binutils-recursive-debuglink-following.patch # Lifetime: Fixed in 2.36 Patch28: binutils-SHF_LINK_ORDER.patch +# Purpose: Correctly handle multiple same-named sections in linker scripts +# Lifetime: Fixed in 2.36 +Patch29: binutils-duplicate-sections.patch + #---------------------------------------------------------------------------- Provides: bundled(libiberty) @@ -870,6 +874,9 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Mon Jan 04 2021 Nick Clifton - 2.35.1-18 +- Fix linking with multiple same-name sections. (PR 27100) + * Mon Jan 04 2021 Nick Clifton - 2.35.1-17 - Fix linking mixed SHF_LINK_ORDER and non-SHF_LINK_ORDER sections. (#1907945)