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
On Wed, Oct 17, 2007 at 10:15:06AM +0930, Alan Modra wrote:
> On Tue, Oct 16, 2007 at 04:29:45PM -0700, H.J. Lu wrote:
> > On Wed, Oct 17, 2007 at 08:51:11AM +0930, Alan Modra wrote:
> > > On Tue, Oct 16, 2007 at 10:55:54AM -0700, H.J. Lu wrote:
> > > > @@ -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);
> > > >
> > > > + /* Used by alpha, sparc, i386 and x86-64 linkers to link again object
> > > > + files with different EI_OSABI. PR 4424. */
> > > > + struct elf_backend_data *relocs_compatible;
> > > > +
> > >
> > > This is only slightly better than a flag. Please make this a pointer
> > > to the predicate function. If it's a function, a backend can make
> > > arbitrary decisions about object file compatibility.
> > >
> >
> > I will add a pointer to the predicate function. But this field is
> > still needed to compare 2 backends.
>
> No it isn't. You can have a generic ELF function that only allows
> matching targets, and another function that looks similar to your
> bfd_elf_relocs_compatible but tests for matching arch and matching
> relocs_compatible function pointer.
>
Different backends can use the same function to check compatible
relocations. But they may not be compatible. Overloading the
meaning of the relocs_compatible function pointer is hard to read
and confusing. Why do we want to save a few bytes for it?
Here is the updated patch. bfd_is_relocs_compatible isn't required.
We can use _bfd_elf_is_relocs_compatible for all.
H.J.
----
2007-10-16 H.J. Lu <hongjiu.lu@intel.com>
PR ld/4424
* bfd.c (bfd_is_relocs_compatible): New.
* bfd-in2.h: Regenerated.
* config.bfd (targ_selvecs): Add bfd_elf64_alpha_vec for
alpha/FreeBSD. Add bfd_elf64_sparc_vec for sparc64/FreeBSD.
Add bfd_elf64_sparc_vec, bfd_elf32_i386_vec and
bfd_efi_app_ia32_vec for i386/FreeBSD.
(targ64_selvecs): Set for i386/FreeBSD.
* elf-bfd.h (elf_backend_data): Add is_relocs_compatible and
relocs_compatible.
(_bfd_elf_is_relocs_compatible): New.
* elf.c (_bfd_elf_is_relocs_compatible): New.
* elf32-i386.c (elf32_bed): Defined.
(elf_backend_relocs_compatible): Defined. Undefine for vxworks.
(elf_backend_is_relocs_compatible): Likewise.
* elf64-alpha.c (elf64_bed): Defined.
(elf_backend_relocs_compatible): Likewise.
(elf_backend_is_relocs_compatible): Likewise.
* elf64-sparc.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c (elf_link_add_object_symbols): Call
is_relocs_compatible to check if relocations in input
relocatable file can be processed.
* elfxx-target.h (elf_backend_is_relocs_compatible): New.
Default to bfd_is_relocs_compatible.
(elf_backend_relocs_compatible): New. Default to &elfNN_bed
(elfNN_bed): Add elf_backend_is_relocs_compatible and
elf_backend_relocs_compatible.
--- bfd/bfd-in2.h.mixed 2007-10-01 15:12:56.000000000 -0700
+++ bfd/bfd-in2.h 2007-10-16 18:08:47.000000000 -0700
@@ -4958,6 +4958,9 @@ void bfd_emul_set_commonpagesize (const
char *bfd_demangle (bfd *, const char *, int);
+bfd_boolean bfd_is_relocs_compatible
+ (const struct bfd_target *, const struct bfd_target *);
+
/* Extracted from archive.c. */
symindex bfd_get_next_mapent
(bfd *abfd, symindex previous, carsym **sym);
--- bfd/bfd.c.mixed 2007-09-15 13:50:58.000000000 -0700
+++ bfd/bfd.c 2007-10-16 18:09:04.000000000 -0700
@@ -1809,3 +1809,23 @@ bfd_demangle (bfd *abfd, const char *nam
return res;
}
+
+/*
+FUNCTION
+ bfd_is_relocs_compatible
+
+SYNOPSIS
+ bfd_boolean bfd_is_relocs_compatible
+ (const struct bfd_target *, const struct bfd_target *);
+
+DESCRIPTION
+ Return TRUE if relocations for INPUT are compatible with OUTPUT.
+*/
+
+
+bfd_boolean
+bfd_is_relocs_compatible (const struct bfd_target *input,
+ const struct bfd_target *output)
+{
+ return input == output;
+}
--- bfd/config.bfd.mixed 2007-09-08 18:23:19.000000000 -0700
+++ bfd/config.bfd 2007-10-16 17:34:47.000000000 -0700
@@ -140,7 +140,7 @@ case "${targ}" in
#ifdef BFD64
alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu)
targ_defvec=bfd_elf64_alpha_freebsd_vec
- targ_selvecs=ecoffalpha_little_vec
+ targ_selvecs="bfd_elf64_alpha_vec ecoffalpha_little_vec"
want64=true
# FreeBSD <= 4.0 supports only the old nonstandard way of ABI labelling.
case "${targ}" in
@@ -188,7 +188,7 @@ case "${targ}" in
;;
sparc64-*-freebsd* | sparc64-*-kfreebsd*-gnu)
targ_defvec=bfd_elf64_sparc_freebsd_vec
- targ_selvecs="bfd_elf32_sparc_vec sunos_big_vec"
+ targ_selvecs="bfd_elf64_sparc_vec bfd_elf32_sparc_vec sunos_big_vec"
;;
sparc64-*-netbsd* | sparc64-*-openbsd*)
targ_defvec=bfd_elf64_sparc_vec
@@ -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="bfd_elf32_i386_vec bfd_efi_app_ia32_vec i386coff_vec"
+ targ64_selvecs="bfd_elf64_x86_64_freebsd_vec bfd_elf64_x86_64_vec bfd_efi_app_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-16 17:34:47.000000000 -0700
+++ bfd/elf-bfd.h 2007-10-16 18:06:08.000000000 -0700
@@ -1053,6 +1053,14 @@ struct elf_backend_data
/* Return TRUE if type is a function symbol type. */
bfd_boolean (*is_function_type) (unsigned int type);
+ /* Return TRUE if relocations of 2 targets are compatible. */
+ bfd_boolean (*is_relocs_compatible) (const bfd_target *,
+ const bfd_target *);
+
+ /* The compatible ELF backend. Used by alpha, sparc, i386 and x86-64
+ files with different EI_OSABI. PR 4424. */
+ struct elf_backend_data *relocs_compatible;
+
/* Used to handle bad SHF_LINK_ORDER input. */
bfd_error_handler_type link_order_error_handler;
@@ -2008,6 +2016,9 @@ extern bfd_boolean _bfd_elf_map_sections
extern bfd_boolean _bfd_elf_is_function_type (unsigned int);
+extern bfd_boolean _bfd_elf_is_relocs_compatible
+ (const bfd_target *, 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-10-16 17:34:47.000000000 -0700
+++ bfd/elf.c 2007-10-16 18:02:49.000000000 -0700
@@ -8809,3 +8809,24 @@ _bfd_elf_is_function_type (unsigned int
{
return (type == STT_FUNC);
}
+
+/* Return TRUE if relocations for INPUT are compatible with OUTPUT. */
+
+bfd_boolean
+_bfd_elf_is_relocs_compatible (const bfd_target *input,
+ const bfd_target *output)
+{
+ const struct elf_backend_data *obed, *ibed;
+
+ if (input == output)
+ return TRUE;
+
+ if (input->flavour != bfd_target_elf_flavour
+ || output->flavour != bfd_target_elf_flavour)
+ return FALSE;
+
+ ibed = xvec_get_elf_backend_data (input);
+ obed = xvec_get_elf_backend_data (output);
+
+ return ibed->relocs_compatible == obed->relocs_compatible;
+}
--- bfd/elf32-i386.c.mixed 2007-10-16 17:34:47.000000000 -0700
+++ bfd/elf32-i386.c 2007-10-16 18:17:40.000000000 -0700
@@ -4059,6 +4059,10 @@ elf_i386_hash_symbol (struct elf_link_ha
#define elf_backend_merge_symbol \
_bfd_elf_sharable_merge_symbol
+#define elf32_bed elf32_i386_bed
+#define elf_backend_relocs_compatible &elf32_i386_bed
+#define elf_backend_is_relocs_compatible _bfd_elf_is_relocs_compatible
+
#include "elf32-target.h"
/* FreeBSD support. */
@@ -4124,6 +4128,8 @@ elf_i386_vxworks_link_hash_table_create
return ret;
}
+#undef elf_backend_relocs_compatible
+#undef elf_backend_is_relocs_compatible
#undef elf_backend_post_process_headers
#undef bfd_elf32_bfd_link_hash_table_create
--- bfd/elf64-alpha.c.mixed 2007-10-16 17:34:47.000000000 -0700
+++ bfd/elf64-alpha.c 2007-10-16 18:17:57.000000000 -0700
@@ -5369,6 +5369,10 @@ static const struct elf_size_info alpha_
#define elf_backend_want_plt_sym 1
#define elf_backend_got_header_size 0
+#define elf64_bed elf64_alpha_bed
+#define elf_backend_relocs_compatible &elf64_alpha_bed
+#define elf_backend_is_relocs_compatible _bfd_elf_is_relocs_compatible
+
#include "elf64-target.h"
/* FreeBSD support. */
--- bfd/elf64-sparc.c.mixed 2007-07-24 15:03:49.000000000 -0700
+++ bfd/elf64-sparc.c 2007-10-16 18:18:05.000000000 -0700
@@ -907,6 +907,10 @@ const struct elf_size_info elf64_sparc_s
/* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
#define elf_backend_plt_alignment 8
+#define elf64_bed elf64_sparc_bed
+#define elf_backend_relocs_compatible &elf64_sparc_bed
+#define elf_backend_is_relocs_compatible _bfd_elf_is_relocs_compatible
+
#include "elf64-target.h"
/* FreeBSD support */
--- bfd/elf64-x86-64.c.mixed 2007-10-16 17:34:47.000000000 -0700
+++ bfd/elf64-x86-64.c 2007-10-16 18:16:50.000000000 -0700
@@ -3915,6 +3915,10 @@ static const struct bfd_elf_special_sect
#define elf_backend_hash_symbol \
elf64_x86_64_hash_symbol
+#define elf64_bed elf64_x86_64_bed
+#define elf_backend_relocs_compatible &elf64_x86_64_bed
+#define elf_backend_is_relocs_compatible _bfd_elf_is_relocs_compatible
+
#include "elf64-target.h"
/* FreeBSD support. */
--- bfd/elflink.c.mixed 2007-10-16 17:34:47.000000000 -0700
+++ bfd/elflink.c 2007-10-16 17:59:41.000000000 -0700
@@ -4700,8 +4700,8 @@ 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->check_relocs != NULL)
+ && bed->check_relocs != NULL
+ && bed->is_relocs_compatible (abfd->xvec, htab->root.creator))
{
asection *o;
--- bfd/elfxx-target.h.mixed 2007-09-12 11:46:41.000000000 -0700
+++ bfd/elfxx-target.h 2007-10-16 18:09:24.000000000 -0700
@@ -606,6 +606,14 @@
#define elf_backend_is_function_type _bfd_elf_is_function_type
#endif
+#ifndef elf_backend_is_relocs_compatible
+#define elf_backend_is_relocs_compatible bfd_is_relocs_compatible
+#endif
+
+#ifndef elf_backend_relocs_compatible
+#define elf_backend_relocs_compatible &elfNN_bed
+#endif
+
extern const struct elf_size_info _bfd_elfNN_size_info;
static struct elf_backend_data elfNN_bed =
@@ -690,6 +698,8 @@ static struct elf_backend_data elfNN_bed
elf_backend_merge_symbol,
elf_backend_hash_symbol,
elf_backend_is_function_type,
+ elf_backend_is_relocs_compatible,
+ elf_backend_relocs_compatible,
elf_backend_link_order_error_handler,
elf_backend_relplt_name,
ELF_MACHINE_ALT1,