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/binutils-2_29-branch] Add more targets to the list of architectures not supporting format changing during linking. Fix se


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

commit 7476906bc53665adfef4c4598774584eb34cc5af
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu Aug 3 11:59:32 2017 +0100

    Add more targets to the list of architectures not supporting format changing during linking.  Fix seg-faults triggered when this is attempted.
    
    	PR ld/21884
    	* testsuite/ld-elf/pr21884.d: Add AVR, HPPA, IA64, M68HC1x and
    	SCORE to list of targets not supporting file format changes during
    	linking.
    	* testsuite/ld-unique/pr21529.d: Likewise.
    	* emultempl/avrelf.em (_before_allocation): Skip for non-ELF
    	output formats.
    	(avr_elf_create_output_section_statements): Fail if the output
    	format is not ELF.
    	(avr_finish): Do not access the ELF header in non-ELF format
    	output bfds.
    	* emultempl/m68hc1xelf.em (_before_allocation): Skip for non-ELF
    	output formats.
    	(m68hc11elf_create_output_section_statements): Fail if the putput
    	format is not ELF.
    	(m68hc11elf_after_allocation): Skip for non-ELF output formats.

Diff:
---
 ld/ChangeLog                     | 19 +++++++++++++++++++
 ld/emultempl/avrelf.em           | 24 ++++++++++++++++++++----
 ld/emultempl/m68hc1xelf.em       | 38 +++++++++++++++++++++++++-------------
 ld/testsuite/ld-elf/pr21884.d    |  2 +-
 ld/testsuite/ld-unique/pr21529.d |  3 ++-
 5 files changed, 67 insertions(+), 19 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 81b3dc6..2854372 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,22 @@
+2017-08-03  Nick Clifton  <nickc@redhat.com>
+
+	PR ld/21884
+	* testsuite/ld-elf/pr21884.d: Add AVR, HPPA, IA64, M68HC1x and
+	SCORE to list of targets not supporting file format changes during
+	linking.
+	* testsuite/ld-unique/pr21529.d: Likewise.
+	* emultempl/avrelf.em (_before_allocation): Skip for non-ELF
+	output formats.
+	(avr_elf_create_output_section_statements): Fail if the output
+	format is not ELF.
+	(avr_finish): Do not access the ELF header in non-ELF format
+	output bfds.
+	* emultempl/m68hc1xelf.em (_before_allocation): Skip for non-ELF
+	output formats.
+	(m68hc11elf_create_output_section_statements): Fail if the putput
+	format is not ELF.
+	(m68hc11elf_after_allocation): Skip for non-ELF output formats.
+
 2017-07-25  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/ld-powerpc/tlsopt5.s: Add cfi.
diff --git a/ld/emultempl/avrelf.em b/ld/emultempl/avrelf.em
index 2072124..acb478f 100644
--- a/ld/emultempl/avrelf.em
+++ b/ld/emultempl/avrelf.em
@@ -71,6 +71,12 @@ avr_elf_${EMULATION_NAME}_before_allocation (void)
 
   gld${EMULATION_NAME}_before_allocation ();
 
+  if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
+    {
+      avr_no_stubs = TRUE;
+      return;
+    }
+
   /* We only need stubs for avr6, avrxmega6, and avrxmega7. */
   if (strcmp ("${EMULATION_NAME}","avr6")
       && strcmp ("${EMULATION_NAME}","avrxmega6")
@@ -108,6 +114,12 @@ avr_elf_create_output_section_statements (void)
 {
   flagword flags;
 
+  if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
+    {
+      einfo ("%X%P: changing output format whilst linking is not supported\n");
+      return;
+    }
+
   stub_file = lang_add_input_file ("linker stubs",
                                    lang_input_file_is_fake_enum,
                                    NULL);
@@ -204,10 +216,14 @@ avr_finish (void)
     }
 
   abfd = link_info.output_bfd;
-  if (avr_link_relax)
-    elf_elfheader (abfd)->e_flags |= EF_AVR_LINKRELAX_PREPARED;
-  else
-    elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
+
+  if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour)
+    {
+      if (avr_link_relax)
+	elf_elfheader (abfd)->e_flags |= EF_AVR_LINKRELAX_PREPARED;
+      else
+	elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
+    }
 
   finish_default ();
 }
diff --git a/ld/emultempl/m68hc1xelf.em b/ld/emultempl/m68hc1xelf.em
index bfe88d6..f7337da 100644
--- a/ld/emultempl/m68hc1xelf.em
+++ b/ld/emultempl/m68hc1xelf.em
@@ -66,6 +66,9 @@ m68hc11_elf_${EMULATION_NAME}_before_allocation (void)
 
   gld${EMULATION_NAME}_before_allocation ();
 
+  if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
+    return;
+
   /* If generating a relocatable output file, then we don't
      have to generate the trampolines.  */
   if (bfd_link_relocatable (&link_info))
@@ -141,6 +144,12 @@ m68hc11_elf_${EMULATION_NAME}_before_allocation (void)
 static void
 m68hc11elf_create_output_section_statements (void)
 {
+  if (bfd_get_flavour (link_info.output_bfd) != bfd_target_elf_flavour)
+    {
+      einfo ("%X%P: changing output format whilst linking is not supported\n");
+      return;
+    }
+
   stub_file = lang_add_input_file ("linker stubs",
 				   lang_input_file_is_fake_enum,
 				   NULL);
@@ -286,22 +295,25 @@ m68hc11elf_add_stub_section (const char *stub_sec_name,
 static void
 m68hc11elf_after_allocation (void)
 {
-  /* Now build the linker stubs.  */
-  if (stub_file->the_bfd->sections != NULL)
+  if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour)
     {
-      /* Call again the trampoline analyzer to initialize the trampoline
-	 stubs with the correct symbol addresses.  Since there could have
-	 been relaxation, the symbol addresses that were found during
-	 first call may no longer be correct.  */
-      if (!elf32_m68hc11_size_stubs (link_info.output_bfd,
-				     stub_file->the_bfd,
-				     &link_info, 0))
+      /* Now build the linker stubs.  */
+      if (stub_file->the_bfd->sections != NULL)
 	{
-	  einfo ("%X%P: can not size stub section: %E\n");
-	  return;
+	  /* Call again the trampoline analyzer to initialize the trampoline
+	     stubs with the correct symbol addresses.  Since there could have
+	     been relaxation, the symbol addresses that were found during
+	     first call may no longer be correct.  */
+	  if (!elf32_m68hc11_size_stubs (link_info.output_bfd,
+					 stub_file->the_bfd,
+					 &link_info, 0))
+	    {
+	      einfo ("%X%P: can not size stub section: %E\n");
+	      return;
+	    }
+	  if (!elf32_m68hc11_build_stubs (link_info.output_bfd, &link_info))
+	    einfo ("%X%P: can not build stubs: %E\n");
 	}
-      if (!elf32_m68hc11_build_stubs (link_info.output_bfd, &link_info))
-	einfo ("%X%P: can not build stubs: %E\n");
     }
 
   gld${EMULATION_NAME}_after_allocation ();
diff --git a/ld/testsuite/ld-elf/pr21884.d b/ld/testsuite/ld-elf/pr21884.d
index 52cd2c1..0de7b83 100644
--- a/ld/testsuite/ld-elf/pr21884.d
+++ b/ld/testsuite/ld-elf/pr21884.d
@@ -2,7 +2,7 @@
 #source: pr21884b.s
 #ld: -T pr21884.t
 #objdump: -b binary -s
-#notarget: aarch64*-*-* arm*-*-* nds32*-*-*
+#notarget: aarch64*-*-* arm*-*-* avr-*-* hppa-*-* ia64-*-* m68hc1*-*-* nds32*-*-* score-*-*
 # Skip targets which can't change output format to binary.
 
 .*:     file format binary
diff --git a/ld/testsuite/ld-unique/pr21529.d b/ld/testsuite/ld-unique/pr21529.d
index bc4763d..5d3436b 100644
--- a/ld/testsuite/ld-unique/pr21529.d
+++ b/ld/testsuite/ld-unique/pr21529.d
@@ -1,5 +1,6 @@
 #ld: --oformat binary -T pr21529.ld -e main
 #objdump: -s -b binary
-#xfail: aarch64*-*-* arm*-*-* hppa-*-* ia64-*-* nds32*-*-* score-*-*
+#notarget: aarch64*-*-* arm*-*-* avr-*-* hppa-*-* ia64-*-* m68hc1*-*-* nds32*-*-* score-*-*
+# Skip targets which can't change output format to binary.
 
 #pass


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