From 871bf81821c15919d10c51795716bc5099d4af5a Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mar 07 2018 14:37:36 +0000 Subject: Treat relocs against IFUNC symbols in note sections as relocs against the FUNC symbol instead. Relates: #1552056 --- diff --git a/binutils-strip-unknown-relocs.patch b/binutils-strip-unknown-relocs.patch new file mode 100644 index 0000000..d8ecd84 --- /dev/null +++ b/binutils-strip-unknown-relocs.patch @@ -0,0 +1,107 @@ +diff -rup binutils.orig/bfd/elf32-i386.c binutils-2.30/bfd/elf32-i386.c +--- binutils.orig/bfd/elf32-i386.c 2018-02-27 17:25:53.961140597 +0000 ++++ binutils-2.30/bfd/elf32-i386.c 2018-02-27 17:27:14.115133477 +0000 +@@ -383,7 +383,7 @@ elf_i386_rtype_to_howto (bfd *abfd, unsi + /* xgettext:c-format */ + _bfd_error_handler (_("%B: invalid relocation type %d"), + abfd, (int) r_type); +- indx = R_386_NONE; ++ return NULL; + } + /* PR 17512: file: 0f67f69d. */ + if (elf_howto_table [indx].type != r_type) +diff -rup binutils.orig/bfd/elf64-ppc.c binutils-2.30/bfd/elf64-ppc.c +--- binutils.orig/bfd/elf64-ppc.c 2018-02-27 17:25:53.969140496 +0000 ++++ binutils-2.30/bfd/elf64-ppc.c 2018-02-27 17:27:56.213604518 +0000 +@@ -2516,9 +2516,10 @@ ppc64_elf_info_to_howto (bfd *abfd, arel + /* xgettext:c-format */ + _bfd_error_handler (_("%B: invalid relocation type %d"), + abfd, (int) type); +- type = R_PPC64_NONE; ++ cache_ptr->howto = NULL; + } +- cache_ptr->howto = ppc64_elf_howto_table[type]; ++ else ++ cache_ptr->howto = ppc64_elf_howto_table[type]; + } + + /* Handle the R_PPC64_ADDR16_HA and similar relocs. */ +diff -rup binutils.orig/bfd/elf64-s390.c binutils-2.30/bfd/elf64-s390.c +--- binutils.orig/bfd/elf64-s390.c 2018-02-27 17:25:53.968140509 +0000 ++++ binutils-2.30/bfd/elf64-s390.c 2018-02-27 17:28:24.632247443 +0000 +@@ -372,9 +372,10 @@ elf_s390_info_to_howto (bfd *abfd ATTRIB + /* xgettext:c-format */ + _bfd_error_handler (_("%B: invalid relocation type %d"), + abfd, (int) r_type); +- r_type = R_390_NONE; ++ cache_ptr->howto = NULL; + } +- cache_ptr->howto = &elf_howto_table[r_type]; ++ else ++ cache_ptr->howto = &elf_howto_table[r_type]; + } + } + +diff -rup binutils.orig/bfd/elf64-x86-64.c binutils-2.30/bfd/elf64-x86-64.c +--- binutils.orig/bfd/elf64-x86-64.c 2018-02-27 17:25:53.964140559 +0000 ++++ binutils-2.30/bfd/elf64-x86-64.c 2018-02-27 17:29:12.554645307 +0000 +@@ -284,7 +284,7 @@ elf_x86_64_rtype_to_howto (bfd *abfd, un + /* xgettext:c-format */ + _bfd_error_handler (_("%B: invalid relocation type %d"), + abfd, (int) r_type); +- r_type = R_X86_64_NONE; ++ return NULL; + } + i = r_type; + } +@@ -347,8 +347,6 @@ elf_x86_64_info_to_howto (bfd *abfd ATTR + && r_type != (unsigned int) R_X86_64_GNU_VTENTRY) + r_type &= ~R_X86_64_converted_reloc_bit; + cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type); +- +- BFD_ASSERT (r_type == cache_ptr->howto->type || cache_ptr->howto->type == R_X86_64_NONE); + } + + /* Support for core dump NOTE sections. */ +diff -rup binutils.orig/bfd/elfcode.h binutils-2.30/bfd/elfcode.h +--- binutils.orig/bfd/elfcode.h 2018-02-27 17:25:53.964140559 +0000 ++++ binutils-2.30/bfd/elfcode.h 2018-02-27 17:26:57.234345581 +0000 +@@ -1474,6 +1474,12 @@ elf_slurp_reloc_table_from_section (bfd + (*ebd->elf_info_to_howto) (abfd, relent, &rela); + else + (*ebd->elf_info_to_howto_rel) (abfd, relent, &rela); ++ ++ if (relent->howto == NULL) ++ { ++ bfd_set_error (bfd_error_bad_value); ++ goto error_return; ++ } + } + + if (allocated != NULL) +diff -rup binutils.orig/binutils/objcopy.c binutils-2.30/binutils/objcopy.c +--- binutils.orig/binutils/objcopy.c 2018-02-27 17:25:53.185150347 +0000 ++++ binutils-2.30/binutils/objcopy.c 2018-02-27 17:30:05.806976202 +0000 +@@ -3022,10 +3022,19 @@ copy_object (bfd *ibfd, bfd *obfd, const + haven't been set yet. mark_symbols_used_in_relocations will + ignore input sections which have no corresponding output + section. */ ++ bfd_set_error (bfd_error_no_error); + if (strip_symbols != STRIP_ALL) +- bfd_map_over_sections (ibfd, +- mark_symbols_used_in_relocations, +- isympp); ++ { ++ bfd_map_over_sections (ibfd, ++ mark_symbols_used_in_relocations, ++ isympp); ++ if (bfd_get_error () != bfd_error_no_error) ++ { ++ status = 1; ++ return FALSE; ++ } ++ } ++ + osympp = (asymbol **) xmalloc ((symcount + add_symbols + 1) * sizeof (asymbol *)); + symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount); + } diff --git a/binutils-x86_64-ifunc-relocs-in-notes.patch b/binutils-x86_64-ifunc-relocs-in-notes.patch new file mode 100644 index 0000000..9cc629d --- /dev/null +++ b/binutils-x86_64-ifunc-relocs-in-notes.patch @@ -0,0 +1,64 @@ +diff -rup binutils.orig/bfd/elf32-i386.c binutils-2.30/bfd/elf32-i386.c +--- binutils.orig/bfd/elf32-i386.c 2018-03-07 14:17:57.645689834 +0000 ++++ binutils-2.30/bfd/elf32-i386.c 2018-03-07 14:22:39.987385632 +0000 +@@ -2202,12 +2202,19 @@ elf_i386_relocate_section (bfd *output_b + + if ((input_section->flags & SEC_ALLOC) == 0) + { ++ /* If this is a SHT_NOTE section without SHF_ALLOC, treat ++ STT_GNU_IFUNC symbol as STT_FUNC. */ ++ if (elf_section_type (input_section) == SHT_NOTE) ++ goto skip_ifunc; + /* Dynamic relocs are not propagated for SEC_DEBUGGING + sections because such sections are not SEC_ALLOC and + thus ld.so will not process them. */ + if ((input_section->flags & SEC_DEBUGGING) != 0) + continue; +- abort (); ++ _bfd_error_handler (_("%B: error: relocation againt ifunc symbol in non-alloc section %A"), ++ input_bfd, input_section); ++ bfd_set_error (bfd_error_invalid_operation); ++ return FALSE; + } + + /* STT_GNU_IFUNC symbol must go through PLT. */ +@@ -2421,6 +2428,7 @@ do_ifunc_pointer: + } + } + ++ skip_ifunc: + resolved_to_zero = (eh != NULL + && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh)); + +diff -rup binutils.orig/bfd/elf64-x86-64.c binutils-2.30/bfd/elf64-x86-64.c +--- binutils.orig/bfd/elf64-x86-64.c 2018-03-07 14:17:57.691689296 +0000 ++++ binutils-2.30/bfd/elf64-x86-64.c 2018-03-07 14:22:33.907456784 +0000 +@@ -2499,12 +2499,19 @@ elf_x86_64_relocate_section (bfd *output + + if ((input_section->flags & SEC_ALLOC) == 0) + { ++ /* If this is a SHT_NOTE section without SHF_ALLOC, treat ++ STT_GNU_IFUNC symbol as STT_FUNC. */ ++ if (elf_section_type (input_section) == SHT_NOTE) ++ goto skip_ifunc; + /* Dynamic relocs are not propagated for SEC_DEBUGGING + sections because such sections are not SEC_ALLOC and + thus ld.so will not process them. */ + if ((input_section->flags & SEC_DEBUGGING) != 0) + continue; +- abort (); ++ _bfd_error_handler (_("%B: error: relocation againt ifunc symbol in non-alloc section %A"), ++ input_bfd, input_section); ++ bfd_set_error (bfd_error_invalid_operation); ++ return FALSE; + } + + switch (r_type) +@@ -2722,6 +2729,7 @@ do_ifunc_pointer: + } + } + ++ skip_ifunc: + resolved_to_zero = (eh != NULL + && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh)); + diff --git a/binutils.spec b/binutils.spec index d555f42..8a0318e 100644 --- a/binutils.spec +++ b/binutils.spec @@ -62,7 +62,7 @@ Summary: A GNU collection of binary utilities Name: %{?cross}binutils%{?_with_debug:-debug} Version: 2.30 -Release: 8%{?dist} +Release: 10%{?dist} License: GPLv3+ Group: Development/Tools URL: https://sourceware.org/binutils @@ -159,20 +159,30 @@ Patch11: binutils-skip-dwo-search-if-not-needed.patch # Lifetime: Fixed in 2.30.1 and/or 2.31. Patch12: binutils-page-to-segment-assignment.patch -# Purpose: Fix a bug in ld for linking against AARCH64 UEFI +# Purpose: Fix a bug in ld for linking against AARCH64 UEFI # Lifetime: Fixed in 2.30.1 and/or 2.31 Patch13: binutils-2.30-allow_R_AARCH64-symbols.patch +# Purpose: Stop strip from replacing unknown relocs with null relocs. Make +# it return an error status and not strip the file instead. +# Lifetime: Fixed in 2.31. +Patch14: binutils-strip-unknown-relocs.patch + # Purpose: Improves objdump's function for locating a symbol to match a # given address, so that it uses a binary chop algorithm. # Lifetime: Fixed in 2.31. -Patch14: binutils-speed-up-objdump.patch +Patch15: binutils-speed-up-objdump.patch # Purpose: Ignore duplicate indirect symbols generated by GOLD. # Lifetime: Permanent. # FIXME: This problem needs to be resolved in the FSF sources, but the # GOLD maintainers seem to be reluctant to address the issue. -Patch15: binutils-2.28-ignore-gold-duplicates.patch +Patch16: binutils-2.28-ignore-gold-duplicates.patch + +# Purpose: Treat relosc against STT_GNU_IFUNC symbols in note sections as +# if they were relocs against STT_FUNC symbols instead. +# Lifetime: Fixed in 2.31. +Patch17: binutils-x86_64-ifunc-relocs-in-notes.patch #---------------------------------------------------------------------------- @@ -314,6 +324,8 @@ using libelf instead of BFD. %patch13 -p1 %patch14 -p1 %patch15 -p1 +%patch16 -p1 +%patch17 -p1 # We cannot run autotools as there is an exact requirement of autoconf-2.59. @@ -722,6 +734,12 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Wed Mar 07 2018 Nick Clifton 2.30-10 +- Treat relocs against IFUNC symbols in note sections as relocs against the FUNC symbol instead. (#1552056) + +* Wed Mar 07 2018 Nick Clifton 2.30-9 +- Stop strip from replacing unknown relocs with null relocs. (#1545386) + * Wed Mar 07 2018 Nick Clifton 2.30-8 - Ignore duplicate symbols generated by GOLD. (#1458003)