Profiling with gcc

Profiling with gcc

Post by Aaron Baughe » Thu, 29 May 2003 20:46:16



In my quest to port Duke Nukem 3D to FreeBSD, I'm trying to profile
the program to see what's making it so low, as suggested on the
3drealms forum.  I add -pg to CFLAGS and LDFLAGS, and when it gets to
the linking stage, it dies like this:

gcc -o build -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib \
    -lSDL-1.1 -pthread build.o bstub.o engine.o cache1d.o \
    sdl_driver.o unix_compat.o a.o pragmas.o
/usr/local/lib/libaa.so.1: undefined reference to `longjmp'
/usr/local/lib/libaa.so.1: undefined reference to `setjmp'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getgid'
/usr/local/lib/libaa.so.1: undefined reference to `random'
/usr/local/lib/libesd.so.2: undefined reference to `connect'
[snip about 50 more similar lines]

If I take the -pg out, it compiles fine again.  After googling, I
thought I might be missing the profiling libraries, so I set NOPROFILE
to false in /etc/make.conf and did a full installworld and kernel
(4.8-R).  But I still get the same error above.  I looked in /usr/lib,
and I do have a bunch of lib*_p.a files, like libc_p.a.  They're all
dated from the day I originally installed this system, so it doesn't
look like my installworld installed them, but they do exist.

Anyone know what I'm missing here?

Thanks,
--
Aaron

 
 
 

Profiling with gcc

Post by Gunther Nik » Thu, 29 May 2003 20:55:57



> gcc -o build -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib \

  Is -L<> -Wl,<> necessary?

Quote:> If I take the -pg out, it compiles fine again.  After googling, I
> thought I might be missing the profiling libraries, so I set NOPROFILE
> to false in /etc/make.conf and did a full installworld and kernel
> (4.8-R).  But I still get the same error above.

  Did you add NOPROFILE=false? IMHO, NOPROFILE shouldn't be there at all to
  get the profiled libraries.

  Gunther

--
Linux is only free if your time has no value
 - Jamie Zawinsky

 
 
 

Profiling with gcc

Post by Aaron Baughe » Thu, 29 May 2003 22:12:39




> > gcc -o build -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib \

>   Is -L<> -Wl,<> necessary?

I don't know, but it works fine with them in there as long as I remove
-pg.  I'll try it without. ....  Nope, no luck.  Removing -W<> still
gives the same errors.  Removing -L<> makes it unable to find the SDL
libs at all.

Quote:>   Did you add NOPROFILE=false? IMHO, NOPROFILE shouldn't be there at
>   all to get the profiled libraries.

Yes, I did, because I wasn't sure if the default was true or false.
I'm not finding anything under /usr/obj that looks like profiling
libraries, though, except for lib/libc/profile.* and
lib/libc_r/profil.*.  Maybe my NOPROFILE setting confused it; I'll try
rebuilding again with that removed.

Thanks,
--
Aaron

 
 
 

Profiling with gcc

Post by Steven G. Kar » Fri, 30 May 2003 02:02:26




Quote:

> gcc -o build -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib \
>     -lSDL-1.1 -pthread build.o bstub.o engine.o cache1d.o \
>     sdl_driver.o unix_compat.o a.o pragmas.o

Is something missing here?

Quote:> /usr/local/lib/libaa.so.1: undefined reference to `longjmp'
> /usr/local/lib/libaa.so.1: undefined reference to `setjmp'
> /usr/X11R6/lib/libX11.so.6: undefined reference to `getgid'
> /usr/local/lib/libaa.so.1: undefined reference to `random'
> /usr/local/lib/libesd.so.2: undefined reference to `connect'
> [snip about 50 more similar lines]

Add -v to the command line and post the entire output.

--
Steve
http://troutmask.apl.washington.edu/~kargl/

 
 
 

Profiling with gcc

Post by Aaron Baughe » Fri, 30 May 2003 03:18:11



> Yes, I did, because I wasn't sure if the default was true or false.
> I'm not finding anything under /usr/obj that looks like profiling
> libraries, though, except for lib/libc/profile.* and
> lib/libc_r/profil.*.  Maybe my NOPROFILE setting confused it; I'll try
> rebuilding again with that removed.

No such luck.  I built and installed world without a NOPROFILE line in
/etc/make.conf, confirmed that it copied a bunch of lib*_p.a files
into /usr/lib, and rebooted.  I still get the same 'undefined
reference' errors when I give gcc the -pg option.

I wrote a simple hello.c program and compiled it with -pg, ran it, and
ran gprof on the resulting .gmon file.  So profiling does work in
general; it just won't with this command line:

gcc -o build -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib \
    -lSDL-1.1 -pthread build.o bstub.o engine.o cache1d.o \
    sdl_driver.o unix_compat.o a.o pragmas.o
/usr/local/lib/libaa.so.1: undefined reference to `longjmp'
/usr/local/lib/libaa.so.1: undefined reference to `setjmp'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getgid'
/usr/local/lib/libaa.so.1: undefined reference to `random'
/usr/local/lib/libesd.so.2: undefined reference to `connect'
[and so on]

I also tried installing the ngpt port, to see if that implementation
of pthread would help.  No change.  I think I've narrowed the problem
down to a conflict between profiling and either SDL or pthread (which
SDL requires).  I've exhausted all the leads I could find through
google searches.  Right now I'm installing lang/gcc33, to give that a
try.

Any other ideas?

--
Aaron

 
 
 

Profiling with gcc

Post by Aaron Baughe » Fri, 30 May 2003 06:24:12



Quote:> > gcc -o build -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib \
> >     -lSDL-1.1 -pthread build.o bstub.o engine.o cache1d.o \
> >     sdl_driver.o unix_compat.o a.o pragmas.o

> Is something missing here?

Nope, that's cut-and-pasted from the output; I just split the line.

Quote:> Add -v to the command line and post the entire output.

Here goes (splitting long lines):

gcc -o build -v -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib
-lSDL-1.1 -pthread build.o bstub.o engine.o cache1d.o sdl_driver.o
unix_compat.o a.o pragmas.o

Using builtin specs.
gcc version 2.95.4 20020320 [FreeBSD]

 /usr/libexec/elf/ld -V -dynamic-linker /usr/libexec/ld-elf.so.1 -o
 build /usr/lib/gcrt1.o /usr/lib/crti.o /usr/lib/crtbegin.o
 -L/usr/local/lib -L/usr/lib -rpath /usr/local/lib -lSDL-1.1 build.o
 bstub.o engine.o cache1d.o sdl_driver.o unix_compat.o a.o pragmas.o
 -lgcc_p -lc_r_p -lgcc_p /usr/lib/crtend.o /usr/lib/crtn.o

GNU ld version 2.12.1 [FreeBSD] 2002-07-20
  Supported emulations:
   elf_i386
/usr/local/lib/libaa.so.1: undefined reference to `longjmp'
/usr/local/lib/libaa.so.1: undefined reference to `setjmp'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getgid'
/usr/local/lib/libaa.so.1: undefined reference to `random'
/usr/local/lib/libesd.so.2: undefined reference to `connect'
/usr/X11R6/lib/libX11.so.6: undefined reference to `xdrmem_create'
/usr/local/lib/libaa.so.1: undefined reference to `atol'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getegid'
/usr/X11R6/lib/libX11.so.6: undefined reference to `__inet_addr'
/usr/local/lib/libvga.so.1: undefined reference to `usleep'
/usr/lib/libncurses.so.5: undefined reference to `vsscanf'
/usr/lib/libm.so.2: undefined reference to `__infinity'
/usr/local/lib/libesd.so.2: undefined reference to `execl'
/usr/local/lib/libvga.so.1: undefined reference to `puts'
/usr/local/lib/libesd.so.2: undefined reference to `getuid'
/usr/local/lib/libvga.so.1: undefined reference to `system'
/usr/lib/libncurses.so.5: undefined reference to `remove'
/usr/local/lib/libesd.so.2: undefined reference to `endpwent'
/usr/X11R6/lib/libX11.so.6: undefined reference to `sleep'
/usr/local/lib/libaudiofile.so.0: undefined reference to `ldexp'
/usr/local/lib/libaudiofile.so.0: undefined reference to `vsnprintf'
/usr/X11R6/lib/libX11.so.6: undefined reference to `authdes_create'
/usr/X11R6/lib/libX11.so.6: undefined reference to `wctomb'
/usr/local/lib/libesd.so.2: undefined reference to `socket'
/usr/X11R6/lib/libX11.so.6: undefined reference to `mbstowcs'
/usr/X11R6/lib/libX11.so.6: undefined reference to `strncasecmp'
/usr/local/lib/libvga.so.1: undefined reference to `setpgid'
/usr/local/lib/libesd.so.2: undefined reference to `pipe'
/usr/lib/libncurses.so.5: undefined reference to `getpgrp'
/usr/local/lib/libartsc.so.0: undefined reference to `strrchr'
/usr/X11R6/lib/libX11.so.6: undefined reference to `readv'
/usr/local/lib/libvga.so.1: undefined reference to `vprintf'
/usr/local/lib/libesd.so.2: undefined reference to `__inet_aton'
/usr/local/lib/libesd.so.2: undefined reference to `setsockopt'
/usr/local/lib/libvga.so.1: undefined reference to `setgid'
/usr/X11R6/lib/libX11.so.6: undefined reference to `unlink'
/usr/local/lib/libesd.so.2: undefined reference to `strcasecmp'
/usr/local/lib/libesd.so.2: undefined reference to `strtok'
/usr/local/lib/libaudiofile.so.0: undefined reference to `fdopen'
/usr/local/lib/libvga.so.1: undefined reference to `execv'
/usr/local/lib/libvga.so.1: undefined reference to `setreuid'
/usr/local/lib/libaudiofile.so.0: undefined reference to `__swbuf'
/usr/local/lib/libvga.so.1: undefined reference to `getppid'
/usr/X11R6/lib/libX11.so.6: undefined reference to `time'
/usr/X11R6/lib/libX11.so.6: undefined reference to `poll'
/usr/local/lib/libesd.so.2: undefined reference to `getitimer'
/usr/local/lib/libvga.so.1: undefined reference to `seteuid'
/usr/local/lib/libvga.so.1: undefined reference to `nice'
/usr/X11R6/lib/libX11.so.6: undefined reference to `shutdown'
/usr/local/lib/libesd.so.2: undefined reference to `getpwuid'
/usr/local/lib/libaudiofile.so.0: undefined reference to `dup'
/usr/lib/libncurses.so.5: undefined reference to `getcwd'
/usr/local/lib/libesd.so.2: undefined reference to `gethostbyname'
/usr/local/lib/libvga.so.1: undefined reference to `strsignal'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getpwnam'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getservbyname'
/usr/local/lib/libvga.so.1: undefined reference to `fgetc'
/usr/local/lib/libesd.so.2: undefined reference to `gethostname'
/usr/local/lib/libesd.so.2: undefined reference to `strcspn'
/usr/X11R6/lib/libX11.so.6: undefined reference to `setlocale'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getpeername'
/usr/lib/libncurses.so.5: undefined reference to `strsep'
/usr/local/lib/libesd.so.2: undefined reference to `fsync'
/usr/local/lib/libvga.so.1: undefined reference to `valloc'
/usr/lib/libncurses.so.5: undefined reference to `fputc'
/usr/lib/libncurses.so.5: undefined reference to `cgetset'
/usr/local/lib/libesd.so.2: undefined reference to `access'
/usr/X11R6/lib/libX11.so.6: undefined reference to `rewind'
/usr/lib/libncurses.so.5: undefined reference to `link'
/usr/lib/libncurses.so.5: undefined reference to `cgetent'
/usr/local/lib/libvga.so.1: undefined reference to `strspn'
/usr/local/lib/libvga.so.1: undefined reference to `clock'
/usr/lib/libm.so.2: undefined reference to `fputs'
/usr/local/lib/libvga.so.1: undefined reference to `setegid'
/usr/local/lib/libaa.so.1: undefined reference to `srandomdev'
/usr/local/lib/libvga.so.1: undefined reference to `setuid'
/usr/lib/libncurses.so.5: undefined reference to `mkdir'
/usr/local/lib/libaudiofile.so.0: undefined reference to `frexp'
/usr/X11R6/lib/libX11.so.6: undefined reference to `mbtowc'
/usr/local/lib/libvga.so.1: undefined reference to `sysctlbyname'
/usr/X11R6/lib/libX11.so.6: undefined reference to `strpbrk'
/usr/X11R6/lib/libX11.so.6: undefined reference to `___tolower'
/usr/local/lib/libvga.so.1: undefined reference to `raise'
/usr/local/lib/libvga.so.1: undefined reference to `sigprocmask'
/usr/X11R6/lib/libX11.so.6: undefined reference to `getsockname'
gmake: *** [build] Error 1

--
Aaron

 
 
 

Profiling with gcc

Post by Steven G. Kar » Fri, 30 May 2003 07:09:59





>> > gcc -o build -g -pg -L/usr/local/lib -Wl,-rpath,/usr/local/lib \
>> >     -lSDL-1.1 -pthread build.o bstub.o engine.o cache1d.o \
>> >     sdl_driver.o unix_compat.o a.o pragmas.o

>> Is something missing here?

> Nope, that's cut-and-pasted from the output; I just split the line.

Is SDL-1.1 a shared library?  The missing routines appear
to be from libc_r_p, but libraries in the error messages
aren't being linked into build.  

Can you do

gcc -o build -g -pg -pthread build.o bstub.o engine.o cache1d.o \
     sdl_driver.o unix_compat.o a.o pragmas.o -L/usr/local/lib \
     -lSDL-1.1 -lvga -lesd -laudiofile -laa -lncurses -lX11

That is explicitly include the missing libraries.  Note, you
may need to play with the ordering.

--
Steve
http://troutmask.apl.washington.edu/~kargl/

 
 
 

Profiling with gcc

Post by Aaron Baughe » Fri, 30 May 2003 20:50:24



Quote:> Is SDL-1.1 a shared library?  The missing routines appear
> to be from libc_r_p, but libraries in the error messages
> aren't being linked into build.  

Yes, I think it is shared.  The Makefile runs 'sdl-config --libs' to
get this part of it:

  -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lSDL-1.1 -pthread

I tried replacing that with 'sdl-config --static-libs', which returns
a much longer list:

  -L/usr/local/lib -Wl,-rpath,/usr/local/lib -lSDL-1.1 -pthread -lm \
  -L/usr/local/lib -lartsc -pthread -L/usr/local/lib -lesd \
  -laudiofile -lm -L/usr/local/lib -lgnugetopt -L/usr/X11R6/lib \
  -lX11 -lXext -lvga -laa -lusbhid

That got rid of many of the undefined references, but not all of them.

Quote:> Can you do
> gcc -o build -g -pg -pthread build.o bstub.o engine.o cache1d.o \
>      sdl_driver.o unix_compat.o a.o pragmas.o -L/usr/local/lib \
>      -lSDL-1.1 -lvga -lesd -laudiofile -laa -lncurses -lX11

Yes, that worked!  I had all those things when I tried static-libs,
except for ncurses, and the order was different.  Thanks very much!

--
Aaron

 
 
 

1. Profiling with gcc

        I would appreciate explicit instructions
on how to get profiling to work under gcc/g++
on Linux, including version numbers for gcc,
libraries and kernel. I have read the faq and
tried numerous times to profile, but have never
achieved anything other than a program that
instantly seg-faults.

                Thanks,
                        Frederick Umminger

2. authorize only some to su root

3. Profiling with gcc on solaris x86

4. stupid pipe/FILE * question

5. profiling with gcc ???

6. Question about /proc/stat

7. Profiling with GCC-2, and Solaris 2.3 (No Proworks)

8. Sanyo CD ROM Problem

9. Linker/Profile error GCC 2.6.3

10. GCC and profiling

11. GCC-2.95 configuration & profile.

12. gcc 2.95.3 + profiling + s8 = link errors

13. gcc-2.5.8, solaris 2.3, threads, and profiling