NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Program segfaults if compiled with -pg and linked to shared library



On Sun, 28 Feb 2021, Silas wrote:

Given this program:

   #include <stdio.h>
   int main(int argc, char *argv[]) {
   	printf("Hello world\n");
   	return 0;
   }

I'm trying to profile it:

   $ gcc -g -pg -Wl,-R/usr/lib -L/usr/lib -lcurses -o prog prog.c
ld: /usr/lib/libc.so.12: warning: warning: __findenv is an internal obsolete function.
       $ ./prog
   zsh: segmentation fault (core dumped)  ./prog
...
As you can see, it segfaults. I added -g flag only to get some information into
the core dump, but it still segfaults without the -g flag.

It happens only if I try to link external libraries.


On FreeBSD-12.2 and OpenBSD-6.8 (both having Clang 10.0.1 as the native
compiler), the program segfaults even when not linked with any external
shared libs.

It looks like profiling on the *BSDs needs static binaries (the
profile libraries, /usr/lib/*_p.a, are all static anyway).

-RVP


Home | Main Index | Thread Index | Old Index