calling convention adopted by the gcc compiler for the C programs

P

priyanka

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
 
T

Tim Prince

priyanka 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.
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.
 
M

Morris Dovey

priyanka (in (e-mail address removed))
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.
 
T

Tom St Denis

priyanka 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.

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
 
S

Skarmander

Tom said:
priyanka 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.

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.
 
R

Rod Pemberton

priyanka 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.

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
 
S

Stephen Sprunk

Skarmander said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top