Have the x86 linker resolve relocations against the _end, _edata and __bss_start symbols locally.

Resolves: #1576735
This commit is contained in:
Nick Clifton 2018-05-14 12:41:40 +01:00
parent 347768434c
commit 1f337663ab
2 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,64 @@
--- binutils.orig/bfd/elfxx-x86.c 2018-05-14 12:22:29.149657093 +0100
+++ binutils-2.30/bfd/elfxx-x86.c 2018-05-14 12:25:16.244700009 +0100
@@ -839,6 +839,33 @@ _bfd_x86_elf_compare_relocs (const void
return 0;
}
+/* Mark symbol, NAME, as locally defined by linker if it is referenced
+ and not defined in a relocatable object file. */
+
+static void
+elf_x86_linker_defined (struct bfd_link_info *info, const char *name)
+{
+ struct elf_link_hash_entry *h;
+
+ h = elf_link_hash_lookup (elf_hash_table (info), name,
+ FALSE, FALSE, FALSE);
+ if (h == NULL)
+ return;
+
+ while (h->root.type == bfd_link_hash_indirect)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+
+ if (h->root.type == bfd_link_hash_new
+ || h->root.type == bfd_link_hash_undefined
+ || h->root.type == bfd_link_hash_undefweak
+ || h->root.type == bfd_link_hash_common
+ || (!h->def_regular && h->def_dynamic))
+ {
+ elf_x86_hash_entry (h)->local_ref = 2;
+ elf_x86_hash_entry (h)->linker_def = 1;
+ }
+}
+
bfd_boolean
_bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
{
@@ -869,18 +896,16 @@ _bfd_x86_elf_link_check_relocs (bfd *abf
/* "__ehdr_start" will be defined by linker as a hidden symbol
later if it is referenced and not defined. */
- h = elf_link_hash_lookup (elf_hash_table (info),
- "__ehdr_start",
- FALSE, FALSE, FALSE);
- if (h != NULL
- && (h->root.type == bfd_link_hash_new
- || h->root.type == bfd_link_hash_undefined
- || h->root.type == bfd_link_hash_undefweak
- || h->root.type == bfd_link_hash_common))
+ elf_x86_linker_defined (info, "__ehdr_start");
+
+ if (bfd_link_executable (info))
{
- elf_x86_hash_entry (h)->local_ref = 2;
- elf_x86_hash_entry (h)->linker_def = 1;
- }
+ /* References to __bss_start, _end and _edata should be
+ locally resolved within executables. */
+ elf_x86_linker_defined (info, "__bss_start");
+ elf_x86_linker_defined (info, "_end");
+ elf_x86_linker_defined (info, "_edata");
+ }
}
}

View File

@ -69,7 +69,7 @@
Summary: A GNU collection of binary utilities
Name: %{?cross}binutils%{?_with_debug:-debug}
Version: 2.30
Release: 19%{?dist}
Release: 20%{?dist}
License: GPLv3+
Group: Development/Tools
URL: https://sourceware.org/binutils
@ -265,6 +265,11 @@ Patch31: binutils-CVE-2018-10534.patch
# Lifetime: Fixed in 2.31
Patch32: binutils-CVE-2018-10535.patch
# Purpose: Have the x86 linker resolve relocations against the _end,
# __bss_start and -edata symbols locally.
# Lifetime: Fixed in 2.31
Patch33: binutils-x86-local-relocs.patch
#----------------------------------------------------------------------------
Provides: bundled(libiberty)
@ -422,6 +427,7 @@ using libelf instead of BFD.
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
# We cannot run autotools as there is an exact requirement of autoconf-2.59.
@ -835,6 +841,9 @@ exit 0
#----------------------------------------------------------------------------
%changelog
* Mon May 14 2018 Nick Clifton <nickc@redhat.com> 2.30-20
- Have the x86 linker resolve relocations against the _end, _edata and __bss_start symbols locally. (#1576735)
* Thu May 10 2018 Nick Clifton <nickc@redhat.com> 2.30-19
- Fix a seg-fault running objcopy on a corrupt PE format file. (#1574702)
- Fix a seg-fault running objcopy on a corrupt ELF format file. (#1574705)