[TriLUG] what do crt[1in].o do?
Joseph Mack NA3T
jmack at wm7d.net
Wed Dec 9 10:33:14 EST 2009
I haven't been able to find out much here after a couple of
If you have a single small source file (eg a main() that
just has "return 0;") you get a small object file. When you
link to get the executable, about 2k is added. AFAICT, this
extra code comes from 3 files crt[1in].o. If this is so, I
should be able to produce the executable directly from the
.c source code with gcc, or via the .s file using gas/as. I
can't get the gas/as route to work, which means that I'm not
using the crt*.o files correctly.
gcc -S main.c #produces main.s
gcc -o main main.s #produces executable which runs
This produces an executable that doesn't run
as -o main.o main.s #
ld -m elf_i386 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o main.o -lc -o main
-bash: ./main: No such file or directory
The missing file seems to be /usr/lib/libc.so.1, (which
indeed doesn't exist). Linking /usr/lib/libc.so.1 to
/usr/lib/libc.so gets "permission denied". I don't know why
-lc picks up /usr/lib/libc.so. If I explicitely use
/lib/libc.so.6 I get undefined references.
So I have two problems
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
Anyone know what's going on, give me pointer?
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!
More information about the TriLUG