Backport fix for object files without ELF header flags set on RISC-V

This caused compilation errors for glib package.

Signed-off-by: David Abdurachmanov <david.abdurachmanov@gmail.com>
This commit is contained in:
David Abdurachmanov 2019-04-13 10:18:08 +02:00
parent 8e13e791f6
commit ccbd31cb6c
Signed by: davidlt
GPG Key ID: 7108702C938B13C1
2 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,59 @@
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 69cadaa2..ac6f136a 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -3084,8 +3084,7 @@ static bfd_boolean
_bfd_riscv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
{
bfd *obfd = info->output_bfd;
- flagword new_flags = elf_elfheader (ibfd)->e_flags;
- flagword old_flags = elf_elfheader (obfd)->e_flags;
+ flagword new_flags, old_flags;
if (!is_riscv_elf (ibfd) || !is_riscv_elf (obfd))
return TRUE;
@@ -3105,6 +3104,9 @@ _bfd_riscv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
if (!riscv_merge_attributes (ibfd, info))
return FALSE;
+ new_flags = elf_elfheader (ibfd)->e_flags;
+ old_flags = elf_elfheader (obfd)->e_flags;
+
if (! elf_flags_init (obfd))
{
elf_flags_init (obfd) = TRUE;
@@ -3112,6 +3114,34 @@ _bfd_riscv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
return TRUE;
}
+ /* Check to see if the input BFD actually contains any sections. If not,
+ its flags may not have been initialized either, but it cannot actually
+ cause any incompatibility. Do not short-circuit dynamic objects; their
+ section list may be emptied by elf_link_add_object_symbols.
+
+ Also check to see if there are no code sections in the input. In this
+ case, there is no need to check for code specific flags. */
+ if (!(ibfd->flags & DYNAMIC))
+ {
+ bfd_boolean null_input_bfd = TRUE;
+ bfd_boolean only_data_sections = TRUE;
+ asection *sec;
+
+ for (sec = ibfd->sections; sec != NULL; sec = sec->next)
+ {
+ if ((bfd_get_section_flags (ibfd, sec)
+ & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
+ == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
+ only_data_sections = FALSE;
+
+ null_input_bfd = FALSE;
+ break;
+ }
+
+ if (null_input_bfd || only_data_sections)
+ return TRUE;
+ }
+
/* Disallow linking different float ABIs. */
if ((old_flags ^ new_flags) & EF_RISCV_FLOAT_ABI)
{

View File

@ -85,7 +85,7 @@
Summary: A GNU collection of binary utilities
Name: %{?cross}binutils%{?_with_debug:-debug}
Version: 2.32
Release: 11%{?dist}
Release: 11.0.riscv64%{?dist}
License: GPLv3+
URL: https://sourceware.org/binutils
@ -206,6 +206,10 @@ Patch18: binutils-disassembling-efi-files.patch
# Lifetime: Fixed in 2.33
Patch19: binutils-CVE-2019-9071.patch
# Purpose: Fix object files without ELF headers on RISC-V
# Lifetime: Fixed in master (2.33)
# Commit: 87f98bacb76001157d5a26555a41738ac3841a56
Patch25: binutils-2.32-backport-24389.patch
#----------------------------------------------------------------------------
Provides: bundled(libiberty)
@ -352,6 +356,8 @@ Conflicts: gcc-c++ < 4.0.0
%patch18 -p1
%patch19 -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 ?
@ -752,6 +758,9 @@ exit 0
#----------------------------------------------------------------------------
%changelog
* Sat Apr 12 2019 David Abdurachmanov <david.abdurachmanov@gmail.com> - 2.32-11.0.riscv64
- Backport fix for binary objects without ELF headers flags set on RISC-V
* Wed Apr 10 2019 Nick Clifton <nickc@redhat.com> - 2.32-11
- Fix a stack exhaustion problem in libiberty's name demangling code. (#1680658)