Subject: Re: Can't compile with profiling...
To: None <mikel@shore.net>
From: Brian C. Grayson <bgrayson@ece.utexas.edu>
List: netbsd-help
Date: 10/27/1997 23:00:39
Mike Long wrote:
>
> >Date: Sun, 26 Oct 1997 18:47:56
> >From: Jonathan Belson <jon@dookie.demon.co.uk>
>
> >I've been trying to compile a piece of code with profiling enabled...
> >Compilation of each file with the -pg option goes fine, but when I
> >link I get an error about the symbol __DYNAMIC being undefined.
> >
> >gcc -o vector main.o display.o object.o rock.o real.o --verbose -pg
> >-lstdc++ -lm -L/usr/local/X11R6.1/lib -lX11 -lXext -lSM -lICE
> >gcc version 2.7.2
> > ld -e start -dc -dp -o vector /usr/lib/gcrt0.o
> >-L/usr/local/X11R6.1/lib -L/usr/libexec main.o display.o object.o
> >rock.o real.o -lstdc++ -lm -lX11 -lXext -lSM -lICE -lgcc -lc_p -lgcc
>
> >Am I doing something wrong, is my installation broken or (shudder)
> >does gcc not support profiling of C++ code?
>
> Use gcc to link the binary, instead of trying to use ld directly.
Er. I thought the --verbose flag he is passing to his command
line "gcc -o ... --verbose -pg -lstdc++ ... -lICE" is the same
as the -v flag, i.e., the line "gcc version 2.7.2" and below is
what _gcc_ is doing, and not what he typed. And I think the
other note, about compiling with -fpic, isn't really needed for
compiling full programs, is it? I've never actually used -fpic
except for creating shared libraries or ``embedded'' programs that
would be relocated later. But, my ld knowledge is quite limited.
Regardless, profiling of dynamically-linked programs has been
broken for us (running mostly -current) for at least one year,
perhaps more. As a work-around, change the link flags from -pg
to -pg -static, and things will work.
Here's output from a session (with list of 70 .o files truncated):
> which gcc g++
/usr/bin/gcc
/usr/local/bin/g++
> g++ -pg (lots of .o files) -o psim
ld: No reference to __DYNAMIC
> g++ -pg -v *.o -o psim
gcc version 2.7.2.2
ld -e start -dc -dp -o psim /usr/lib/gcrt0.o -L/usr/libexec (*.o here)
-lg++ -lstdc++ -lm -lgcc -lc_p -lgcc
ld: No reference to __DYNAMIC
> g++ -pg -static *.o -o psim
> (no errors)
The same thing happens if we use gcc instead of g++.
From a quick inspection of /usr/share/mk, the -pg flag is only
used in building the .po files for lib*_p.a.
Is there anything that says, fundamentally, that profiling and
dynamic linking don't go together? I could have _sworn_ this
used to work circa 1.0. But back then I didn't know what I was
doing (as if I know what I'm doing now!). :)
Do we just need to add a new crt file, dgcrt0.o or some such,
that is compiled with both -DDYNAMIC and -DMCRT0, and modify the
gcc specs file/gcc.c appropriately for the -shared -pg case?
Not that it matters, but gcc -pg foo.c works fine under L*nux. :)
Anyway, I hope the -static trick works for you!
Brian
--
Brian Grayson (bgrayson@ece.utexas.edu)
Graduate Student, Electrical and Computer Engineering
The University of Texas at Austin
Office: ENS 406 (512) 471-8011
Finger bgrayson@orac.ece.utexas.edu for PGP key.