[bitlug] C Startup files...

  • From: Peeyush Prasad <peeyush@xxxxxxxxxx>
  • To: bitlug@xxxxxxxxxxxxx
  • Date: Tue, 15 Nov 2005 10:08:08 +0530 (IST)

Hi again,
 Thought I should start another thread for this discussion...
Does anybody know the functions of the various startup files ?
I see the following on my system: (RH 7.3, gcc 2.96)

/usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o
/usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbeginS.o
/usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o
/usr/lib/gcc-lib/i386-redhat-linux/2.96/crtendS.o

 and

/usr/lib/crt1.o
/usr/lib/crti.o
/usr/lib/crtn.o

These guys get linked in if you do a default gcc build with the c library:

Best thing to do is to find the files in the gcc sources and go through them, but I want to stay away from that....

Now,lets see...

[vlbi@rcs1 bfin]$ cat hello.c
#include <stdio.h>

int main(int argc,char *argv[])
{
  int i = 0;
  for(i=0; i<10; i++)
   printf("Go AwaY!! >:-(\n");
  getchar();
  return 0;
}

[vlbi@rcs1 bfin]$ gcc -v -o hello hello.c

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
/usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__NO_INLINE__ -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ hello.c /tmp/ccLkKeK6.i
GNU CPP version 2.96 20000731 (Red Hat Linux 7.3 2.96-110) (cpplib) (i386 Linux/ELF)


ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/include
 /usr/include
End of search list.

// =========== Compile command ==============
/usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1 /tmp/ccLkKeK6.i -quiet -dumpbase hello.c -version -o /tmp/ccu7NLr5.s
GNU C version 2.96 20000731 (Red Hat Linux 7.3 2.96-110) (i386-redhat-linux) compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.3 2.96-110).


// ========== Assemble command ==============
as -V -Qy -o /tmp/ccpaFlN5.o /tmp/ccu7NLr5.s
GNU assembler version 2.11.93.0.2 (i386-redhat-linux) using BFD version 2.11.93.0.2 20020207
// ========== Linker called from within the assembler =========
/usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o hello /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. /tmp/ccpaFlN5.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o



[vlbi@rcs1 vlbi]$ pgrep hello 20713 [vlbi@rcs1 vlbi]$ cat /proc/20713/ cmdline cwd exe maps mounts stat status cpu environ fd mem root statm [vlbi@rcs1 vlbi]$ cat /proc/20713/mem cat: /proc/20713/mem: No such process [vlbi@rcs1 vlbi]$ cat /proc/20713/maps 08048000-08049000 r-xp 00000000 03:05 229541 /home/vlbi/bfin/hello 08049000-0804a000 rw-p 00000000 03:05 229541 /home/vlbi/bfin/hello 40000000-40013000 r-xp 00000000 03:07 67421 /lib/ld-2.2.5.so 40013000-40014000 rw-p 00013000 03:07 67421 /lib/ld-2.2.5.so 40014000-40016000 rw-p 00000000 00:00 0 42000000-4212c000 r-xp 00000000 03:07 114259 /lib/i686/libc-2.2.5.so 4212c000-42131000 rw-p 0012c000 03:07 114259 /lib/i686/libc-2.2.5.so 42131000-42135000 rw-p 00000000 00:00 0 bfffe000-c0000000 rwxp fffff000 00:00 0


Questions: 1. What is cpp0? 2. What does collect2 do ?? 3. The following are linked in: crt1.o crti.o crtbegin.o crtend.o crtn.o -lc -lgcc. Why?? 4. The dynamic linker ? /lib/ld-linux.so.2 ??

-- P ps - output :^)
[vlbi@rcs1 bfin]$ ./hello
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(
Go AwaY!! >:-(



Other related posts: