[TriLUG] what do crt[1in].o do?
Rodney Radford
rradford at mindspring.com
Wed Dec 9 13:33:23 EST 2009
Take a look at this website for details about the internals of the GCC compiler as it will answer a lot of your questions:
http://gcc.gnu.org/onlinedocs/gccint/
It goes over the various phases of the compiler, how the code is generated, the linker steps, and a program called collect2 that is actually responsible for pulling all the system relevant pieces together.
You can also run strace on the executable generated to find out what system calls are executed for the process and the names of any shared libraries that are being opened (for example, /lib/libc.so.6 for my system).
And may I ask why you are curious? Is it just the search for knowledge (always a good thing, and if so, that page will be a great start), or is there a development issue you are trying to resolve?
-----Original Message-----
>From: Joseph Mack NA3T <jmack at wm7d.net>
>Sent: Dec 9, 2009 11:10 AM
>To: Triangle Linux Users Group General Discussion <trilug at trilug.org>
>Subject: Re: [TriLUG] what do crt[1in].o do?
>
>On Wed, 9 Dec 2009, Rodney Radford wrote:
>
>>
>> The crt are the "C Run Time" objects that set up the
>> environment expected by main, such as getting the opening
>> any files,
>
>OK
>
>> initializing the C runtime library
>
>what/where is the C runtime library - is it in the crt*.o
>files?
>
>> 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.
>
>thanks good to know. I haven't been able to find this
>anywhere with google and it's not in K&R II or Harbison and
>Steel (another C book)
>
>I assume this is common knowledge somewhere. Is this found
>in undergrad CS books?
>
>> You should be able to create the link line with your
>> output assembly file and those files,
>
>that's what I thought too :-)
>
>> but there may be additional switches to set up the entry
>> point for the executable.
>
>who know's what's missing.
>
>> 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.
>
>sounds reasonable.
>
>I did find two crt*.asm files, but not the 3rd. When I
>figure out how to link the crt*.o files to get a working
>executable, the next thing would be to produce the crt*.o
>files from the .asm files. However docs on the internet seem
>to assocate the crt*.o files with libc in some situations
>and with the compiler in other situations (and I don't know
>which is which). Presumably you'd have to understand this to
>link up all of these files from source.
>
>> 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.
>
>sounds reasonable too - it's theoretically possible then.
>That's good to know.
>
>Thanks Joe
>
>--
>Joseph Mack NA3T EME(B,D), FM05lw North Carolina
>jmack (at) wm7d (dot) net - azimuthal equidistant map
>generator at http://www.wm7d.net/azproj.shtml
>Homepage http://www.austintek.com/ It's GNU/Linux!
>--
>TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
>TriLUG FAQ : http://www.trilug.org/wiki/Frequently_Asked_Questions
More information about the TriLUG
mailing list