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


This patch adds the fix for i386/FreeBSD.


H.J.
----
2007-10-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/4424
	* config.bfd (targ_selvecs): Add bfd_efi_app_ia32_vec and
	bfd_elf32_i386_vec for i386/FreeBSD.
	(targ64_selvecs): Set for i386/FreeBSD.

	* 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/config.bfd.mixed	2007-09-08 18:23:19.000000000 -0700
+++ bfd/config.bfd	2007-10-15 10:06:45.000000000 -0700
@@ -535,7 +535,8 @@ case "${targ}" in
     ;;
   i[3-7]86-*-freebsd* | i[3-7]86-*-kfreebsd*-gnu | i[3-7]86-*-dragonfly*)
     targ_defvec=bfd_elf32_i386_freebsd_vec
-    targ_selvecs=i386coff_vec
+    targ_selvecs="i386coff_vec bfd_efi_app_ia32_vec bfd_elf32_i386_vec"
+    targ64_selvecs="bfd_efi_app_x86_64_vec bfd_elf64_x86_64_vec"
     # FreeBSD <= 4.0 supports only the old nonstandard way of ABI labelling.
     case "${targ}" in
       i[3-7]86-*-freebsd3* | i[3-7]86-*-freebsd4 | i[3-7]86-*-freebsd4.0*)
--- bfd/elf-bfd.h.mixed	2007-10-15 10:01:08.000000000 -0700
+++ bfd/elf-bfd.h	2007-10-15 10:01:10.000000000 -0700
@@ -1143,6 +1143,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-10-15 10:01:09.000000000 -0700
+++ bfd/elf32-i386.c	2007-10-15 10:01:10.000000000 -0700
@@ -4043,6 +4043,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
@@ -4124,6 +4125,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-10-15 10:01:10.000000000 -0700
+++ bfd/elf64-x86-64.c	2007-10-15 10:01:10.000000000 -0700
@@ -3914,6 +3914,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-10-15 10:01:10.000000000 -0700
+++ bfd/elflink.c	2007-10-15 10:01:10.000000000 -0700
@@ -3312,6 +3312,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;
@@ -4697,10 +4698,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-09-12 11:46:41.000000000 -0700
+++ bfd/elfxx-target.h	2007-10-15 10:01:10.000000000 -0700
@@ -606,6 +606,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 =
@@ -718,7 +722,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]