This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
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 15:58:40 -0700
- Subject: PATCH: PR ld/4424: Can't link in Linux object files on FreeBSD
This patch adds elf_backend_is_target_compatible to check if output
hash table is compatible with input.
H.J.
----
2007-04-24 H.J. Lu <hongjiu.lu@intel.com>
PR ld/4424
* elf-bfd.h (elf_backend_data): Add is_target_compatible.
(_bfd_elf_is_target_compatible): Add prototype.
* elf.c (_bfd_elf_is_target_compatible): New.
* elf32-i386.c (elf_i386_is_target_compatible): New.
(elf_backend_is_target_compatible): Define. Undefine for
vxworks.
* elf64-x86-64.c (elf64_x86_64_is_target_compatible): New.
(elf_backend_is_target_compatible): Define.
* elflink.c (elf_link_add_object_symbols): Use
bed->is_target_compatible to check if output hash table is
compatible with input.
* elfxx-target.h (elf_backend_is_target_compatible): Add default
definition.
(elfNN_bed): Add elf_backend_is_target_compatible.
--- bfd/elf-bfd.h.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elf-bfd.h 2007-04-24 15:25:01.000000000 -0700
@@ -1053,6 +1053,9 @@ struct elf_backend_data
/* Return TRUE if type is a function symbol type. */
bfd_boolean (*is_function_type) (unsigned int type);
+ /* Return TRUE if target is compatible with bfd. */
+ bfd_boolean (*is_target_compatible) (bfd *bfd, const bfd_target *target);
+
/* Used to handle bad SHF_LINK_ORDER input. */
bfd_error_handler_type link_order_error_handler;
@@ -1943,6 +1946,9 @@ extern bfd_boolean _bfd_elf_map_sections
extern bfd_boolean _bfd_elf_is_function_type (unsigned int);
+extern bfd_boolean _bfd_elf_is_target_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 15:31:26.000000000 -0700
@@ -9371,3 +9371,11 @@ _bfd_elf_is_function_type (unsigned int
{
return (type == STT_FUNC);
}
+
+/* Return TRUE if TARGET is compatible with ABFD. */
+
+bfd_boolean
+_bfd_elf_is_target_compatible (bfd *abfd, const bfd_target *target)
+{
+ return abfd->xvec == target;
+}
--- bfd/elf32-i386.c.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elf32-i386.c 2007-04-24 15:46:39.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_is_target_compatible (bfd *abfd, const bfd_target *target)
+{
+ extern const bfd_target bfd_elf32_i386_vec;
+ extern const bfd_target bfd_elf32_i386_freebsd_vec;
+
+ return (target == abfd->xvec
+ || target == &bfd_elf32_i386_vec
+ || target == &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_is_target_compatible elf_i386_is_target_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_is_target_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 15:46:02.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_is_target_compatible (bfd *abfd, const bfd_target *target)
+{
+ extern const bfd_target bfd_elf64_x86_64_vec;
+ extern const bfd_target bfd_elf64_x86_64_freebsd_vec;
+
+ return (target == abfd->xvec
+ || target == &bfd_elf64_x86_64_vec
+ || target == &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_is_target_compatible \
+ elf64_x86_64_is_target_compatible
#include "elf64-target.h"
--- bfd/elflink.c.mixed 2007-04-24 13:45:03.000000000 -0700
+++ bfd/elflink.c 2007-04-24 15:28:24.000000000 -0700
@@ -3270,7 +3270,7 @@ elf_link_add_object_symbols (bfd *abfd,
the format of the output file. */
if (info->relocatable
|| !is_elf_hash_table (htab)
- || htab->root.creator != abfd->xvec)
+ || !bed->is_target_compatible (abfd, htab->root.creator))
{
if (info->relocatable)
bfd_set_error (bfd_error_invalid_operation);
@@ -3367,7 +3367,7 @@ elf_link_add_object_symbols (bfd *abfd,
format as the output, we can't make a shared library. */
if (info->shared
&& is_elf_hash_table (htab)
- && htab->root.creator == abfd->xvec
+ && bed->is_target_compatible (abfd, htab->root.creator)
&& !htab->dynamic_sections_created)
{
if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
@@ -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->is_target_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 15:24:33.000000000 -0700
@@ -591,6 +591,10 @@
#define elf_backend_is_function_type _bfd_elf_is_function_type
#endif
+#ifndef elf_backend_is_target_compatible
+#define elf_backend_is_target_compatible _bfd_elf_is_target_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_is_target_compatible,
elf_backend_link_order_error_handler,
elf_backend_relplt_name,
ELF_MACHINE_ALT1,