-The weirdness of the crt*.o files-

Ananthan Srinivasan abyss at Apple.COM
Wed Aug 1 04:27:48 AEST 1990


To see all the right crt*.o files that need to be used to keep 'ld' happy,
write a dummy program (dummy.c) and compile it using "cc -v".
On A/UX 2.0 you will see that 'ld' is invoked as foll:
"/bin/ld /lib/crt1.o /lib/crt2.o dummy.o -lc /lib/crtn.o /usr/lib/shlib.ld"
On A/UX 1.* this is
"/bin/ld /lib/crt0.o dummy.o -lc /usr/lib/shared.ld".

The new crt files in A/UX 2.0 - crt1.o, crt2.o and crtn.o replace the old
crt0.o file and provide the mechanism to support shared libraries. The files
crt1.o and crt2.o need to be specified as the first 2 object files to be
linked and crtn.o needs to the last object file to be linked. (The link
directive files - /usr/lib/shlib.ld or /usr/lib/shared.ld are not object files,
they contain specifications for the layout of the final executable - a.out.
/usr/lib/shlib.ld needs to be used if any shared libraries are being linked 
if not /usr/lib/shared.ld works fine.

The 'cc' front end (which calls 'cpp', 'as' and 'ld') has been modified in
A/UX 2.0 so that all the proper crt files are used if an executable is to
be obtained. However if the final linking of several objects is done explicitly,
the appropriate crt files (crt0.o for A/UX 1.* and crt1.o, crt2.o & crtn.o for
A/UX 2.0) need to be used in the right order. [Note: Linking in different
libraries using the -l option with 'cc' results in the appropriate libraries
being added after '-lc (libc) and before '/lib/crtn.o' in A/UX 2.0]

Srinivasan, A.B.



More information about the Comp.unix.aux mailing list