|
From: Nicholas N. <nj...@ca...> - 2004-10-18 15:11:19
|
On Mon, 18 Oct 2004, Adam Gundy wrote: >>> what's wrong with: >>> >>> init_sp = &argc; >> >> Is it actually certain that argc will be on the stack? Eg. for PPC, >> functions args usually get passed in registers... I'm not really sure, >> I'm copying Paul Mackerras' PPC port here. > > if it's not on the stack, then what is 'argv - 1' pointing to? > some random piece of data above it on the stack... > > I would guess that if argc is a register, and you ask for &argc, the > compiler will generate a temporary on the stack which you can mess with (but > it wouldn't be what you want.. it would be somewhere in the local variables) I should have been clearer. The value of argc will definitely be on the stack, because the ABI requires it. However, the argument argc to main() may be in a register (ie. there could be two copies of argc floating around, one on the stack, one in a register). In which case a temporary will be generated as you say, which is not what we want. Does that make sense? > could be wrong though... try writing a five line program on PPC and seeing > what assembler you get (I know that's not portable) I don't have access to a PPC at the moment, unfortunately... > you know that GCC has some builtins that return things like this? > > http://ou800doc.caldera.com/cgi-bin/info2html?(gcc.info)Return%2520Address&lang=en I don't see how either of those really help? Thanks for the info. N |