[comp.unix.aux] Using -p

jimg@zeno.gso.uri.edu (James Gallagher) (02/04/91)

I have had no success. 

Here's what I've tried: 

1) I tried compiling a simple program with 'gcc -p -v -D_BSD_SOURCE
-D_SYSV_SOURCE simple.c' and got the error 'linker cant find -lc_p'.

2) I tried 'cc -v -p simple.c' (I can use cc on simple.c, but not on the ANSI
program I want to profile). That works. So, I tried using the linker that way
cc did (it used /lib/libp/libc rather than the non-existant libc_p). However,
I got an undefined symbol error (d0 and mcount 'referenced but not defined').

Any help would be grately appreciated.

-- 
James Gallagher
jimg@zeno.gso.uri.edu

liam@cs.qmw.ac.uk (William Roberts;) (02/06/91)

In <532@rafos.UUCP> jimg@zeno.gso.uri.edu (James Gallagher) writes:

>I have had no success. 

>Here's what I've tried: 

>1) I tried compiling a simple program with 'gcc -p -v -D_BSD_SOURCE
>-D_SYSV_SOURCE simple.c' and got the error 'linker cant find -lc_p'.

>2) I tried 'cc -v -p simple.c' (I can use cc on simple.c, but not on the ANSI
>program I want to profile). That works. So, I tried using the linker that way
>cc did (it used /lib/libp/libc rather than the non-existant libc_p). However,
>I got an undefined symbol error (d0 and mcount 'referenced but not defined').

>Any help would be grately appreciated.

You didn't look closely enough at the difference between A/UX cc and A/UX cc 
with the -p (I presume you used the -v option to find out what is happening).

% /nfs/CDROM/bin/cc -v -p foo.c
/nfs/CDROM/lib/cpp -Dmc68k32 foo.c /usr/tmp/ctmAAAa004914
/nfs/CDROM/lib/ccom -Xn -XI -U /usr/tmp/ctmAAAa004914 /usr/tmp/ctmAAAa004913 
-XP
/nfs/CDROM/bin/as -o foo.o /usr/tmp/ctmAAAa004913
/nfs/CDROM/bin/ld /nfs/CDROM/lib/mcrt0.o /nfs/CDROM/lib/crt2.o -L/lib/libp 
foo.o -lc /nfs/CDROM/lib/crtn.o /nfs/CDROM/usr/lib/shlib.ld

% /nfs/CDROM/bin/cc -v foo.c
/nfs/CDROM/lib/cpp -Dmc68k32 foo.c /usr/tmp/ctmAAAa004964
/nfs/CDROM/lib/ccom -Xn -XI -U /usr/tmp/ctmAAAa004964 /usr/tmp/ctmAAAa004963
/nfs/CDROM/bin/as -o foo.o /usr/tmp/ctmAAAa004963
/nfs/CDROM/bin/ld /nfs/CDROM/lib/crt1.o /nfs/CDROM/lib/crt2.o foo.o -lc 
/nfs/CDROM/lib/crtn.o /nfs/CDROM/usr/lib/shlib.ld

Don't worry about /nfs/CDROM - it is just a disk image mounted read-only. The 
salient features are:

Profiling: link with mcrt0.o crt2.o and -L/lib/libp 
Normal:    link with crt1.o  crt2.o and no tricks about libraries.

The thing you are missing is mcrt0.o which starts things up correctly and 
provides those missing symbols. Personally I prefer the _p trick for naming 
profiled libraries because it is more generic that having cc invoke ld with an 
additional -L option: do I really want to put my profiled X libraries into 
/lib/libp?

This is another problem for the long suffering John Coolidge to look into, 
though personally I'd recommend fixing the mcrt0.o part and ignoring the 
-L/lib/libp stuff.
--

William Roberts                 ARPA: liam@cs.qmw.ac.uk
Queen Mary & Westfield College  UUCP: liam@qmw-cs.UUCP
Mile End Road                   AppleLink: UK0087
LONDON, E1 4NS, UK              Tel:  071-975 5250 (Fax: 081-980 6533)

coolidge@cs.uiuc.edu (John Coolidge) (02/06/91)

jimg@zeno.gso.uri.edu (James Gallagher) writes:
>I have had no success. 

>Here's what I've tried: 
>1) I tried compiling a simple program with 'gcc -p -v -D_BSD_SOURCE
>-D_SYSV_SOURCE simple.c' and got the error 'linker cant find -lc_p'.

My fault; I left LIB_SPEC doing the wrong thing. Fixed in the next
release :-). I'm not sure what the right thing to do with -pg is; for
now I'll have it do the same thing as -p. Perhaps one day I'll
produce my 'almost complete, almost wonderful, mostly free libc' and
run gprof on it :-)

>2) I tried 'cc -v -p simple.c' (I can use cc on simple.c, but not on the ANSI
>program I want to profile). That works. So, I tried using the linker that way
>cc did (it used /lib/libp/libc rather than the non-existant libc_p). However,
>I got an undefined symbol error (d0 and mcount 'referenced but not defined').

This I'll have to look at. I don't really know anything about the
profiling code or what's needed to make it work. I'll try to figure
things out and make it all work. There's some code in the gcc config
file which is supposed to support profiling, but I'm not sure what
it's doing and why...

>Any help would be grately appreciated.

None of this really helps; I'll take a look at it sometime soon. I'd
kinda like to profile some things myself (although I seem to recall
some depressing posts about the stability of profiling in general
under A/UX; anyone remember something like that?). Right now I'm
finishing off g++ (seems to be stable; found one bug in libg++ and
broke it somewhere else; whole package hopefully later this week :-)).

--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 1991 John L. Coolidge. Copying allowed if (and only if) attributed.
You may redistribute this article if and only if your recipients may as well.