> From: Marek Michalkiewicz <[EMAIL PROTECTED]>
>> On Sun, Mar 20, 2005 at 04:29:01PM -0800, Richard Henderson wrote:
>> The easiest way is to do this in the linker instead of the compiler.
>> See the xstormy16 port and how it handles R_XSTORMY16_FPTR16. This
>> has the distinct advantage that you do not commit to the creation of
>> an indirect jump until you discover that the target label is outside
>> the low 64k.
>
> Looks perfect to me. So we are not the first architecture needing
> such tricks... AVR would need 3 new relocs, used like this:
>
> .word pm16(label)
>
> ldi r30,pm16_lo8(label)
> ldi r31,pm16_hi8(label)
>
> and the linker can do the rest of the magic (add jumps in a section
> below 64K words if the label is above).
>
> Cc: to Denis, as I may need help actually implementing these changes
> (you know binutils internals much better than I do).
- yup, and nicer than trying to play games with alignment, etc.,
And just to double check, using the earlier example:
> int foo(int dest)
> {
> __label__ l1, l2, l3;
> void *lb[] = { &&l1, &&l2, &&l3 };
> int x = 0;
>
> goto *lb[dest];
>
> l1:
> x += 1;
> l2:
> x += 1;
> l3:
> x += 1;
> return x;
> }
It would seem that the only time the pm16(label) address would ever
be used, would as an initializing constant pointer value being assigned
to a _label_/function pointer variable; as a CALL/JUMP LABEL instruction
would be used to call/jump-to the true entry point directly otherwise.
(is that correct?)