This is the mail archive of the binutils@sourceware.org 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]

Re: assertion failure with gas and broken syntax


Prevents register arithmetic in fixup_segment if md_register_arithmetic
disallows such.  Fixes the following testcase on x86

$ echo  'cmp (%ax)-1, %ax'|as
as: BFD (Linux/GNU Binutils) 2.18.50.0.9.20080822 assertion fail
../../bfd/elf.c:6492
as: BFD (Linux/GNU Binutils) 2.18.50.0.9.20080822 internal error, aborting
at ../../bfd/elfcode.h line 227 in bfd_elf64_swap_symbol_out

	* write.c (md_register_arithmetic): Define.
	(fixup_segment): Adjust TC_FORCE_RELOCATION_SUB_ABS invocation.
	Modify error message when registers involved.
	(TC_FORCE_RELOCATION_SUB_ABS): Heed md_register_arithmetic.
	* config/tc-sh.h (TC_FORCE_RELOCATION_SUB_ABS): Likewise.

Index: gas/write.c
===================================================================
RCS file: /cvs/src/src/gas/write.c,v
retrieving revision 1.119
diff -u -p -r1.119 write.c
--- gas/write.c	15 Sep 2008 13:53:17 -0000	1.119
+++ gas/write.c	19 Sep 2008 01:41:30 -0000
@@ -54,8 +54,13 @@
   (! SEG_NORMAL (SEG))
 #endif
 
+#ifndef md_register_arithmetic
+# define md_register_arithmetic 1
+#endif
+
 #ifndef TC_FORCE_RELOCATION_SUB_ABS
-#define TC_FORCE_RELOCATION_SUB_ABS(FIX)	0
+#define TC_FORCE_RELOCATION_SUB_ABS(FIX, SEG)	\
+  (!md_register_arithmetic && (SEG) == reg_section)
 #endif
 
 #ifndef TC_FORCE_RELOCATION_SUB_LOCAL
@@ -924,7 +929,7 @@ fixup_segment (fixS *fixP, segT this_seg
 #endif
 	    }
 	  else if (sub_symbol_segment == absolute_section
-		   && !TC_FORCE_RELOCATION_SUB_ABS (fixP))
+		   && !TC_FORCE_RELOCATION_SUB_ABS (fixP, add_symbol_segment))
 	    {
 	      add_number -= S_GET_VALUE (fixP->fx_subsy);
 	      fixP->fx_offset = add_number;
@@ -955,12 +960,18 @@ fixup_segment (fixS *fixP, segT this_seg
 	    }
 	  else if (!TC_VALIDATE_FIX_SUB (fixP))
 	    {
-	      as_bad_where (fixP->fx_file, fixP->fx_line,
-			    _("can't resolve `%s' {%s section} - `%s' {%s section}"),
-			    fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0",
-			    segment_name (add_symbol_segment),
-			    S_GET_NAME (fixP->fx_subsy),
-			    segment_name (sub_symbol_segment));
+	      if (!md_register_arithmetic
+		  && (add_symbol_segment == reg_section
+		      || sub_symbol_segment == reg_section))
+		as_bad_where (fixP->fx_file, fixP->fx_line,
+			      _("register value used as expression"));
+	      else
+		as_bad_where (fixP->fx_file, fixP->fx_line,
+			      _("can't resolve `%s' {%s section} - `%s' {%s section}"),
+			      fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0",
+			      segment_name (add_symbol_segment),
+			      S_GET_NAME (fixP->fx_subsy),
+			      segment_name (sub_symbol_segment));
 	    }
 	}
 
Index: gas/config/tc-sh.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-sh.h,v
retrieving revision 1.50
diff -u -p -r1.50 tc-sh.h
--- gas/config/tc-sh.h	6 Aug 2008 15:42:15 -0000	1.50
+++ gas/config/tc-sh.h	19 Sep 2008 01:41:30 -0000
@@ -211,8 +211,9 @@ extern bfd_boolean sh_fix_adjustable (st
 
 /* This keeps the subtracted symbol around, for use by PLT_PCREL
    relocs.  */
-#define TC_FORCE_RELOCATION_SUB_ABS(FIX)		\
-  ((FIX)->fx_r_type == BFD_RELOC_32_PLT_PCREL)
+#define TC_FORCE_RELOCATION_SUB_ABS(FIX, SEG)		\
+  ((FIX)->fx_r_type == BFD_RELOC_32_PLT_PCREL		\
+   || (!md_register_arithmetic && (SEG) == reg_section))
 
 /* Don't complain when we leave fx_subsy around.  */
 #undef TC_VALIDATE_FIX_SUB

-- 
Alan Modra
Australia Development Lab, IBM


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