[LIP] Re: Program Execution

Trideepraj Roychoudhury <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
On Mon, Sep 13, 2004 at 08:39:32PM -0700, linux-india-programmers-request-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org wrote:
 
> 
> Hi
> This is regarding program execution,
> I have seen lot many system calls being called
> b4 actually the execution of program happens.
> I would like to know where this code present.
> To be precise, the code that gets executed for 
> a program is to be made to process.
> If some one knows kindly let me know.
> thanks
> 
> V.V Suresh Kumar
> 
> V.V Suresh Kumar
>

$ gcc -v trial.c

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
 "/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cc1" "-lang-c" "-D__GNUC__=3" "-D__GNUC_MINOR__=2" "-D__GNUC_PATCHLEVEL__=2" "-D__GXX_ABI_VERSION=102" "-D__ELF__" "-Dunix" "-D__gnu_linux__" "-Dlinux" "-D__ELF__" "-D__unix__" "-D__gnu_linux__" "-D__linux__" "-D__unix" "-D__linux" "-Asystem=posix" "-D__NO_INLINE__" "-D__STDC_HOSTED__=1" "-Acpu=i386" "-Amachine=i386" "-Di386" "-D__i386" "-D__i386__" "-D__tune_i386__" "trial.c" "-quiet" "-dumpbase" "trial.c" "-o" "/tmp/cco6iST3.s"
 "as" "-Qy" "-o" "/tmp/ccMf2AHX.o" "/tmp/cco6iST3.s"

 ************************
 "/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/collect2" "--eh-frame-hdr" "-m" "elf_i386" "-dynamic-linker" "/lib/ld-linux.so.2" "/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o" "/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crti.o" "/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtbegin.o" "-L/usr/lib/gcc-lib/i386-redhat-linux/3.2.2" "-L/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../.." "/tmp/ccMf2AHX.o" "-lgcc" "-lgcc_eh" "-lc" "-lgcc" "-lgcc_eh" "/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtend.o" "/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crtn.o"
*************************

The output within asteriks, is the linker( collect2 ) output. If you closely study it you will find out that certain object files other than library files (ld-linux.so.2) are getting linked with your program object code( i.e. ccMf2AHX.o, the output file name generated by "as" ).

The files of interest are crt1.o crti.o crtbegin.o crtend.o crtn.o. When a program begins execution the environment for the program to run is created by code present in these object files. After setting up program environment execution control jumps to main(). Hence if you dont have a main() your program cannot execute. By the way, you can use other function as your programs entry point by passing some parameters to gcc. When the program ends, i.e. return is executed in main() there is some cleanup work doen by the code present in these object files.

Hope that answers your question. Correct me if i am wrong anywhere...

-- 
Trideepraj Roychoudhury
Linux Kernel Consultant
FSALabs(www.fsalabs.com)



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.