This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: PR ld/4424: Can't link in Linux object files on FreeBSD
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Tue, 24 Apr 2007 17:27:24 -0700
- Subject: Re: PATCH: PR ld/4424: Can't link in Linux object files on FreeBSD
- References: <20070424225840.GA16546@lucon.org>
On Tue, Apr 24, 2007 at 03:58:40PM -0700, H. J. Lu wrote:
> This patch adds elf_backend_is_target_compatible to check if output
> hash table is compatible with input.
>
I renamed is_target_compatible to input_compatible and limited it
to only check if input relocatable file is compatible with output.
H.J.
----
2007-04-24 H.J. Lu <hongjiu.lu@intel.com>
PR ld/4424
* elf-bfd.h (elf_backend_data): Add input_compatible.
(_bfd_elf_input_compatible): Add prototype.
* elf.c (_bfd_elf_input_compatible): New.
* elf32-i386.c (elf_i386_input_compatible): New.
(elf_backend_input_compatible): Define. Undefine for vxworks.
* elf64-x86-64.c (elf64_x86_64_input_compatible): New.
(elf_backend_input_compatible): Define.
* elflink.c (elf_link_add_object_symbols): Use
bed->input_compatible to check if input relocatable file is
compatible with output.
* elfxx-target.h (elf_backend_input_compatible): Add default
definition.
(elfNN_bed): Add elf_backend_input_compatible.
--- bfd/elf-bfd.h.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elf-bfd.h 2007-04-24 17:20:13.000000000 -0700
@@ -1053,6 +1053,10 @@ struct elf_backend_data
/* Return TRUE if type is a function symbol type. */
bfd_boolean (*is_function_type) (unsigned int type);
+ /* Return TRUE if input bfd is compatible with output. */
+ bfd_boolean (*input_compatible) (bfd *input,
+ const bfd_target *output);
+
/* Used to handle bad SHF_LINK_ORDER input. */
bfd_error_handler_type link_order_error_handler;
@@ -1943,6 +1947,9 @@ extern bfd_boolean _bfd_elf_map_sections
extern bfd_boolean _bfd_elf_is_function_type (unsigned int);
+extern bfd_boolean _bfd_elf_input_compatible (bfd *,
+ const bfd_target *);
+
/* Exported interface for writing elf corefile notes. */
extern char *elfcore_write_note
(bfd *, char *, int *, const char *, int, const void *, int);
--- bfd/elf.c.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elf.c 2007-04-24 17:17:46.000000000 -0700
@@ -9371,3 +9371,11 @@ _bfd_elf_is_function_type (unsigned int
{
return (type == STT_FUNC);
}
+
+/* Return TRUE if INPUT is compatible with OUTPUT. */
+
+bfd_boolean
+_bfd_elf_input_compatible (bfd *input, const bfd_target *output)
+{
+ return input->xvec == output;
+}
--- bfd/elf32-i386.c.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elf32-i386.c 2007-04-24 17:22:47.000000000 -0700
@@ -3837,6 +3837,17 @@ elf_i386_hash_symbol (struct elf_link_ha
return _bfd_elf_hash_symbol (h);
}
+static bfd_boolean
+elf_i386_input_compatible (bfd *input, const bfd_target *output)
+{
+ extern const bfd_target bfd_elf32_i386_vec;
+ extern const bfd_target bfd_elf32_i386_freebsd_vec;
+
+ return (output == input->xvec
+ || output == &bfd_elf32_i386_vec
+ || output == &bfd_elf32_i386_freebsd_vec);
+}
+
#define TARGET_LITTLE_SYM bfd_elf32_i386_vec
#define TARGET_LITTLE_NAME "elf32-i386"
#define ELF_ARCH bfd_arch_i386
@@ -3880,6 +3891,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_input_compatible elf_i386_input_compatible
#define elf_backend_add_symbol_hook \
_bfd_elf_add_sharable_symbol
@@ -3961,6 +3973,7 @@ elf_i386_vxworks_link_hash_table_create
return ret;
}
+#undef elf_backend_input_compatible
#undef elf_backend_post_process_headers
#undef bfd_elf32_bfd_link_hash_table_create
--- bfd/elf64-x86-64.c.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elf64-x86-64.c 2007-04-24 17:21:13.000000000 -0700
@@ -3692,6 +3692,17 @@ elf64_x86_64_hash_symbol (struct elf_lin
return _bfd_elf_hash_symbol (h);
}
+static bfd_boolean
+elf64_x86_64_input_compatible (bfd *input, const bfd_target *output)
+{
+ extern const bfd_target bfd_elf64_x86_64_vec;
+ extern const bfd_target bfd_elf64_x86_64_freebsd_vec;
+
+ return (output == input->xvec
+ || output == &bfd_elf64_x86_64_vec
+ || output == &bfd_elf64_x86_64_freebsd_vec);
+}
+
static const struct bfd_elf_special_section
elf64_x86_64_special_sections[]=
{
@@ -3770,6 +3781,8 @@ 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_input_compatible \
+ elf64_x86_64_input_compatible
#include "elf64-target.h"
--- bfd/elflink.c.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elflink.c 2007-04-24 17:20:40.000000000 -0700
@@ -4622,7 +4622,7 @@ elf_link_add_object_symbols (bfd *abfd,
different format. It probably can't be done. */
if (! dynamic
&& is_elf_hash_table (htab)
- && htab->root.creator == abfd->xvec
+ && bed->input_compatible (abfd, htab->root.creator)
&& bed->check_relocs != NULL)
{
asection *o;
--- bfd/elfxx-target.h.mixed 2007-04-18 06:14:49.000000000 -0700
+++ bfd/elfxx-target.h 2007-04-24 17:19:56.000000000 -0700
@@ -591,6 +591,10 @@
#define elf_backend_is_function_type _bfd_elf_is_function_type
#endif
+#ifndef elf_backend_input_compatible
+#define elf_backend_input_compatible _bfd_elf_input_compatible
+#endif
+
extern const struct elf_size_info _bfd_elfNN_size_info;
static struct elf_backend_data elfNN_bed =
@@ -677,6 +681,7 @@ static struct elf_backend_data elfNN_bed
elf_backend_merge_symbol,
elf_backend_hash_symbol,
elf_backend_is_function_type,
+ elf_backend_input_compatible,
elf_backend_link_order_error_handler,
elf_backend_relplt_name,
ELF_MACHINE_ALT1,