NetBSD-Users archive

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

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



Hello.

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
$ gdb -c prog.core prog Reading symbols from prog... [New process 1]
    Core was generated by `prog'.
    Program terminated with signal SIGSEGV, Segmentation fault.
    #0  0x0000000000433e10 in dl_iterate_phdr ()
    (gdb) bt
    #0  0x0000000000433e10 in dl_iterate_phdr ()
    #1  0x0000000000409e05 in __libc_static_tls_setup ()
    #2  0x0000000000494487 in _libc_init ()
    #3  0x00007a7198a41d14 in ?? () from /usr/lib/libc.so.12
    #4  0x00007a7199802240 in ?? ()
    #5  0x00007a7198a3cdf9 in _init () from /usr/lib/libc.so.12
    #6  0x0000000000000000 in ?? ()

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.

    $ uname -a
    NetBSD xyza 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
$ gcc -v 2>&1 | grep '^gcc version'
    gcc version 7.4.0 (nb3 20190319)

Any help?

Thanks.


Home | Main Index | Thread Index | Old Index