This is the mail archive of the binutils@sources.redhat.com 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]

Re: Patch: Check input format against output


On Sun, Mar 25, 2001 at 11:10:21PM -0800, Ian Lance Taylor wrote:
> "H . J . Lu" <hjl@lucon.org> writes:
> 
> > How about this patch? You can link a SPARC ELF input into a i386
> > ELF output file as long as your BFD supports SPARC ELF.
> 
> This approach just seems odd to me.  It doesn't seem to address the
> underlying problem, which is that the generic ELF backends don't
> support linking.  If you fix that problem to give an appropriate
> error, then the problem you are trying to address goes away.  Fixing
> the generic ELF backend problem also fixes other aspects of the
> problem not addressed by your patch, like linking directly to
> S-records.

I believe we can use the generic ELF backends as input during final
link as long as no relocations were involved. We should only flag an
error if there are any relocations for the generic ELF backends. How
about this new patch.

Thanks.


H.J.
---
Index: elflink.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elflink.h,v
retrieving revision 1.53
diff -u -p -r1.53 elflink.h
--- elflink.h	2001/03/09 19:37:59	1.53
+++ elflink.h	2001/03/26 21:36:21
@@ -5465,10 +5465,36 @@ elf_link_input_bfd (finfo, input_bfd)
   asection **ppsection;
   asection *o;
   struct elf_backend_data *bed;
+  struct elf_backend_data *i_bed;
 
   output_bfd = finfo->output_bfd;
   bed = get_elf_backend_data (output_bfd);
   relocate_section = bed->elf_backend_relocate_section;
+  i_bed = get_elf_backend_data (input_bfd);
+
+  if (i_bed->elf_machine_code == EM_NONE)
+    {
+      /* Check if there are any relocations.  */
+      for (o = input_bfd->sections; o != NULL; o = o->next)
+	if ((o->flags & SEC_RELOC) != 0)
+	  {
+	    Elf_Internal_Ehdr *i_ehdrp;
+
+	    i_ehdrp = elf_elfheader (input_bfd);
+	    if (input_bfd->my_archive)
+	      (*_bfd_error_handler) (_("%s(%s): Relocations in generic ELF (EM: %d)"),
+				     bfd_get_filename (input_bfd->my_archive),
+				     bfd_get_filename (input_bfd),
+				     i_ehdrp->e_machine);
+	    else
+	      (*_bfd_error_handler) (_("%s: Relocations in generic ELF (EM: %d)"),
+				     bfd_get_filename (input_bfd),
+				     i_ehdrp->e_machine);
+
+	    bfd_set_error (bfd_error_wrong_format);
+	    return false;
+	  }
+    }
 
   /* If this is a dynamic object, we don't want to do anything here:
      we don't want the local symbols, and we don't want the section


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