This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Not linking 32-bit and 64-bit objects



If I try to link a 32-bit i386 object as 64-bit x86-64 object, it
should fail but I'd like to see a better error message.

Currently I get:
gee:~/tmp:[1]$ /opt/x86-64/bin/x86_64-unknown-linux-gcc k.o 
collect2: ld terminated with signal 11 [Segmentation fault], core dumped
/opt/x86-64/lib/gcc-lib/x86_64-unknown-linux/3.1/../../../../x86_64-unknown-linux/bin/ld: BFD 2.12.90 20020312 assertion fail /cvs/binutils-ln/bfd/elflink.h:2649

I made the appended (not cleaned up) change and now I get:

gee:~/tmp:[1]$ /opt/x86-64/bin/x86_64-unknown-linux-gcc k.o 
collect2: ld terminated with signal 11 [Segmentation fault], core dumped
/opt/x86-64/lib/gcc-lib/x86_64-unknown-linux/3.1/../../../../x86_64-unknown-linux/bin/ld: k.o: compiled for a 32 bit system and target is 64 bit
Bad value: failed to merge target specific data of file k.o
/opt/x86-64/lib/gcc-lib/x86_64-unknown-linux/3.1/../../../../x86_64-unknown-linux/bin/ld: BFD 2.12.90 20020312 assertion fail /cvs/binutils-ln/bfd/elflink.h:2649

This is better but I'm not happy, the linker should not abort but exit
cleanly.

So, my questions are:
- is this the right way to go (using merge_private_bfd_data)?
- how can I exit cleanly in this case?

Andreas

2002-03-12  Andreas Jaeger  <aj@suse.de>

	* elf64-x86-64.c (elf64_x86_64_merge_private_bfd_data): New.
	(bfd_elf64_bfd_merge_private_bfd_data): New.


============================================================
Index: bfd/elf64-x86-64.c
--- bfd/elf64-x86-64.c	2002/02/22 10:03:03	1.37
+++ bfd/elf64-x86-64.c	2002/03/12 10:59:09
@@ -2060,6 +2060,37 @@ elf64_x86_64_finish_dynamic_symbol (outp
   return true;
 }
 
+static boolean
+elf64_x86_64_merge_private_bfd_data (ibfd, obfd)
+     bfd *ibfd;
+     bfd *obfd;
+{
+  boolean error = false;
+
+  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+    return true;
+
+  if (bfd_get_mach (ibfd) != bfd_mach_x86_64
+      && bfd_get_mach (ibfd) != bfd_mach_x86_64_intel_syntax)
+    {
+      error = true;
+      (*_bfd_error_handler)
+	(_("%s: compiled for a 32 bit system and target is 64 bit"),
+	 bfd_archive_filename (ibfd));
+    }
+
+  if (error)
+    {
+      bfd_set_error (bfd_error_bad_value);
+      return false;
+    }
+
+  return true;
+}
+
+
+  
 /* Used to decide how to sort relocs in an optimal manner for the
    dynamic linker, before writing them out.  */
 
@@ -2231,6 +2262,7 @@ elf64_x86_64_finish_dynamic_sections (ou
 #define bfd_elf64_bfd_link_hash_table_create \
   elf64_x86_64_link_hash_table_create
 #define bfd_elf64_bfd_reloc_type_lookup	    elf64_x86_64_reloc_type_lookup
+#define bfd_elf64_bfd_merge_private_bfd_data elf64_x86_64_merge_private_bfd_data
 
 #define elf_backend_adjust_dynamic_symbol   elf64_x86_64_adjust_dynamic_symbol
 #define elf_backend_check_relocs	    elf64_x86_64_check_relocs

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]