f



calling convention adopted by the gcc compiler for the C programs

Hi there,

I want to learn about the calling convention that is adopted by the gcc
compiler for C programs ? I need to learn about it immidiately for
finding out the parameters passed to registers when a function call is
made and print out the values of the parameters. Can anyone give me
some pointers or refer to some book that would be helpful ? I tried
searching at google but did not find any useful papers or reference.

Thank you,
Priyanka

0
7/14/2006 5:16:09 PM
comp.lang.c 30657 articles. 4 followers. spinoza1111 (3246) is leader. Post Follow

6 Replies
244 Views

Similar Articles

[PageSpeed] 53

priyanka wrote:
> Hi there,
> 
> I want to learn about the calling convention that is adopted by the gcc
> compiler for C programs ? I need to learn about it immidiately for
> finding out the parameters passed to registers when a function call is
> made and print out the values of the parameters. Can anyone give me
> some pointers or refer to some book that would be helpful ? I tried
> searching at google but did not find any useful papers or reference.
A more obvious place to search would be at gcc.gnu.org The answer would 
depend (at least) on your target platform, which of course this list 
doesn't want to hear about.
0
7/14/2006 5:47:35 PM
priyanka (in 1152897369.905570.47830@75g2000cwc.googlegroups.com)
said:

| Hi there,
|
| I want to learn about the calling convention that is adopted by the
| gcc compiler for C programs ? I need to learn about it immidiately
| for finding out the parameters passed to registers when a function
| call is made and print out the values of the parameters. Can anyone
| give me some pointers or refer to some book that would be helpful ?
| I tried searching at google but did not find any useful papers or
| reference.

Priyanka...

Gcc provides an option to stop after generating assembly code (man
gcc). Make a very short program with the call of interest - and
examine the assembly code file. Warning: the convention may vary from
processor to processor.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto


0
mrdovey (601)
7/14/2006 6:01:00 PM
priyanka wrote:
> Hi there,
>
> I want to learn about the calling convention that is adopted by the gcc
> compiler for C programs ? I need to learn about it immidiately for
> finding out the parameters passed to registers when a function call is
> made and print out the values of the parameters. Can anyone give me
> some pointers or refer to some book that would be helpful ? I tried
> searching at google but did not find any useful papers or reference.

What you want is called the Application Binary Interface [or something
like that] the acronym is ABI.

The compiler doesn't specify it.  The platform does.

Failing that you can always cheat and write a prototype for your
function, call it and see what the GCC assembler looks like.  That's
the unofficial quick and dirty solution that seems to work for simple
functions.

Tom

0
tomstdenis (380)
7/14/2006 6:43:12 PM
Tom St Denis wrote:
> priyanka wrote:
>> Hi there,
>>
>> I want to learn about the calling convention that is adopted by the gcc
>> compiler for C programs ? I need to learn about it immidiately for
>> finding out the parameters passed to registers when a function call is
>> made and print out the values of the parameters. Can anyone give me
>> some pointers or refer to some book that would be helpful ? I tried
>> searching at google but did not find any useful papers or reference.
> 
> What you want is called the Application Binary Interface [or something
> like that] the acronym is ABI.
> 
> The compiler doesn't specify it.  The platform does.
> 
To be precise in a way that does matter, some interested parties writing 
code for the platform do.

There's no such thing as "the" ABI for a platform (in contrast to, say, the 
register set) except that which is agreed upon by everyone. Unless, of 
course, one reverses things and takes up the position that the platform is 
*defined* by the ABI, which has its own problems.

S.
0
invalid58 (621)
7/14/2006 7:11:17 PM
"priyanka" <priyankabhar@gmail.com> wrote in message
news:1152897369.905570.47830@75g2000cwc.googlegroups.com...
> Hi there,
>
> I want to learn about the calling convention that is adopted by the gcc
> compiler for C programs ? I need to learn about it immidiately for
> finding out the parameters passed to registers when a function call is
> made and print out the values of the parameters. Can anyone give me
> some pointers or refer to some book that would be helpful ? I tried
> searching at google but did not find any useful papers or reference.
>

Read about the cdecl calling convention:
http://en.wikipedia.org/wiki/Calling_convention

More in depth info on register usage:
http://my.execpc.com/CE/AC/geezer/osd/libc/

Rod Pemberton



0
do_not_have1 (222)
7/15/2006 7:08:22 AM
"Skarmander" <invalid@dontmailme.com> wrote in message 
news:44b7ec53$0$31642$e4fe514c@news.xs4all.nl...
> There's no such thing as "the" ABI for a platform (in contrast to, say, 
> the register set) except that which is agreed upon by everyone. Unless, of 
> course, one reverses things and takes up the position that the platform is 
> *defined* by the ABI, which has its own problems.

I would say that position is the only logical one.  Programs are generally 
incompatible with libraries using a different ABI, and a "platform" is (in 
the real world) a collection of libraries and programs, so for the platform 
to be functional it must use a single ABI or provide mechanisms for code 
using different ABIs to link (e.g. Win16/32 thunking).

In that sense, Solaris x86, Linux x86, and Windows x86 are all different 
"platforms" even though they may be capable of running on the same hardware 
and, in some rare cases, using the same application source.  I doubt you'd 
find too many people claiming those are all the same "platform".

I'm not sure if Linux and the BSDs use the same x86 ABI; I think they do, 
but I also know they require special kernel support to run each others' 
binaries (though that may be due to syscall, not pure ABI, differences).

S

-- 
Stephen Sprunk        "Stupid people surround themselves with smart
CCIE #3723           people.  Smart people surround themselves with
K5SSS         smart people who disagree with them."  --Aaron Sorkin 


-- 
Posted via a free Usenet account from http://www.teranews.com

0
stephen (1366)
7/17/2006 1:13:41 AM
Reply: