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: Relative expressions and ASSERT


On Thu, Jan 20, 2011 at 05:18:11PM +0000, Maciej W. Rozycki wrote:
>  I've been looking through the thread (including the August part), trying 
> to understand what the origin of your changes has been.

I started looking at a bug, and decided the old ld expression
evaluation code was just so inconsistent that it needed cleaning up.

> 1. Plain symbol references, possibly with an offset yield an expression
>    relative to the symbol's section.  Examples:
> 
>    foo
>    foo + 4
>    foo - 2 - (3 * 5)
>    -7 + foo

New expression code does this, except for compatibility with old ld we
return absolute section values if the expression is outside of an
output section statement.

Also of course, expressions like min(x,y), max(x,y), align(x,4) with x
and y in the same section should return a section relative result.

> 2. Plain numbers and any operations made on them plus subtraction of two 
>    section-relative expressions (i.e. anything that falls into #1 above) 
>    yield a plain number.  Examples:
> 
>    0
>    3 + 7
>    foo - bar
>    bar - foo + 2
>    (bar + 2) - foo
>    (bar - 10) - (foo + (~4 ^ 12))

With either of my fixes the new code will do this too.  Old ld code
will sometimes return section relative or absolute values.

> 3. Anything else yields an absolute expression (I would see no problem if 
>    it failed altogether on an incremental link, though I understand we 
>    may not want to do this for compatibility reasons).  You can make it 
>    section-relative again by adding it to a section-relative expression.  
>    Examples:
> 
>    foo + bar
>    -foo + bar
>    2 * foo
>    foo & 1
>    foo ^ bar
>    etc., etc...
> 
> (note that #1 and #2 are how pointer arithmetics works in C too).  This 
> for example implies that:
> 
>    foo + foo + foo
> 
> and:
> 
>    foo + 2 * foo
> 
> are relative, but:
> 
>    3 * foo
> 
> is not.

Yes, these are the sort of oddities we get with *any* choice we make
regarding expressions involving two or more relative symbols.

We've also got the constraint of compatibility with old ld behaviour,
at least for the simple expressions likely to be used in many existing
linker scripts.  That makes your #3 a bit of a problem.  For instance

x = 2;
y = 3;
z = x * y;

ought to always result in z having a value of 6, assuming x, y, and z
are all outside any output section statement, or all in one
particular output section statement.  In the latter case, z should be
section relative.  What happens when z is set in a different output
section statement to x and y is open to change from the old ld, I'd
say.

Note that the new code makes the distinction between a plain number
and an absolute symbol, so the result section of "x * y" could either
be NULL (plain number) as I do in my second patch, or the same section
as x and y as in the first patch, and still satisfy this compatibility
requirement.  You could not make the result of "x * y" an absolute
value as that would cause z to be absolute.

-- 
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]