recent mips-elf linker "architecture ... incompatible" regressions
Alan Modra
amodra@bigpond.net.au
Thu Mar 14 02:36:00 GMT 2002
On Thu, Mar 14, 2002 at 12:27:59PM +1030, Alan Modra wrote:
> On Wed, Mar 13, 2002 at 07:24:16PM -0500, Daniel Jacobowitz wrote:
> > On Wed, Mar 13, 2002 at 03:59:42PM -0800, cgd@broadcom.com wrote:
> > > Recently -- not quite sure when, haven't tracked it down -- building
> > > on host sparc-solaris for --target=mips-elf started showing the
> > > following ld testsuite errors:
> >
> > Past day or two. Alan's patches, which were meant to prevent crashes
> > in linking 32-bit and 64-bit code together, presumably tightened the
> > compatibility checks. He said in his patch MIPS would be affected.
>
> Guilty as charged. mips is tricky. You have 64 bit code using ELF32,
> right? So the check I added to bfd_default_compatible is wrong for
> mips, and also the check in elf_bfd_final_link. We really want to test
> the reloc size, not the word size.
This fixes the new mips failures by introducing a new mips_compatible
function that mimics the old bfd_default_compatible, and corrects
the checks I added in elf_link_input_bfd and lang_check.
bfd/ChangeLog
* cpu-mips.c (mips_compatible): New. Don't check bits_per_word.
(N): Use the above.
* elflink.h (elf_bfd_final_link): Revert last change. Instead,
ensure reloc size matches before calling elf_link_input_bfd.
Add an assert to check reloc size when counting output relocs.
ld/ChangeLog
* ldlang.c (lang_check): Remove the word size check added in last
change. Treat emitrelocations case as for relocatable links.
--
Alan Modra
IBM OzLabs - Linux Technology Centre
Index: bfd/cpu-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/cpu-mips.c,v
retrieving revision 1.10
diff -u -p -r1.10 cpu-mips.c
--- cpu-mips.c 2001/08/31 21:24:28 1.10
+++ cpu-mips.c 2002/03/14 09:44:25
@@ -1,5 +1,5 @@
/* bfd back-end for mips support
- Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 2000
+ Copyright 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2002
Free Software Foundation, Inc.
Written by Steve Chamberlain of Cygnus Support.
@@ -23,6 +23,26 @@ Foundation, Inc., 59 Temple Place - Suit
#include "sysdep.h"
#include "libbfd.h"
+/* The default routine tests bits_per_word, which is wrong on mips as
+ mips word size doesn't correlate with reloc size. */
+
+const bfd_arch_info_type *
+mips_compatible (a, b)
+ const bfd_arch_info_type *a;
+ const bfd_arch_info_type *b;
+{
+ if (a->arch != b->arch)
+ return NULL;
+
+ if (a->mach > b->mach)
+ return a;
+
+ if (b->mach > a->mach)
+ return b;
+
+ return a;
+}
+
#define N(BITS_WORD, BITS_ADDR, NUMBER, PRINT, DEFAULT, NEXT) \
{ \
BITS_WORD, /* bits in a word */ \
@@ -34,7 +54,7 @@ Foundation, Inc., 59 Temple Place - Suit
PRINT, \
3, \
DEFAULT, \
- bfd_default_compatible, \
+ mips_compatible, \
bfd_default_scan, \
NEXT, \
}
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.149
diff -u -p -r1.149 elflink.h
--- elflink.h 2002/03/13 07:26:24 1.149
+++ elflink.h 2002/03/14 10:19:32
@@ -5086,10 +5086,20 @@ elf_bfd_final_link (abfd, info)
= elf_section_data (output_section);
unsigned int *rel_count;
unsigned int *rel_count2;
+ bfd_size_type entsize;
+ bfd_size_type entsize2;
- /* We must be careful to add the relocation froms the
+ /* We must be careful to add the relocations from the
input section to the right output count. */
- if (esdi->rel_hdr.sh_entsize == esdo->rel_hdr.sh_entsize)
+ entsize = esdi->rel_hdr.sh_entsize;
+ entsize2 = esdi->rel_hdr2 ? esdi->rel_hdr2->sh_entsize : 0;
+ BFD_ASSERT ((entsize == sizeof (Elf_External_Rel)
+ || entsize == sizeof (Elf_External_Rela))
+ && entsize2 != entsize
+ && (entsize2 == 0
+ || entsize2 == sizeof (Elf_External_Rel)
+ || entsize2 == sizeof (Elf_External_Rela)));
+ if (entsize == esdo->rel_hdr.sh_entsize)
{
rel_count = &esdo->rel_count;
rel_count2 = &esdo->rel_count2;
@@ -5319,12 +5329,21 @@ elf_bfd_final_link (abfd, info)
{
for (p = o->link_order_head; p != NULL; p = p->next)
{
+ Elf_Internal_Shdr *rhdr;
+
if (p->type == bfd_indirect_link_order
- && (bfd_get_flavour ((sub = p->u.indirect.section->owner))
+ && (bfd_get_flavour (p->u.indirect.section->owner)
== bfd_target_elf_flavour)
- && (sub->arch_info->bits_per_word
- == abfd->arch_info->bits_per_word))
+ && (((rhdr = &elf_section_data (p->u.indirect.section)->rel_hdr)
+ ->sh_entsize == 0)
+ || rhdr->sh_entsize == sizeof (Elf_External_Rel)
+ || rhdr->sh_entsize == sizeof (Elf_External_Rela))
+ && (((rhdr = elf_section_data (p->u.indirect.section)->rel_hdr2)
+ == NULL)
+ || rhdr->sh_entsize == sizeof (Elf_External_Rel)
+ || rhdr->sh_entsize == sizeof (Elf_External_Rela)))
{
+ sub = p->u.indirect.section->owner;
if (! sub->output_has_begun)
{
if (! elf_link_input_bfd (&finfo, sub))
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.76
diff -u -p -r1.76 ldlang.c
--- ldlang.c 2002/03/13 02:56:36 1.76
+++ ldlang.c 2002/03/14 09:44:39
@@ -3577,11 +3577,9 @@ lang_check ()
input format may not have equivalent representations in
the output format (and besides BFD does not translate
relocs for other link purposes than a final link). */
- if (link_info.relocateable
+ if ((link_info.relocateable || link_info.emitrelocations)
&& (compatible == NULL
- || bfd_get_flavour (input_bfd) != bfd_get_flavour (output_bfd)
- || (input_bfd->arch_info->bits_per_word
- != output_bfd->arch_info->bits_per_word))
+ || bfd_get_flavour (input_bfd) != bfd_get_flavour (output_bfd))
&& (bfd_get_file_flags (input_bfd) & HAS_RELOC) != 0)
{
einfo (_("%P%F: Relocatable linking with relocations from format %s (%B) to format %s (%B) is not supported\n"),
More information about the Binutils
mailing list