Joined: 30 Jun 2004
Location: The Portland Group Inc.
|Posted: Tue Oct 21, 2008 1:26 pm Post subject: FAQ: "Backtrace" causes a seg fault when compiled
I wanted to share the following report sent in to PGI customer support. The user was trying to use the "backtrace" function in a static binary causing the code to seg fault. For example:
bicycle:/tmp% cat back.c
main ( int argc, char *argv  )
void *pcs [ 32 ];
setvbuf ( stdout, 0, _IONBF, 0 );
printf ( "calling backtrace\n" );
num_pcs = backtrace ( pcs, sizeof ( pcs ) / sizeof ( pcs [ 0 ] ) );
printf ( "back\n" );
bicycle:/tmp% pgcc -Bstatic back.c
Segmentation fault (core dumped)
There are two problems here. The first was the we (PGI) weren't linking the correct crtbegin.o object which included static traceback (crtbeginT.o). While this was fixed with the 7.2 release, the same code will still seg fault on systems that use GCC 3.3.3. This is a problem with crtbeginT.o itself which was fixed with later versions of GCC.
If you encounter this problem either don't statically link system files when using backtrace (i.e. link with -Bstatic_pgi which statically links the PGI libraries but not the system libraries.) or update your PGI and GCC versions.
Hope this helps,