[TriLUG] what do crt[1in].o do?

Rodney Radford rradford at mindspring.com
Wed Dec 9 10:49:56 EST 2009


The crt are the "C Run Time" objects that set up the environment expected by main, such as getting the opening any files, initializing the C runtime library, setting up the stack, setting up heap, and grabbing the values of argc, argv, and envp for your main program, and opening stdin, stdout and stderr.

You should be able to create the link line with your output assembly file and those files, but there may be additional switches to set up the entry point for the executable.

The reason the debugger starts at main is you are using a source level debugger and you don't have C source for the crt files.  If you were to use a lower level debugger (or you can probably pass in an argument to your debugger to tell it to not auto-step over the crt code), you could stop at the real entry point and single step through the assembly code setup.

---------------
o I can't produce an executable using the crt*.o files, 
although webpages on the internet use the ld line above 
(sometimes without the -m elf_i386 and sometimes with 
--verbose). I've tried the line above on several machines, 
including ones I haven't setup (and can't have messed up) 
and which are straight installs from a distro on a cd.

o I don't know much about why you can't just make the 
executable from the *.o file without adding 2k of extra 
files. AFAICT some segment (data?) is initialised to 0.
As well the extra code has a start() which is the real start 
of the code. After start() returns, then main() is called. 
When you run the debugger, you don't see any of the code 
before main().




More information about the TriLUG mailing list