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]

more on ARM ELF flag merging


I just discovered that ld was rejecting an attempt to interlink -msoft-float 
and -mhard-float objects without explaining why.  The patch below fixes this. 
and also rearranges things slightly so that the linker will produce messages 
for all the mismatches that exist, rather than just the first one.

There's still the potential for this code to behave in unexpected ways, 
though...

This is OK:

$ arm-linux-as -o t1.o </dev/null
$ arm-linux-as -o t2.o -k </dev/null
$ arm-linux-ld -o t.o t1.o t2.o
arm-linux-ld: warning: cannot find entry symbol _start; defaulting to 02000074
$

But this fails:

$ arm-linux-ld -o t.o t1.o t2.o t1.o
arm-linux-ld: Error: t1.o is compiled as position dependent code, whereas t.o is not
File format not recognized: failed to merge target specific data of file t1.o
arm-linux-ld: warning: cannot find entry symbol _start; defaulting to 02000074
$

And so does this:

$ arm-linux-as -o t1.o -mno-fpu </dev/null
$ arm-linux-as -o t2.o -k -mno-fpu </dev/null
$ arm-linux-ld -o t.o t1.o t2.o
arm-linux-ld: Error: t2.o is compiled as position independent code, whereas t.o is not
File format not recognized: failed to merge target specific data of file t2.o
arm-linux-ld: warning: cannot find entry symbol _start; defaulting to 02000074
$

Linking PIC code into a non-PIC executable is something that happens all the 
time on Linux (libgcc.a is PIC, for example) so we shouldn't generate an error 
or even a warning for that case.  I think my preference would be to just 
silently clear the PIC flag on the output BFD if any non-PIC BFDs are merged 
with it; at the moment it inherits from the first input BFD that has any 
non-default flags.  Nick, what do you think?

p.

2000-10-22  Philip Blundell  <philb@gnu.org>

	* elf32-arm.h (elf32_arm_merge_private_bfd_data): Print an error
	message for EF_SOFT_FLOAT mismatches.  Display diagnostics for all
	mismatches, not just the first one.

Index: elf32-arm.h
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.h,v
retrieving revision 1.25.2.2
diff -u -p -u -r1.25.2.2 elf32-arm.h
--- elf32-arm.h	2000/10/22 15:19:56	1.25.2.2
+++ elf32-arm.h	2000/10/22 17:12:11
@@ -1973,6 +1973,7 @@ elf32_arm_merge_private_bfd_data (ibfd, 
 {
   flagword out_flags;
   flagword in_flags;
+  boolean flags_compatible = true;
 
   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -2024,48 +2025,61 @@ elf32_arm_merge_private_bfd_data (ibfd, 
       return true;
     }
 
-  /* Check flag compatibility.  */
-  if (in_flags == out_flags)
-    return true;
-
   /* Complain about various flag mismatches.  */
 
   if ((in_flags & EF_APCS_26) != (out_flags & EF_APCS_26))
-    _bfd_error_handler (_ ("\
+    {
+      _bfd_error_handler (_ ("\
 Error: %s compiled for APCS-%d, whereas %s is compiled for APCS-%d"),
 			bfd_get_filename (ibfd),
 			in_flags & EF_APCS_26 ? 26 : 32,
 			bfd_get_filename (obfd),
 			out_flags & EF_APCS_26 ? 26 : 32);
+      flags_compatible = false;
+    }
 
   if ((in_flags & EF_APCS_FLOAT) != (out_flags & EF_APCS_FLOAT))
-    _bfd_error_handler (_ ("\
+    {
+      _bfd_error_handler (_ ("\
 Error: %s passes floats in %s registers, whereas %s passes them in %s registers"),
 			bfd_get_filename (ibfd),
 		     in_flags & EF_APCS_FLOAT ? _ ("float") : _ ("integer"),
 			bfd_get_filename (obfd),
 		      out_flags & EF_APCS_26 ? _ ("float") : _ ("integer"));
+      flags_compatible = false;
+    }
 
   if ((in_flags & EF_PIC) != (out_flags & EF_PIC))
-    _bfd_error_handler (_ ("\
+    {
+      _bfd_error_handler (_ ("\
 Error: %s is compiled as position %s code, whereas %s is not"),
 			bfd_get_filename (ibfd),
 		    in_flags & EF_PIC ? _ ("independent") : _ ("dependent"),
 			bfd_get_filename (obfd));
+      flags_compatible = false;
+    }
 
-  /* Interworking mismatch is only a warning. */
-  if ((in_flags & EF_INTERWORK) != (out_flags & EF_INTERWORK))
+  if ((in_flags & EF_SOFT_FLOAT) != (out_flags & EF_SOFT_FLOAT))
     {
       _bfd_error_handler (_ ("\
+Error: %s uses %s floating point, whereas %s uses %s floating point"),
+			  bfd_get_filename (ibfd),
+			  in_flags & EF_SOFT_FLOAT ? _("soft") : _("hard"),
+			  bfd_get_filename (obfd),
+			  out_flags & EF_SOFT_FLOAT ? _("soft") : _("hard"));
+      flags_compatible = false;
+    }
+
+  /* Interworking mismatch is only a warning. */
+  if ((in_flags & EF_INTERWORK) != (out_flags & EF_INTERWORK))
+    _bfd_error_handler (_ ("\
 Warning: %s %s interworking, whereas %s %s"),
 			  bfd_get_filename (ibfd),
 	  in_flags & EF_INTERWORK ? _ ("supports") : _ ("does not support"),
 			  bfd_get_filename (obfd),
 		    out_flags & EF_INTERWORK ? _ ("does not") : _ ("does"));
-      return true;
-    }
 
-  return false;
+  return flags_compatible;
 }
 
 /* Display the flags field */



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