Not linking 32-bit and 64-bit objects
Alan Modra
amodra@bigpond.net.au
Tue Mar 12 18:55:00 GMT 2002
This should stop the linker trying to do silly things with incompatible
relocs.
bfd/ChangeLog
* elflink.h (elf_bfd_final_link): Only call elf_link_input_bfd
when word size of input matches output word size.
ld/ChangeLog
* ldlang.c (lang_check): Do relocatable link checks first, so that
warn_mismatch can't override. Check compatible and word size too.
--
Alan Modra
IBM OzLabs - Linux Technology Centre
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.145
diff -u -p -r1.145 elflink.h
--- elflink.h 2002/03/05 05:18:41 1.145
+++ elflink.h 2002/03/13 02:33:29
@@ -5320,10 +5320,11 @@ elf_bfd_final_link (abfd, info)
for (p = o->link_order_head; p != NULL; p = p->next)
{
if (p->type == bfd_indirect_link_order
- && (bfd_get_flavour (p->u.indirect.section->owner)
- == bfd_target_elf_flavour))
+ && (bfd_get_flavour ((sub = p->u.indirect.section->owner))
+ == bfd_target_elf_flavour)
+ && (sub->arch_info->bits_per_word
+ == abfd->arch_info->bits_per_word))
{
- 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.75
diff -u -p -r1.75 ldlang.c
--- ldlang.c 2002/02/15 02:11:05 1.75
+++ ldlang.c 2002/03/13 02:50:43
@@ -3569,8 +3569,27 @@ lang_check ()
file = file->input_statement.next)
{
input_bfd = file->input_statement.the_bfd;
- compatible = bfd_arch_get_compatible (input_bfd,
- output_bfd);
+ compatible = bfd_arch_get_compatible (input_bfd, output_bfd);
+
+ /* In general it is not possible to perform a relocatable
+ link between differing object formats when the input
+ file has relocations, because the relocations in the
+ 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
+ && (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_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"),
+ bfd_get_target (input_bfd), input_bfd,
+ bfd_get_target (output_bfd), output_bfd);
+ /* einfo with %F exits. */
+ }
+
if (compatible == NULL)
{
if (command_line.warn_mismatch)
@@ -3578,18 +3597,6 @@ lang_check ()
bfd_printable_name (input_bfd), input_bfd,
bfd_printable_name (output_bfd));
}
- else if (link_info.relocateable
- /* In general it is not possible to perform a relocatable
- link between differing object formats when the input
- file has relocations, because the relocations in the
- 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). */
- && 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"),
- bfd_get_target (input_bfd), input_bfd,
- bfd_get_target (output_bfd), output_bfd);
else if (bfd_count_sections (input_bfd))
{
/* If the input bfd has no contents, it shouldn't set the
More information about the Binutils
mailing list