[Bug 269875] devel/libunwind: cherry-pick fix for 64-bit FreeBSD from upstream

From: <bugzilla-noreply_at_freebsd.org>
Date: Tue, 28 Feb 2023 14:07:51 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269875

            Bug ID: 269875
           Summary: devel/libunwind: cherry-pick fix for 64-bit FreeBSD
                    from upstream
           Product: Ports & Packages
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: Individual Port(s)
          Assignee: sunpoet@FreeBSD.org
          Reporter: mizhka@FreeBSD.org
             Flags: maintainer-feedback?(sunpoet@FreeBSD.org)
          Assignee: sunpoet@FreeBSD.org

Hi,

Shortly speaking, we've found out that actual version of libunwind returns
broken stack for PostgreSQL processes. But fix is already in upstream (not yet
released):

https://github.com/libunwind/libunwind/commit/400b3f819ad44ff4e15487b163cc3613389cb4c8

Details.

We're trying to use libunwind to get stacktrace in case of PostgreSQL crash.
Sometimes stack looks hang on wrong position like:

1 libthr.so.3 + 0x1a4b0 0x0008009ba58e 0x00007fffffffc130 _pthread_sigmask +
0x54e
2 libthr.so.3 + 0x19a00 0x0008009b9b3f 0x00007fffffffc4f0
_pthread_setschedparam + 0x82f
3 [vdso] + 0x2d0 0x7ffffffff8a3 0x00007fffffffc560 + 0xffffffff
4 libc.so.7 + 0x138570 0x00080143457a 0x00007fffffffc560 __sys_kevent + 0xa
5 libthr.so.3 + 0x19870 0x0008009b9a00 0x00007fffffffc568
_pthread_setschedparam + 0x6f0
6 <unknown> 0x000000000000 0x00007fffffffc570 + 0xffffffff
7 libthr.so.3 + 0x1ccc0 0x0008009bcd13 0x00007fffffffc578 _pthread_getspecific
+ 0x1903
8 libthr.so.3 + 0x1ccc0 0x0008009bcd13 0x56415741e5894865 _pthread_getspecific
+ 0x1903
9 libthr.so.3 + 0x1ccc0 0x0008009bcd13 0x56415741e5894865 _pthread_getspecific
+ 0x1903
10 libthr.so.3 + 0x1ccc0 0x0008009bcd13 0x56415741e5894865 _pthread_getspecific
+ 0x1903

The problem isn't reproduced on latest commit of libunwind. Git-bisect pointed
to commit: 
https://github.com/libunwind/libunwind/commit/400b3f819ad44ff4e15487b163cc3613389cb4c8

On this commit stack looks good in all test invocations:

1 libthr.so.3 + 0x1a4b0 0x0008009ba58e 0x00007fffffffc130 _pthread_sigmask +
0x54e
2 libthr.so.3 + 0x19a00 0x0008009b9b3f 0x00007fffffffc4f0
_pthread_setschedparam + 0x82f
3 [vdso] + 0x2d0 0x7ffffffff8a3 0x00007fffffffc560 + 0xffffffff
4 libc.so.7 + 0x138570 0x00080143457a 0x00007fffffffc9b8 __sys_kevent + 0xa
5 libthr.so.3 + 0x1ccc0 0x0008009bcd13 0x00007fffffffc9c0 _pthread_getspecific
+ 0x1903
6 postgres + 0x7acc00 0x0000007acd44 0x00007fffffffca10 WaitEventSetWait +
0x144
7 postgres + 0x7ac790 0x0000007ac8d6 0x00007fffffffcac0 WaitLatchOrSocket +
0x146
8 postgres + 0x746170 0x000000746284 0x00007fffffffcb20 pgstat_start + 0x1b4
9 postgres + 0x7460d0 0x000000746129 0x00007fffffffd350 pgstat_start + 0x59
10 postgres + 0x74f2e0 0x00000074f81b 0x00007fffffffd370 InitProcessGlobals +
0x129b
11 libthr.so.3 + 0x1a4b0 0x0008009ba580 0x00007fffffffd7e0 _pthread_sigmask +
0x540
12 libthr.so.3 + 0x19a00 0x0008009b9b3f 0x00007fffffffdba0
_pthread_setschedparam + 0x82f
13 [vdso] + 0x2d0 0x7ffffffff8a3 0x00007fffffffdc10 + 0xffffffff
14 libc.so.7 + 0x138730 0x00080143473a 0x00007fffffffe068 __sys_select + 0xa
15 libthr.so.3 + 0x1c9c0 0x0008009bca02 0x00007fffffffe070 _pthread_getspecific
+ 0x15f2
16 postgres + 0x7504b0 0x000000750ac4 0x00007fffffffe0b0 InitProcessGlobals +
0x2544
17 postgres + 0x74d6a0 0x00000074e371 0x00007fffffffe610 PostmasterMain + 0xcd1
18 postgres + 0x6ad8d0 0x0000006adbac 0x00007fffffffea70 main + 0x2dc
19 postgres + 0x4b4100 0x0000004b4100 0x00007fffffffeaa0 _start + 0x100
20 <unknown> 0x000800981008 0x00007fffffffeae0 + 0xffffffff

It's hard to provide simple reproducible case without compiling PostgreSQL and
extensions. 
Also worth mentioning that issue is reproduced only on 64-bit FreeBSD, neither
on Linux distributions (Debian/Ubuntu) nor on 32-bit FreeBSD.

What is best way to solve it? To cherry-pick patch to port?

I'll appreciate your help.

Thanks,
 Michael.

-- 
You are receiving this mail because:
You are the assignee for the bug.