From f3c54369c5e4e79cd59bc76d673a608f25e86edc Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 2 Aug 2019 18:44:25 +0200 Subject: [PATCH] Fix ld -Map not to produce corrupt ELF notes (#1736114) --- binutils-rh1736114.patch | 158 +++++++++++++++++++++++++++++++++++++++ binutils.spec | 10 ++- 2 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 binutils-rh1736114.patch diff --git a/binutils-rh1736114.patch b/binutils-rh1736114.patch new file mode 100644 index 0000000..b47dde9 --- /dev/null +++ b/binutils-rh1736114.patch @@ -0,0 +1,158 @@ +Backup from binutils-2_32-branch upstream: + +commit df010caac3b33b1d38b6d67024091854c3f77c77 +Author: H.J. Lu +Date: Mon Jun 24 11:08:40 2019 -0700 + + elf: Remove the property after reporting its removal + + commit d2ef37ebd9f771d06edf1fdea37970f60b242b2d + Author: H.J. Lu + Date: Fri Dec 7 08:30:30 2018 -0800 + + elf: Report property change when merging properties + + failed to remove the property after reporting it has been removed. This + patch corrects it. + + bfd/ + + PR ld/24721 + * elf-properties.c (elf_merge_gnu_property_list): Remove the + property after reporting property removal. + + ld/ + + PR ld/24721 + * testsuite/ld-x86-64/x86-64.exp: Run PR ld/24721 tests. + * testsuite/ld-x86-64/pr24721-x32.d: New file. + * testsuite/ld-x86-64/pr24721.d: Likewise. + * testsuite/ld-x86-64/pr24721.map: Likewise. + * testsuite/ld-x86-64/pr24721a.s: Likewise. + * testsuite/ld-x86-64/pr24721b.s: Likewise. + + (cherry picked from commit f93ab3a0b8039a1667a666f013cca50b03d67f9b) + +Conflicts: + ld/testsuite/ld-x86-64/x86-64.exp + (Missing backports of PR24151, PR24458.) + +diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c +index 5e48d75faa269453..4a9907ff7edad5e0 100644 +--- a/bfd/elf-properties.c ++++ b/bfd/elf-properties.c +@@ -322,12 +322,10 @@ elf_merge_gnu_property_list (struct bfd_link_info *info, bfd *first_pbfd, + (bfd_vma) p->property.pr_type, first_pbfd, abfd); + } + } +- else +- { +- /* Remove this property. */ +- *lastp = p->next; +- continue; +- } ++ ++ /* Remove this property. */ ++ *lastp = p->next; ++ continue; + } + else if (number_p) + { +diff --git a/ld/testsuite/ld-x86-64/pr24721-x32.d b/ld/testsuite/ld-x86-64/pr24721-x32.d +new file mode 100644 +index 0000000000000000..9b067efdc11a4824 +--- /dev/null ++++ b/ld/testsuite/ld-x86-64/pr24721-x32.d +@@ -0,0 +1,6 @@ ++#source: pr24721a.s ++#source: pr24721b.s ++#as: --x32 -mx86-used-note=no ++#ld: -r -m elf32_x86_64 -Map tmpdir/pr24721.map ++#readelf: -n ++#map: pr24721.map +diff --git a/ld/testsuite/ld-x86-64/pr24721.d b/ld/testsuite/ld-x86-64/pr24721.d +new file mode 100644 +index 0000000000000000..efa88db2b3c7e9c5 +--- /dev/null ++++ b/ld/testsuite/ld-x86-64/pr24721.d +@@ -0,0 +1,6 @@ ++#source: pr24721a.s ++#source: pr24721b.s ++#as: --64 -defsym __64_bit__=1 -mx86-used-note=no ++#ld: -r -melf_x86_64 -Map tmpdir/pr24721.map ++#readelf: -n ++#map: pr24721.map +diff --git a/ld/testsuite/ld-x86-64/pr24721.map b/ld/testsuite/ld-x86-64/pr24721.map +new file mode 100644 +index 0000000000000000..9e63fff27557b983 +--- /dev/null ++++ b/ld/testsuite/ld-x86-64/pr24721.map +@@ -0,0 +1,3 @@ ++#... ++Removed property 0xc0000002 to merge tmpdir/pr24721a.o \(0x1\) and tmpdir/pr24721b.o \(not found\) ++#pass +diff --git a/ld/testsuite/ld-x86-64/pr24721a.s b/ld/testsuite/ld-x86-64/pr24721a.s +new file mode 100644 +index 0000000000000000..b229d19b02dc9809 +--- /dev/null ++++ b/ld/testsuite/ld-x86-64/pr24721a.s +@@ -0,0 +1,34 @@ ++ .text ++ .globl foo ++ .type foo,@function ++ .p2align 4 ++foo: ++ ret ++ ++ .section ".note.gnu.property", "a" ++.ifdef __64_bit__ ++ .p2align 3 ++.else ++ .p2align 2 ++.endif ++ .long 1f - 0f /* name length */ ++ .long 5f - 2f /* data length */ ++ .long 5 /* note type */ ++0: .asciz "GNU" /* vendor name */ ++1: ++.ifdef __64_bit__ ++ .p2align 3 ++.else ++ .p2align 2 ++.endif ++2: .long 0xc0000002 /* pr_type. */ ++ .long 4f - 3f /* pr_datasz. */ ++3: ++ .long 0x1 ++4: ++.ifdef __64_bit__ ++ .p2align 3 ++.else ++ .p2align 2 ++.endif ++5: +diff --git a/ld/testsuite/ld-x86-64/pr24721b.s b/ld/testsuite/ld-x86-64/pr24721b.s +new file mode 100644 +index 0000000000000000..3d11691166751bfa +--- /dev/null ++++ b/ld/testsuite/ld-x86-64/pr24721b.s +@@ -0,0 +1,6 @@ ++ .text ++ .globl bar ++ .type bar,@function ++ .p2align 4 ++bar: ++ ret +diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp +index 0d65801a942dbddd..3e02531e6f90aff9 100644 +--- a/ld/testsuite/ld-x86-64/x86-64.exp ++++ b/ld/testsuite/ld-x86-64/x86-64.exp +@@ -424,6 +424,8 @@ run_dump_test "pr23486d-x32" + run_dump_test "pr23854" + run_dump_test "pr23930" + run_dump_test "pr23930-x32" ++run_dump_test "pr24721" ++run_dump_test "pr24721-x32" + + if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} { + return diff --git a/binutils.spec b/binutils.spec index 827e8f4..e48cf3b 100644 --- a/binutils.spec +++ b/binutils.spec @@ -2,7 +2,7 @@ Summary: A GNU collection of binary utilities Name: %{?cross}binutils%{?_with_debug:-debug} Version: 2.32 -Release: 19%{?dist} +Release: 20%{?dist} License: GPLv3+ URL: https://sourceware.org/binutils @@ -234,6 +234,10 @@ Patch23: binutils-do-not-warn-about-debuginfo-files.patch # Lifetime: Fixed in 2.33 Patch24: binutils-do-not-merge-differing-SHF_EXCLUDE-groups.patch +# Purpose: Fix -Map and property merging +# Lifetime: Fixed in 2.33 +Patch25: binutils-rh1736114.patch + #---------------------------------------------------------------------------- Provides: bundled(libiberty) @@ -384,6 +388,7 @@ Conflicts: gcc-c++ < 4.0.0 %patch22 -p1 %patch23 -p1 %patch24 -p1 +%patch25 -p1 # We cannot run autotools as there is an exact requirement of autoconf-2.59. # FIXME - this is no longer true. Maybe try reinstating autotool use ? @@ -780,6 +785,9 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Fri Aug 2 2019 Florian Weimer - 2.32-20 +- Fix ld -Map not to produce corrupt ELF notes (#1736114) + * Wed Jul 24 2019 Fedora Release Engineering - 2.32-19 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild