This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] RISC-V: Don't check ABI flags if no code section.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=87f98bacb76001157d5a26555a41738ac3841a56

commit 87f98bacb76001157d5a26555a41738ac3841a56
Author: Jim Wilson <jimw@sifive.com>
Date:   Tue Apr 2 13:30:07 2019 -0700

    RISC-V: Don't check ABI flags if no code section.
    
    This fixes a glib build failure reported in PR 24389.  Using ld -b binary
    creates an object file with no elf header flags set which has the wrong ABI
    info for riscv64-linux.  But the file also has no code sections, so I added
    code borrowed from the arm port that only checks the ELF header ABI flags if
    there is a code section.
    
    	bfd/
    	PR 24389
    	* elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Move read of
    	ELF header flags to after check for ELF object file.  Loop through
    	sections looking for code sections, if none, then skip ABI checks.

Diff:
---
 bfd/ChangeLog     |  7 +++++++
 bfd/elfnn-riscv.c | 34 ++++++++++++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 2c630be..ca5a3a1 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2019-04-02  Jim Wilson  <jimw@sifive.com>
+
+	PR 24389
+	* elfnn-riscv.c (_bfd_riscv_elf_merge_private_bfd_data): Move read of
+	ELF header flags to after check for ELF object file.  Loop through
+	sections looking for code sections, if none, then skip ABI checks.
+
 2019-03-30  Andrew Waterman  <andrew@sifive.com>
 
 	* elfnn-riscv.c (_bfd_riscv_relax_call): Only check ARCH_SIZE for
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index dba1025..964b6bd 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -3086,8 +3086,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;
@@ -3107,6 +3106,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;
@@ -3114,6 +3116,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)
     {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]