NetBSD-Bugs archive

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

bin/56031: binary compiled with -pg (profiling) segfaults if linked against shared library



>Number:         56031
>Category:       bin
>Synopsis:       binary compiled with -pg (profiling) segfaults if linked against shared library
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 03 01:40:00 +0000 2021
>Originator:     silas_netbsd_gnats%nocafe.net@localhost
>Release:        NetBSD 9.0
>Organization:
>Environment:
System: NetBSD xyz 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
Architecture: x86_64
Machine: amd64
>Description:
When compiling a binary file with gcc's -pg flag and a shared library, the
binary segfaults.

See this simple example:

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

$ cc -pg -o test test.c
./test
hello world

$ cc -pg -lcurses -o test test.c
ld: /usr/lib/libc.so.12: warning: warning: __findenv is an internal obsolete function.

$ ./test
[1]   Segmentation fault (core dumped) ./test

Later, I decided to add the -g flag to get debug symbols and see if I'd get something useful from gdb:

$ cc -g -pg -lcurses -o test test.c
ld: /usr/lib/libc.so.12: warning: warning: __findenv is an internal obsolete function.

$ ./test
[1]   Segmentation fault (core dumped) ./test

$ gdb -c test.core -ex bt -ex q test
GNU gdb (GDB) 8.3
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64--netbsd".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...
[New process 1]
Core was generated by `test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000000000433e10 in dl_iterate_phdr ()
#0  0x0000000000433e10 in dl_iterate_phdr ()
#1  0x0000000000409e05 in __libc_static_tls_setup ()
#2  0x0000000000494487 in _libc_init ()
#3  0x00006fb919441d14 in ?? () from /usr/lib/libc.so.12
#4  0x00006fb91a0e0200 in ?? ()
#5  0x00006fb91943cdf9 in _init () from /usr/lib/libc.so.12
#6  0x0000000000000000 in ?? ()

Curious fact: I can profile (generate binary, run the program and use gprof) the
same program normally in NetBSD 8.0 armv7hf (Raspberry Pi 2).

For reference, I started a thread about this in netbsd-users@: http://mail-index.netbsd.org/netbsd-users/2021/02/28/msg026655.html
>How-To-Repeat:
$ cat test.c
#include <stdio.h>
int main(int argc, char *argv[]) {
	printf("hello world\n");
	return 0;
}

$ cc -pg -lcurses -o test test.c
ld: /usr/lib/libc.so.12: warning: warning: __findenv is an internal obsolete function.

$ ./test
[1]   Segmentation fault (core dumped) ./test
>Fix:



Home | Main Index | Thread Index | Old Index