Re: [PATCH] C undefined behavior fix

law
2002-01-03T06:31:44Z

> Now the claim is that RELOC is bad because it adds an offset to a
> pointer, and the offset is usually around 0xc0000000, and thus we are
> "violating" the C standard. Thus we are being told that someday this
> will break and cause a lot of grief. My contention is that this will
> only break if a pointer becomes something other than a simple address
> and pointer arithmetic becomes something other than simple 2's
> complement addition, subtraction, etc. If that happens then C will
> have become useless for implementing a kernel, IMHO.
Well, pointer arithmetic on the HPPA isn't simple 2's complement due to
the way implicit space register selection works.

For example in an unscaled indexed addressing mode like

ldbx srcreg1(srcreg2), dstreg

Is not equivalent to

ldbx srcreg2(srcreg1), dstreg

ie x + y != y + x for computing an address in a memory operation.

For the same reason computing an address outside of an object into a
register, then using a displacement in a memory operation to generate an
address that is within the bounds of the object may not work. ie, you
can't do something like this and expect it to work:

int a[10];
int *z = a - 10;

foo()
{
return z[10];
}

And before anyone says the PA is unbelievably strange and nobody else would
make the same mistakes -- the mn10300 (for which a linux port does exist)
has the same failings.

jeff