3.0.1 Freeze

Mark Mitchell mark@codesourcery.com
Tue Aug 7 12:53:00 GMT 2001


> #define PTRRELOC(x)     ((typeof(x))((unsigned long)(x) + offset))
> #define RELOC(x)        (*PTRRELOC(&(x)))
> offset = get_reloc_offfset();
> strcpy(dest, RELOC("test"));
>
> I  don't see anything illegal/undefined/unportable about that code, just
> plain C pointer arithmetic to implement a poor mans relocation in  early
> boot  code.

Ah.  So, ignoring the non-standard `typeof', you have cast a pointer to
an integer, added another integer, and cast back to a pointer.  That
is (I checked) implementation-defined behavior, but the sensible
definition is that it do what you think.

So, I am now convinced that this optimization is too aggressive.  I
will simply remove it.

Thank you,

-- 
Mark Mitchell                mark@codesourcery.com
CodeSourcery, LLC            http://www.codesourcery.com



More information about the Gcc mailing list