On Wed, Dec 19, 2001 at 12:08:12AM -0600, Ben Combee wrote:
>> Are you sure this applies to PRC tools.
>
> No... I've not analysed the output of PRC tools.
I spent some time in my PalmSource talk last year looking at the
assembly generated by prc-tools for various kinds of function calls and
function addresses (but only in C). I thought you were there, Ben?! :-)
The slides are theoretically still available somewhere at www.palmos.com
or www.palmsource.com, but all I found at the former was broken links
and the latter seems to have turned into an advertisement for the
upcoming conference and if the old material is still there at all it's
close to impossible to find it.
In short, with that famous current implementation of multiple code
resources in prc-tools:
extern int MyFunc ();
extern int MyFunc2 () __attribute__ ((section ("othersec")));
int (*func) () = MyFunc2; /* 1 */
void same_section_as_MyFunc_but_not_as_MyFunc2 () {
func = MyFunc; /* 2 */
func = MyFunc2; /* 3 */
}
Initialisation 1 is done at application startup by a compile-time
constant relocation (and it doesn't matter at all which section the
function you're assigning to func is in).
Assignment 2 is calculated as a compile-time constant offset from %pc.
Assignment 3, when the function whose address you're taking is in a
different section from the place where you're doing it, is calculated as
a compile-time constant offset from a section pointer, which you find at
a compile-time constant offset from the global pointer (usually %a5).
(Oh, and the section pointer lookup can be optimised away by CSE if a
function makes a lot of references to things in the same other section.)
(But all that happens behind the scenes. The average C programmer can
just write "func = MyFunc" and not worry about it. Well, unless they
want to take the address of a system API function...)
#3 is the only one that's different from CodeWarrior. Personally, I
think the double indirection is a lot less weird than CW's opcode
skipping :-), but that's pretty immaterial. I looked more closely at
the pros and cons of the two implementations in that talk last year.
John
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/