[RFC] handling of forward references in expressions

Jan Beulich jbeulich@novell.com
Tue Aug 1 09:11:00 GMT 2006


I ran into a problem with code that I was able to simplify to

	.text
T0:

	.data
D1:
	.long T0 + (D2 - D1)
	.long X0 + (D2 - D1)
D2:
	.long T0 + (D2 - D1)

Here, the first of the three expressions triggers "operation combines
symbols in different segments", but the second and third don't. This
clearly is wrong - either all or none of them should work. The problem
is that expr() treats the result of (D2 - D1), when D2 isn't defined
yet, as living in the section of D1 rather than in expr_section (and
similarly for operations other than subtraction). I was about to submit
the following patch, when I found that a few targets can't deal with
expressions in expr_section. My question hence is - can someone see
another solution to the original problem, or do I need to go through all
affected targets and find where they make those incorrect assumptions?

Thanks, Jan

--- 2006-07-31/gas/expr.c	2006-07-31 15:54:13.000000000 +0200
+++ 2006-07-31/gas/expr.c	2006-07-31 16:17:55.000000000 +0200
@@ -1839,7 +1839,11 @@ expr (int rankarg,		/* Larger # is
highe
 		  retval = absolute_section;
 		  rightseg = absolute_section;
 		}
+	      else
+		retval = expr_section;
 	    }
+	  else
+	    retval = expr_section;
 	}
       else
 	{
@@ -1849,13 +1853,16 @@ expr (int rankarg,		/* Larger # is
highe
 	  resultP->X_op = op_left;
 	  resultP->X_add_number = 0;
 	  resultP->X_unsigned = 1;
+	  retval = expr_section;
 	}
 
       if (retval != rightseg)
 	{
 	  if (! SEG_NORMAL (retval))
 	    {
-	      if (retval != undefined_section || SEG_NORMAL (rightseg))
+	      if (retval == expr_section)
+		;
+	      else if (retval != undefined_section || SEG_NORMAL
(rightseg))
 		retval = rightseg;
 	    }
 	  else if (SEG_NORMAL (rightseg)



More information about the Binutils mailing list