[TriLUG] what do crt[1in].o do?
rradford at mindspring.com
Wed Dec 9 11:24:10 EST 2009
Try turning on the -v (verbose) option on your gcc command line and it gives you information about what steps it is taking to compile, assemble and link your program.
The crt1.s file is just the setup for the C runtime library, but does not contain the various functions you call from your code. The only thing in crt1.s is the minimum setup for your code. The actual routines exist in a library, usually called /usr/lib/libc.a, or some similar wording.
>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,
>> initializing the C runtime library
>what/where is the C runtime library - is it in the crt*.o
>> 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.
>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.
>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