Re: The generated binary code has different main?

From: Bruce Ediger (eballen1@qwest.net)
Date: 09/05/02


Date: Wed, 4 Sep 2002 16:40:06 -0600 (MDT)
From: "Bruce Ediger" <eballen1@qwest.net>
To: "Minchu Mo" <morris_minchu@iwon.com>


On 4 Sep 2002, Minchu Mo wrote:

> I used cc compiler to compile a simple c code under solaris /sparc. The c
> code has main(int argc, char* argv[]) function as entry point as everybody
> knows.
>
> But when I run the generated code under adb, I found the main function
> under adb look like this:
>
> main(2,ffbefd0c,ffbefd18,20800,0,0)
>
> I know that:
> 2 is the number of arguments,
> ffbefd0c is *argv
> ffbefd18 is *envp,
> but what are 20800 and 0, 0 for?
>
> Anybody knows? Thanks

You see an artifact of the SPARC architecture. The first 6 arguments get
passed in registers (%o0 through %o5 in the calling function). adb is a
very simple debugger, and I don't think it looks in the debugging symbols
to find out how many arguments a given function uses.

adb is just showing you the values in the appropriate 6 registers when
main() got called from the well-known routine (start or _start or .start,
I forget) in crt0.o that cc compiles in to any C program by default.

The values 20800, 0, 0 are just whats in the registers, left over from
the code in crt0.o

Try doing a "cc -v -v -v whatever.c" to see what cc actually does. The
ld command line is very instructive.