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 Tue, Oct 16, 2007 at 10:48:47AM +0930, Alan Modra wrote:
> On Mon, Oct 15, 2007 at 06:15:08PM -0700, H.J. Lu wrote:
> > On Tue, Oct 16, 2007 at 09:40:49AM +0930, Alan Modra wrote:
> > > On Mon, Oct 15, 2007 at 10:12:40AM -0700, H.J. Lu wrote:
> > > > + 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))
> > >
> > > Instead of adding always_check_relocs_in_object_file, I'd suggest
> > > adding a predicate function, dynamic_relocs_compatible. The default
> > > ELF version would be:
> > >
> > > _bfd_elf_dynamic_relocs_compatible (const bfd_target *otarg,
> > > const bfd_target *itarg)
> > > {
> > > return otarg == itarg;
> > > }
> > >
> > > The x86 version could check that ibed->dynamic_relocs_compatible
> > > == obed->dynamic_relocs_compatible.
> > >
> >
> > It has nothing to do with dynamic relocations.
>
> Well, it does in the sense that check_relocs is called to determine
> the size of got, plt and other dynamic sections.
>
> > This check only
> > applies to relocations in relocatable object files. How about
> >
> > _bfd_elf_relocs_compatible
> > relocs_compatible
>
> Fine.
>
Here is a path. I only added relocs_compatible to elf_backend_data.
The new function, bfd_elf_relocs_compatible, will check it.
H.J.
---
2007-10-16 H.J. Lu <hongjiu.lu@intel.com>
PR ld/4424
* 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 relocs_compatible.
(bfd_elf_relocs_compatible): New.
* elf.c (bfd_elf_relocs_compatible): New.
* elf32-i386.c (elf32_bed): Defined.
(elf_backend_relocs_compatible): Defined. Undefine for vxworks.
* elf64-alpha.c (elf64_bed): Defined.
(elf_backend_relocs_compatible): Likewise.
* elf64-sparc.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c (elf_link_add_object_symbols): Call
bfd_elf_relocs_compatible to see if relocations in input
relocatable file can be processed.
* elfxx-target.h (elf_backend_relocs_compatible): New. Default
to &elfNN_bed
(elfNN_bed): Add elf_backend_relocs_compatible.
--- bfd/config.bfd.mixed 2007-09-08 18:23:19.000000000 -0700
+++ bfd/config.bfd 2007-10-16 10:47:11.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 09:05:32.000000000 -0700
+++ bfd/elf-bfd.h 2007-10-16 10:23:01.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);
+ /* 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;
+
/* Used to handle bad SHF_LINK_ORDER input. */
bfd_error_handler_type link_order_error_handler;
@@ -2000,6 +2004,9 @@ extern bfd_boolean bfd_elf_gc_common_fin
extern bfd_boolean bfd_elf_reloc_symbol_deleted_p
(bfd_vma, void *);
+extern bfd_boolean bfd_elf_relocs_compatible
+ (const bfd_target *, const bfd_target *);
+
extern struct elf_segment_map * _bfd_elf_make_dynamic_segment
(bfd *, asection *);
--- bfd/elf.c.mixed 2007-10-16 09:05:32.000000000 -0700
+++ bfd/elf.c 2007-10-16 10:29:39.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_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 09:05:32.000000000 -0700
+++ bfd/elf32-i386.c 2007-10-16 10:33:42.000000000 -0700
@@ -4059,6 +4059,9 @@ 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
+
#include "elf32-target.h"
/* FreeBSD support. */
@@ -4124,6 +4127,7 @@ elf_i386_vxworks_link_hash_table_create
return ret;
}
+#undef elf_backend_relocs_compatible
#undef elf_backend_post_process_headers
#undef bfd_elf32_bfd_link_hash_table_create
--- bfd/elf64-alpha.c.mixed 2007-10-16 09:05:32.000000000 -0700
+++ bfd/elf64-alpha.c 2007-10-16 10:34:54.000000000 -0700
@@ -5369,6 +5369,9 @@ 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
+
#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 10:34:43.000000000 -0700
@@ -907,6 +907,9 @@ 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
+
#include "elf64-target.h"
/* FreeBSD support */
--- bfd/elf64-x86-64.c.mixed 2007-10-16 09:05:32.000000000 -0700
+++ bfd/elf64-x86-64.c 2007-10-16 10:24:18.000000000 -0700
@@ -3915,6 +3915,9 @@ 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
+
#include "elf64-target.h"
/* FreeBSD support. */
--- bfd/elflink.c.mixed 2007-10-16 09:05:33.000000000 -0700
+++ bfd/elflink.c 2007-10-16 10:21:40.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
+ && bfd_elf_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 10:13:28.000000000 -0700
@@ -606,6 +606,10 @@
#define elf_backend_is_function_type _bfd_elf_is_function_type
#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 +694,7 @@ static struct elf_backend_data elfNN_bed
elf_backend_merge_symbol,
elf_backend_hash_symbol,
elf_backend_is_function_type,
+ elf_backend_relocs_compatible,
elf_backend_link_order_error_handler,
elf_backend_relplt_name,
ELF_MACHINE_ALT1,