[comp.unix.aux] -The weirdness of the crt*.o files

abyss@Apple.COM (Ananthan Srinivasan) (08/01/90)

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.

coolidge@casca.cs.uiuc.edu (John Coolidge) (08/01/90)

abyss@Apple.COM (Ananthan Srinivasan) writes:
>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".

This is basically how I determined what to have gcc use in its
run of ld. The gcc patches that I just released, and the 1.37.91
binaries, use crt1, crt2, crtn, and shlib.ld whenever building
an executable. The g++ patches (that I'll hopefully get out the
door soon :-)) will also use them.

--John

--------------------------------------------------------------------------
John L. Coolidge     Internet:coolidge@cs.uiuc.edu   UUCP:uiucdcs!coolidge
Of course I don't speak for the U of I (or anyone else except myself)
Copyright 1990 John L. Coolidge. Copying allowed if (and only if) attributed.
You may redistribute this article if and only if your recipients may as well.