Bug 269875 - devel/libunwind: cherry-pick fix for 64-bit FreeBSD from upstream
Summary: devel/libunwind: cherry-pick fix for 64-bit FreeBSD from upstream
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Po-Chuan Hsieh
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-28 14:07 UTC by Michael Zhilin
Modified: 2023-04-20 08:05 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (sunpoet)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Zhilin freebsd_committer freebsd_triage 2023-02-28 14:07:51 UTC
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.
Comment 1 Po-Chuan Hsieh freebsd_committer freebsd_triage 2023-04-06 03:57:10 UTC
Sorry for late reply. I think it's OK to cherry-pick this commit to fix the issue before 1.7.0 release.
Comment 2 Po-Chuan Hsieh freebsd_committer freebsd_triage 2023-04-09 23:39:10 UTC
Committed. Thanks!
Comment 3 commit-hook freebsd_committer freebsd_triage 2023-04-09 23:39:48 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=42ca033358a793bf186420844535e97df3000df6

commit 42ca033358a793bf186420844535e97df3000df6
Author:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
AuthorDate: 2023-04-09 23:38:47 +0000
Commit:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
CommitDate: 2023-04-09 23:38:47 +0000

    devel/libunwind: Stop aliasing RSP and CFA

    - Bump PORTREVISION for package change

    PR:             269875
    Obtained from:  https://github.com/libunwind/libunwind/commit/400b3f819ad44ff4e15487b163cc3613389cb4c8
    Reported by:    mizhka

 devel/libunwind/Makefile                     |   2 +-
 devel/libunwind/files/patch-bug-269875 (new) | 310 +++++++++++++++++++++++++++
 2 files changed, 311 insertions(+), 1 deletion(-)
Comment 4 Michael Zhilin freebsd_committer freebsd_triage 2023-04-20 08:05:14 UTC
Many thanks! Now it works fine (at least for me)