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

PATCH: PR ld/4424: Can't link in Linux object files on FreeBSD


On Thu, Aug 30, 2007 at 10:36:13AM -0700, H.J. Lu wrote:
> On Thu, Aug 30, 2007 at 07:18:03PM +0200, Robert Sebastian Gerus wrote:
> > > you're using binutils-2.18 from Gentoo right ?  try building binutils-2.18
> > > with USE=vanilla please
> > Already tried that, didn't help.
> > 
> > > along those lines, just run `readelf -d /usr/lib/gcc41/crt1.o` ... that should
> > > give you a pretty quick answer; just look for any field which comes up
> > > unrecognized
> > 
> > > Object files do not have dynamic tags.  Perhaps you mean section types?
> > Well...
> > kagerou ~ # readelf -a /usr/lib/gcc41/crt1.o | grep -i unr
> > kagerou ~ #
> > I'm attaching the whole output of ``readelf -a /usr/lib/gcc41/crt1.o''
> > 
> 
> You may run into
> 
> http://www.sourceware.org/bugzilla/show_bug.cgi?id=4424
> 

This is my current patch.


H.J.
---
2007-08-02  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/4424
	* elf-bfd.h (elf_backend_data): Add always_check_relocs_in_object_file.

	* elf32-i386.c (elf_backend_always_check_relocs_in_object_file):
	Defined as 1.  Undefine for vxworks.

	* elf64-x86-64.c (elf_backend_always_check_relocs_in_object_file):
	Defined as 1.

	* elflink.c (elf_link_add_object_symbols): Also check the
	always_check_relocs_in_object_file bit to see if relocations in
	input relocatable file can be processed.

	* elfxx-target.h (elf_backend_always_check_relocs_in_object_file):
	New.  Default to 0.
	(elfNN_bed): Add elf_backend_always_check_relocs_in_object_file.

--- bfd/elf-bfd.h.mixed	2007-08-03 09:44:35.000000000 -0700
+++ bfd/elf-bfd.h	2007-08-03 09:47:54.000000000 -0700
@@ -1149,6 +1149,11 @@ struct elf_backend_data
      other file in the link needs to have a .note.GNU-stack section
      for a PT_GNU_STACK segment to be created.  */
   unsigned default_execstack : 1;
+
+  /* TRUE if relocations in object file should always be checked.  It
+     is used by i386 and x86-64 linkers to link again object files with
+     different EI_OSABI.  PR 4424.  */
+  unsigned always_check_relocs_in_object_file : 1;
 };
 
 /* Information stored for each BFD section in an ELF file.  This
--- bfd/elf32-i386.c.mixed	2007-08-03 09:44:35.000000000 -0700
+++ bfd/elf32-i386.c	2007-08-03 09:44:35.000000000 -0700
@@ -3863,6 +3863,7 @@ elf_i386_hash_symbol (struct elf_link_ha
   ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true)
 #define elf_backend_plt_sym_val		      elf_i386_plt_sym_val
 #define elf_backend_hash_symbol		      elf_i386_hash_symbol
+#define elf_backend_always_check_relocs_in_object_file	      1
 
 #define elf_backend_add_symbol_hook \
   _bfd_elf_add_sharable_symbol
@@ -3944,6 +3945,7 @@ elf_i386_vxworks_link_hash_table_create 
   return ret;
 }
 
+#undef elf_backend_always_check_relocs_in_object_file
 
 #undef	elf_backend_post_process_headers
 #undef bfd_elf32_bfd_link_hash_table_create
--- bfd/elf64-x86-64.c.mixed	2007-08-03 09:44:35.000000000 -0700
+++ bfd/elf64-x86-64.c	2007-08-03 09:44:35.000000000 -0700
@@ -3746,6 +3746,7 @@ static const struct bfd_elf_special_sect
   elf64_x86_64_additional_program_headers
 #define elf_backend_hash_symbol \
   elf64_x86_64_hash_symbol
+#define elf_backend_always_check_relocs_in_object_file 1
 
 #include "elf64-target.h"
 
--- bfd/elflink.c.mixed	2007-08-03 09:44:35.000000000 -0700
+++ bfd/elflink.c	2007-08-03 10:02:04.000000000 -0700
@@ -3304,6 +3304,7 @@ elf_link_add_object_symbols (bfd *abfd, 
   Elf_Internal_Sym *isym;
   Elf_Internal_Sym *isymend;
   const struct elf_backend_data *bed;
+  const struct elf_backend_data *obed;
   bfd_boolean add_needed;
   struct elf_link_hash_table *htab;
   bfd_size_type amt;
@@ -4685,10 +4686,18 @@ elf_link_add_object_symbols (bfd *abfd, 
      This would be a good case for using mmap.
 
      I have no idea how to handle linking PIC code into a file of a
-     different format.  It probably can't be done.  */
+     different format.  It probably can't be done.
+
+     If this object has the same arch as the output object and both
+     targets have the always_check_relocs_in_object_file bit set,
+     then let the backend look through the relocs.  PR 4424.  */
+  obed = xvec_get_elf_backend_data (htab->root.creator);
   if (! dynamic
       && is_elf_hash_table (htab)
-      && htab->root.creator == abfd->xvec
+      && (htab->root.creator == abfd->xvec
+	  || ((obed->arch == bed->arch)
+	      && obed->always_check_relocs_in_object_file
+	      && bed->always_check_relocs_in_object_file))
       && bed->check_relocs != NULL)
     {
       asection *o;
--- bfd/elfxx-target.h.mixed	2007-07-24 15:03:50.000000000 -0700
+++ bfd/elfxx-target.h	2007-08-03 09:44:35.000000000 -0700
@@ -605,6 +605,10 @@
 #define elf_backend_is_function_type _bfd_elf_is_function_type
 #endif
 
+#ifndef elf_backend_always_check_relocs_in_object_file
+#define elf_backend_always_check_relocs_in_object_file 0
+#endif
+
 extern const struct elf_size_info _bfd_elfNN_size_info;
 
 static struct elf_backend_data elfNN_bed =
@@ -719,7 +723,8 @@ static struct elf_backend_data elfNN_bed
   elf_backend_want_got_sym,
   elf_backend_want_dynbss,
   elf_backend_want_p_paddr_set_to_zero,
-  elf_backend_default_execstack
+  elf_backend_default_execstack,
+  elf_backend_always_check_relocs_in_object_file
 };
 
 /* Forward declaration for use when initialising alternative_target field.  */


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