gcc 4.2 profiling breaks argv

Garrett Cooper youshi10 at u.washington.edu
Sat Aug 4 19:06:14 UTC 2007


Niklas Sorensson wrote:
> Hi,
>
> following up on the thread started by Nick Frampton yesterday:
>
> I can repeat the problem, although it looks slightly different. 
> Instead of crashing when argv is accessed, both argc and argv are 
> zero. This behavior is triggered by both gcc 4.2.0 and 4.2.1:
>
> nik> cat test.c
> #include <stdio.h>
> int main (int argc, char **argv) {
>    fprintf (stderr, "argc=%d, argv=%p\n", argc, argv);
>    return 0;
> }
> nik> cc -c -o test.o -pg  test.c &&  cc -o test  -pg  test.o
> nik> ./test
> argc=0, argv=0x0
>
> nik> gcc42 -c -o test.o -pg  test.c && gcc42 -o test  -pg  test.o
> nik> ./test
> argc=0, argv=0x0
>
> nik> cc -v
> Using built-in specs.
> Target: i386-undermydesk-freebsd
> Configured with: FreeBSD/i386 system compiler
> Thread model: posix
> gcc version 4.2.0 20070514 [FreeBSD]
>
> nik> gcc42 -v
> Using built-in specs.
> Target: i386-portbld-freebsd7.0
> Configured with: ./..//gcc-4.2.1-RC-20070712/configure --disable-nls 
> --with-system-zlib --with-libiconv-prefix=/usr/local 
> --with-gmp=/usr/local --program-suffix=42 
> --libdir=/usr/local/lib/gcc-4.2.1 
> --with-gxx-include-dir=/usr/local/lib/gcc-4.2.1/include/c++/ 
> --disable-libgcj --prefix=/usr/local --mandir=/usr/local/man 
> --infodir=/usr/local/info/gcc42 i386-portbld-freebsd7.0
> Thread model: posix
> gcc version 4.2.1 20070712 (prerelease)
>
> nik> uname -a
> FreeBSD apa 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Fri Aug  3 18:08:53 
> CEST 2007   root at apa:/usr/obj/usr/src/sys/APA  i386
>
> Incidentally, I noticed that lang/gcc42 fails to build unless GNU awk 
> is installed. There is at least one awk-script used during the build 
> that produces the wrong result with the default awk. I think other 
> gcc-based ports may be affected, since I observed the same problem 
> with lang/llvm-gcc4.
>
> Cheers,
>
> /Niklas

I think that the real problem lies with our 'GNU binutils 
compatibility', because gprof was originally from the GNU binutils 
distribution. There have also been 4 major releases since the initial 
import date (at least according to the gprof(2) manpage creation date 
and ftp://sourceware.org/pub/binutils/snapshots).

So it could be possible that -pg instructions injected by gcc 4.2.x 
aren't compatible with the gprof in base, or gprof in base was 
miscompiled, because of a similar problem seen in openssl (with inlining 
/ declaring pointers to functions?).

I'm not sure who to ping about this issue though since it appears that 
many hands have touched gprof in the CVS tree. Anyone have any ideas?

Thanks,
-Garrett


More information about the freebsd-current mailing list