Bug 266227 - [exp-run] Request for exp-run with qsort_r API change
Summary: [exp-run] Request for exp-run with qsort_r API change
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: Xin LI
URL:
Keywords:
Depends on: 266574
Blocks:
  Show dependency treegraph
 
Reported: 2022-09-05 06:19 UTC by Xin LI
Modified: 2022-10-01 10:46 UTC (History)
10 users (show)

See Also:
delphij: exp-run?


Attachments
Patch to modify qsort_r API to use GNU (POSIX) interface (19.08 KB, patch)
2022-09-05 06:19 UTC, Xin LI
no flags Details | Diff
Patch to modify qsort_r API to use GNU (POSIX) interface (18.80 KB, patch)
2022-09-06 03:42 UTC, Xin LI
no flags Details | Diff
Patch to modify qsort_r API to use GNU (POSIX) interface (19.08 KB, patch)
2022-09-06 06:15 UTC, Xin LI
no flags Details | Diff
Patch for textproc/raptor2 (2.72 KB, patch)
2022-09-06 07:48 UTC, Xin LI
no flags Details | Diff
Proposed patch for ruby (6.36 KB, patch)
2022-09-08 07:07 UTC, Xin LI
no flags Details | Diff
Proposed patch for graphics/mesa-dri (3.28 KB, patch)
2022-09-10 08:34 UTC, Xin LI
no flags Details | Diff
Proposed patch for sysutils/e2fsprogs (2.07 KB, patch)
2022-09-10 21:06 UTC, Xin LI
delphij: maintainer-approval? (mandree)
Details | Diff
Patch to modify qsort_r API to use GNU (POSIX) interface (22.75 KB, patch)
2022-09-12 02:02 UTC, Xin LI
no flags Details | Diff
Proposed patch for graphics/mesa-devel (3.07 KB, patch)
2022-09-17 04:50 UTC, Xin LI
no flags Details | Diff
Proposed patch for misc/far2l (2.51 KB, patch)
2022-09-17 17:54 UTC, Xin LI
no flags Details | Diff
Proposed patch for security/hashcat (2.15 KB, patch)
2022-09-17 19:36 UTC, Xin LI
delphij: maintainer-approval? (se)
Details | Diff
Proposed patch for databases/iowow (1.85 KB, patch)
2022-09-17 20:25 UTC, Xin LI
delphij: maintainer-approval? (danfe)
Details | Diff
Proposed patch for databases/pointcloud (1.96 KB, patch)
2022-09-18 04:07 UTC, Xin LI
delphij: maintainer-approval? (lbartoletti)
Details | Diff
Patch (v3) to modify qsort_r API to use GNU (POSIX) interface (23.05 KB, patch)
2022-09-18 23:08 UTC, Xin LI
no flags Details | Diff
Patch (v4) to modify qsort_r API to use GNU (POSIX) interface (23.08 KB, patch)
2022-09-22 08:52 UTC, Xin LI
no flags Details | Diff
Proposed patch for databases/ejdb (2.17 KB, patch)
2022-09-23 07:22 UTC, Xin LI
delphij: maintainer-approval? (danfe)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xin LI freebsd_committer freebsd_triage 2022-09-05 06:19:13 UTC
Created attachment 236360 [details]
Patch to modify qsort_r API to use GNU (POSIX) interface

I'd like to request for an exp-run with qsort_r API change, this is basically https://reviews.freebsd.org/D17083 .

Despite being fully aware [1] of FreeBSD's qsort_r(3) implementation and refused it initially, glibc maintainers decided to implement an different API under the same name to lock in developers [2] and Austin Group decided to adopt their API [3].

The proposed patch will change FreeBSD's qsort_r(3) and kernel qsort_3(9) to use the new standard qsort_r API, making it easier for porting Linux applications to FreeBSD.

Backward compatibility is preserved with versioned symbol.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=173
[2] https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=e458144c99ddc00769ffa6bd367c21d37e879d83
[3] https://www.austingroupbugs.net/view.php?id=900
Comment 1 Xin LI freebsd_committer freebsd_triage 2022-09-06 03:42:03 UTC
Created attachment 236386 [details]
Patch to modify qsort_r API to use GNU (POSIX) interface

Revised version of patch; it should be functionality-identical and only touches qsort_b, which should be relatively rare.
Comment 2 Xin LI freebsd_committer freebsd_triage 2022-09-06 06:15:16 UTC
Created attachment 236388 [details]
Patch to modify qsort_r API to use GNU (POSIX) interface

Apparently I got confused today.  The old patch was just fine.
Comment 3 Antoine Brodin freebsd_committer freebsd_triage 2022-09-06 06:27:12 UTC
FYI there was a similar exp-run requested a few years ago,  in bug #231256
Comment 4 Xin LI freebsd_committer freebsd_triage 2022-09-06 07:47:18 UTC
(In reply to Antoine Brodin from comment #3)
Hi, thanks for the pointer.  Since it has been a few years, can we request a new one so we get an idea on how good (or bad) the current ports tree would react with the change?
Comment 5 Xin LI freebsd_committer freebsd_triage 2022-09-06 07:48:16 UTC
Created attachment 236389 [details]
Patch for textproc/raptor2

Patch from bug 231256 for textproc/raptor2
Comment 6 Antoine Brodin freebsd_committer freebsd_triage 2022-09-06 07:54:08 UTC
(In reply to Xin LI from comment #4)
Yes I will do it
Comment 7 Antoine Brodin freebsd_committer freebsd_triage 2022-09-07 20:55:24 UTC
Some failure logs:

http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/cyrus-imapd34-http-3.4.4.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/e2fsprogs-1.46.5_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/e2fsprogs-nobootfsck-1.46.5_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/e2fsprogs-roothardlinks-1.46.5_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/firebird30-client-3.0.7_2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/hashcat-6.2.6,1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/iowow-1.4.14.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/libsolv-0.7.22.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/lsp-plugins-lv2-1.2.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/mesa-devel-22.2.b.1696.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/mesa-libs-21.3.8.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/mlmmj-webview-0.0.6.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/nlopt-2.7.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/pointcloud-1.2.2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/py39-nlopt-2.7.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/ruby-3.0.4_2,1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/ruby27-2.7.6_2,1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/ruby31-3.1.2_1,1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/ruby32-3.2.0.p1_2,1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/singular-4.3.1_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/synthpod-lv2-g20190407_2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/timbre-mill-0.5.6.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-06_09h13m56s/logs/errors/tvheadend-4.2.8_6.log

With ruby and mesa-libs failing, around 5k ports were newly skipped
Comment 8 Xin LI freebsd_committer freebsd_triage 2022-09-08 07:07:23 UTC
Created attachment 236429 [details]
Proposed patch for ruby

Review at: https://reviews.freebsd.org/D36492;
Upstream pull request at: https://github.com/ruby/ruby/pull/6332
Comment 9 Antoine Brodin freebsd_committer freebsd_triage 2022-09-09 06:45:13 UTC
Some failures logs:

http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/cyrus-imapd34-http-3.4.4.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/e2fsprogs-1.46.5_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/e2fsprogs-nobootfsck-1.46.5_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/e2fsprogs-roothardlinks-1.46.5_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/far2l-2.4.0_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/firebird30-client-3.0.7_2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/hashcat-6.2.6,1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/iowow-1.4.14.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/libsolv-0.7.22.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/lsp-plugins-lv2-1.2.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/mesa-devel-22.2.b.1826.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/mesa-libs-21.3.8.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/mlmmj-webview-0.0.6.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/nlopt-2.7.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/pointcloud-1.2.2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/py39-nlopt-2.7.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/singular-4.3.1_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/synthpod-lv2-g20190407_2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/timbre-mill-0.5.6.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-08_07h33m46s/logs/errors/tvheadend-4.2.8_6.log

Around 2300 ports were newly skipped due to failures,  graphics/mesa-libs causing more than 2200 of them
Comment 10 Xin LI freebsd_committer freebsd_triage 2022-09-09 06:57:18 UTC
(In reply to Antoine Brodin from comment #9)
Thanks, I'll take a look at graphics/mesa-libs (I _think_ I have a fix for that, but poudriere decides that the clang 14.0 bundled with base is not sufficient and went ahead to build llvm13 from port, so it would take a little bit more time)...
Comment 11 commit-hook freebsd_committer freebsd_triage 2022-09-10 06:32:15 UTC
A commit in branch main references this bug:

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

commit b4b8c98857e409dd294fd58680cd05ae71893261
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-10 06:31:50 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-10 06:31:51 +0000

    lang/ruby{27,30,31,32}: Improve qsort_r() detection.

    This change merges the following upstream pull request into the Ruby
    interpreter:

            https://github.com/ruby/ruby/pull/6332

    Adding this patch is no-op right now because we are not using POSIX (GNU)
    qsort_r(3) interface yet. It will fix build when the change is applied.

    Reviewed by:    bapt (portmgr@), sunpoet (ruby@)
    PR:             ports/266227
    MFH:            2022Q3
    Differential Revision: https://reviews.freebsd.org/D36492

 lang/ruby27/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 lang/ruby30/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 lang/ruby31/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 lang/ruby32/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 4 files changed, 116 insertions(+)
Comment 12 commit-hook freebsd_committer freebsd_triage 2022-09-10 06:33:16 UTC
A commit in branch 2022Q3 references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1785b9ca4f4e2092bd8b485f94196e1d66eadcf8

commit 1785b9ca4f4e2092bd8b485f94196e1d66eadcf8
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-10 06:31:50 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-10 06:32:54 +0000

    lang/ruby{27,30,31,32}: Improve qsort_r() detection.

    This change merges the following upstream pull request into the Ruby
    interpreter:

            https://github.com/ruby/ruby/pull/6332

    Adding this patch is no-op right now because we are not using POSIX (GNU)
    qsort_r(3) interface yet. It will fix build when the change is applied.

    Reviewed by:    bapt (portmgr@), sunpoet (ruby@)
    PR:             ports/266227
    MFH:            2022Q3
    Differential Revision: https://reviews.freebsd.org/D36492

    (cherry picked from commit b4b8c98857e409dd294fd58680cd05ae71893261)

 lang/ruby27/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 lang/ruby30/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 lang/ruby31/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 lang/ruby32/files/patch-util.c (new) | 29 +++++++++++++++++++++++++++++
 4 files changed, 116 insertions(+)
Comment 13 Xin LI freebsd_committer freebsd_triage 2022-09-10 08:34:43 UTC
Created attachment 236470 [details]
Proposed patch for graphics/mesa-dri

Add a proposed patch for graphics/mesa-dri; submitted an upstream merge request at https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18527 which is slightly different due to branch divergence.
Comment 14 Xin LI freebsd_committer freebsd_triage 2022-09-10 21:06:00 UTC
Created attachment 236483 [details]
Proposed patch for sysutils/e2fsprogs
Comment 15 Xin LI freebsd_committer freebsd_triage 2022-09-12 02:02:25 UTC
Created attachment 236507 [details]
Patch to modify qsort_r API to use GNU (POSIX) interface

I've revised the patch a little bit (main change was for stdlib.h by changing the behavior from breaking applications that called FreeBSD style comparator to just route the call to the compatibility symbol as if the code was compiled for an earlier FreeBSD release; the rest was test cases added to validate the compatibility symbol was doing the right thing). This will fix some of ports broken by the change.
Comment 16 Antoine Brodin freebsd_committer freebsd_triage 2022-09-13 09:25:06 UTC
New failure logs with the previous src patch:

http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/cyrus-imapd34-http-3.4.4.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/far2l-2.4.0_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/firebird30-client-3.0.7_2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/hashcat-6.2.6,1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/iowow-1.4.14.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/libsolv-0.7.22.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/lsp-plugins-lv2-1.2.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/mesa-devel-22.2.b.1915.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/mlmmj-webview-0.0.6.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/nlopt-2.7.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/orange3-3.29.1_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/pointcloud-1.2.2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/py39-nlopt-2.7.1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/singular-4.3.1_1.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/stellarsolver-2.3.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/synthpod-lv2-g20190407_2.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/timbre-mill-0.5.6.log
http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/tvheadend-4.2.8_6.log

math/nlopt caused 26 skipped
Comment 17 Xin LI freebsd_committer freebsd_triage 2022-09-13 16:49:22 UTC
(In reply to Antoine Brodin from comment #16)
By "previous" did you mean the earlier version (2022-09-06 06:15 UTC), or the latest version (2022-09-12 02:02 UTC)?  For example:

http://gohan05.nyi.freebsd.org/data/mainamd64PR266227-default/2022-09-12_17h35m40s/logs/errors/mlmmj-webview-0.0.6.log

Gave me:

===>  Building for mlmmj-webview-0.0.6
cc -Wall -Wextra -std=gnu99 -D_GNU_SOURCE=1 -MT mlmmj-webview.o -MD -MP -MF mlmmj-webview.Tpo -o mlmmj-webview.o -c -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing  -I/usr/local/include  -I/usr/local/include  -Werror=implicit-function-declaration -Werror=return-type -I/wrkdirs/usr/ports/mail/mlmmj-webview/work/mlmmj-webview mlmmj-webview.c
mlmmj-webview.c:251:3: error: called object type 'int' is not a function or function pointer
                qsort_r(names, numitems, sizeof(struct dirent *),
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:345:48: note: expanded from macro 'qsort_r'
        __calling_qsort_r_incorrectly, qsort_r)(base, nel, width, compar, arg)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

which appears to be building against the older patch, and should be gone with the latest version of patch.

(mesa-devel was similar to mesa-dri which I'll create a patch).
Comment 18 Antoine Brodin freebsd_committer freebsd_triage 2022-09-13 17:06:32 UTC
(In reply to Xin LI from comment #17)
By previous patch,  I meant the one from comment #2
Comment 19 Matthias Andree freebsd_committer freebsd_triage 2022-09-13 20:24:30 UTC
(In reply to Xin LI from comment #14)
e2fsprogs - I am scratching my head over this, especially over the detection and the "defined qsort_r" part gives me the creeps. It nicely shows the distress to tell one qsort_r interface from another.

Besides that, the qsort_r standardization attempt is ill-advised. C11 already has qsort_s (but it apparently has not made it into POSIX 2018) and I wonder where GNU libc's implementation is... Fedora 36 apparently does not carry one, and rather than standardizing on an implementation that is behind, they bless qsort_r()? Wow. 

Do we really need to jump the gun? What are our FreeBSD 14 and the POSIX schedules, will we have all the other things in place when we flip the switch for qsort_r to use the GNU API?

I am undecided. Please help me decide, and either propose a better auto-detection (ideally one I can forward upstream) or otherwise convince me we are not shooting our feet here.
Comment 20 Xin LI freebsd_committer freebsd_triage 2022-09-13 21:45:59 UTC
(In reply to Matthias Andree from comment #19)
> e2fsprogs - I am scratching my head over this, especially over the detection 
> and the "defined qsort_r" part gives me the creeps. It nicely shows the 
> distress to tell one qsort_r interface from another.

I agree.  This is meant to be a stop-gap solution: once the change of qsort_r landed, we will have a new __FreeBSD_version which can be used for the detection.

Another potentially better solution would be to have the configure script to:

1. Detect if there is a qsort_r, and
2. When it does, have two C programs with "#include <stdlib.h>" followed by BSD and GNU definition signatures, and compile; if the compilation succeeded, the corresponding variant was used and define HAVE_{GNU,BSD}_QSORT_R accordingly.

And change the code to use the HAVE_{GNU,BSD}_QSORT_R definition.

> Besides that, the qsort_r standardization attempt is ill-advised. C11 already
> has qsort_s (but it apparently has not made it into POSIX 2018) and I wonder
> where GNU libc's implementation is... Fedora 36 apparently does not carry one,
> and rather than standardizing on an implementation that is behind, they bless
> qsort_r()? Wow. 

Well, the crazy part of qsort_s is that the Microsoft version (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/qsort-s?view=msvc-170) is also slightly, but incompatibly different from C11 qsort_s.  We have adopted the C11 signature.

> Do we really need to jump the gun? What are our FreeBSD 14 and the POSIX
> schedules, will we have all the other things in place when we flip the switch
> for qsort_r to use the GNU API?

I think yes.

It's clear that the GNU API have been adopted by more software nowadays.  The problem was created by glibc maintainers, yes, and I don't like their API either, but making software developer's life easier on FreeBSD would benefit us more in long term.
Comment 22 Xin LI freebsd_committer freebsd_triage 2022-09-17 04:50:44 UTC
Created attachment 236621 [details]
Proposed patch for graphics/mesa-devel
Comment 23 Jan Beich freebsd_committer freebsd_triage 2022-09-17 11:09:59 UTC
Comment on attachment 236621 [details]
Proposed patch for graphics/mesa-devel

> graphics/mesa-devel: Improve qsort_r detection.

Commit message are supposed to answer "why?", so this should be "graphics/mesa-devel: unbreak on -CURRENT after <hash or reason>".

> This change is upstreamed as https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18527
> but not yet merged.

Move MR link into patch header and paste error excerpt into the commit message body. Alternatively, leverage PATCHFILES like other upstreamed changes.
Comment 24 commit-hook freebsd_committer freebsd_triage 2022-09-17 11:10:28 UTC
A commit in branch main references this bug:

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

commit b3fbc0c3d48c5e1cc7ac2e87e3ee1f847120bfab
Author:     Jan Beich <jbeich@FreeBSD.org>
AuthorDate: 2022-09-17 07:47:03 +0000
Commit:     Jan Beich <jbeich@FreeBSD.org>
CommitDate: 2022-09-17 11:09:03 +0000

    graphics/mesa-devel: unbreak on -CURRENT after GNU qsort_r

    In file included from ../src/util/u_qsort.cpp:24:
    ../src/util/u_qsort.h:68:4: error: no matching function for call to 'qsort_r'
       qsort_r(base, nmemb, size, &data, util_qsort_adapter);
       ^~~~~~~
    /usr/include/stdlib.h:314:7: note: candidate function not viable: no known conversion from 'struct util_qsort_adapter_data *' to 'int (*)(const void *, const void *, void *)' for 4th argument
    void     qsort_r(void *, size_t, size_t,
             ^

    PR:             266227
    Reported by:    antoine (via exp-run)
    Submitted by:   delphij

 graphics/mesa-devel/Makefile | 1 +
 graphics/mesa-devel/distinfo | 2 ++
 2 files changed, 3 insertions(+)
Comment 25 Xin LI freebsd_committer freebsd_triage 2022-09-17 17:54:39 UTC
Created attachment 236638 [details]
Proposed patch for misc/far2l
Comment 26 Xin LI freebsd_committer freebsd_triage 2022-09-17 19:08:24 UTC
databases/firebird30-client: the port doesn't build on 13-amd64, and the code doesn't appear to be using qsort_r anywhere, so I think it's unrelated.
Comment 27 Xin LI freebsd_committer freebsd_triage 2022-09-17 19:36:49 UTC
Created attachment 236643 [details]
Proposed patch for security/hashcat
Comment 28 Xin LI freebsd_committer freebsd_triage 2022-09-17 20:25:50 UTC
Created attachment 236644 [details]
Proposed patch for databases/iowow
Comment 29 Xin LI freebsd_committer freebsd_triage 2022-09-18 04:07:24 UTC
Created attachment 236652 [details]
Proposed patch for databases/pointcloud
Comment 30 Xin LI freebsd_committer freebsd_triage 2022-09-18 23:08:34 UTC
Created attachment 236678 [details]
Patch (v3) to modify qsort_r API to use GNU (POSIX) interface

Hi, could you please do another exp-run with this patch?  It would add a compatibility shim for C++ code (similar to the _Generic for C code) which should more legacy code work without modification.
Comment 32 Xin LI freebsd_committer freebsd_triage 2022-09-22 08:52:45 UTC
Created attachment 236744 [details]
Patch (v4) to modify qsort_r API to use GNU (POSIX) interface

Looks like GCC really wanted us to explicitly say extern "C++".  I have done some local builds on the new breakages (some of these are due to sort_r library, which I'll fix separately on my Friday or weekend) as well as using C++ test program to verify that the linker would use the correct symbol for LLVM and GCC.

Could you please start another exp-run with this patch?  Thanks in advance!
Comment 33 Xin LI freebsd_committer freebsd_triage 2022-09-23 07:22:30 UTC
Created attachment 236760 [details]
Proposed patch for databases/ejdb
Comment 34 commit-hook freebsd_committer freebsd_triage 2022-09-25 05:40:04 UTC
A commit in branch main references this bug:

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

commit dca15813a52d4a44c7a76ad28a7c1b75a1392334
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-25 05:39:15 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-25 05:39:16 +0000

    astro/stellarsolver: Upgrade to 2.4 and fix build on -CURRENT with GNU qsort_r.

    PR:             ports/266227, ports/266574
    Reported by:    antoine (via exp-run)
    Approved by:    maintainer (acm@)

 astro/stellarsolver/Makefile                       |  2 +-
 astro/stellarsolver/distinfo                       |  6 +-
 .../stellarsolver/files/patch-CMakeLists.txt (new) | 49 ++++++++++++++
 ...ch-stellarsolver_astrometry_os-features.h (new) | 11 ++++
 ...solver_astrometry_util_os-features-test.c (new) | 75 ++++++++++++++++++++++
 .../files/patch-stellarsolver_stellarsolver.cpp    |  4 +-
 astro/stellarsolver/pkg-plist                      |  9 +--
 7 files changed, 142 insertions(+), 14 deletions(-)
Comment 35 Antoine Brodin freebsd_committer freebsd_triage 2022-09-25 06:59:42 UTC
With src patch v4 + ports patches,  the only new failure on amd64 was astro/stellarsolver
Comment 36 Xin LI freebsd_committer freebsd_triage 2022-09-25 22:34:43 UTC
(In reply to Antoine Brodin from comment #35)
Thank you!
Comment 37 Xin LI freebsd_committer freebsd_triage 2022-09-26 07:54:28 UTC
Do I have portmgr@ approval to commit the ports patches if I haven't heard objections from maintainers by September 30th?
Comment 38 Baptiste Daroussin freebsd_committer freebsd_triage 2022-09-26 08:24:30 UTC
This is covered by design, you do not need an explicit approval, but count this as an explicit approval anyway ;)
Comment 39 Xin LI freebsd_committer freebsd_triage 2022-09-30 20:33:23 UTC
Comment on attachment 236638 [details]
Proposed patch for misc/far2l

No longer required with the last round of header change; code would behave sub-optimally due to their "adapter".
Comment 40 commit-hook freebsd_committer freebsd_triage 2022-09-30 22:30:27 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=638b276a416a4a744d51553ec986729ab035e711

commit 638b276a416a4a744d51553ec986729ab035e711
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-30 20:42:53 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-30 22:28:05 +0000

    databases/pointcloud: unbreak on -CURRENT after GNU qsort_r

    PR:             ports/266227
    Exp-run by:     antoine
    Approved by:    portmgr

 .../files/patch-lib_sort__r_sort__r.h (new)        | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Comment 41 commit-hook freebsd_committer freebsd_triage 2022-09-30 22:30:28 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=764565249f6d4df63e65373b696037b9a43ef14e

commit 764565249f6d4df63e65373b696037b9a43ef14e
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-30 20:40:29 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-30 22:28:04 +0000

    databases/iowow: unbreak on -CURRENT after GNU qsort_r

    PR:             ports/266227
    Exp-run by:     antoine
    Approved by:    portmgr

 .../iowow/files/patch-src_utils_sort__r.h (new)    | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
Comment 42 commit-hook freebsd_committer freebsd_triage 2022-09-30 22:30:30 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=82665ce295c0cdd2494bf09356d169ef28442a0a

commit 82665ce295c0cdd2494bf09356d169ef28442a0a
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-30 17:02:48 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-30 22:28:03 +0000

    sysutils/e2fsprogs: Fix qsort_r detection for POSIX qsort_r(3).

    PR:             ports/266227
    Exp-run by:     antoine
    Approved by:    portmgr

 sysutils/e2fsprogs/Makefile                         |  2 +-
 .../files/patch-lib_support_sort__r.h (new)         | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
Comment 43 commit-hook freebsd_committer freebsd_triage 2022-09-30 22:30:31 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7df902171f69003e364e23feefc7d15e4aa97ed4

commit 7df902171f69003e364e23feefc7d15e4aa97ed4
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-30 20:45:51 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-30 22:28:06 +0000

    databases/ejdb: unbreak on -CURRENT after GNU qsort_r

    PR:             266227
    Exp-run by:     antoine
    Approved by:    portmgr

 .../ejdb/files/patch-src_util_sort__r.h (new)      | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Comment 44 commit-hook freebsd_committer freebsd_triage 2022-09-30 22:30:32 UTC
A commit in branch main references this bug:

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

commit a7c48b30a0ac7dac2ecf8d4dc3acdf5c5c02c452
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2022-09-30 20:34:40 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2022-09-30 22:28:04 +0000

    security/hashcat: unbreak on -CURRENT after GNU qsort_r

    PR:             ports/266227
    Exp-run by:     antoine
    Approved by:    portmgr

 .../hashcat/files/patch-include_sort__r.h (new)    | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
Comment 45 commit-hook freebsd_committer freebsd_triage 2022-10-01 07:13:40 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=525e857368c8c2de355ca00b0c35008be6ee8a3c

commit 525e857368c8c2de355ca00b0c35008be6ee8a3c
Author:     Matthias Andree <mandree@FreeBSD.org>
AuthorDate: 2022-10-01 07:10:08 +0000
Commit:     Matthias Andree <mandree@FreeBSD.org>
CommitDate: 2022-10-01 07:13:09 +0000

    sysutils/e2fsprogs: revert bogus qsort_r() patch.

    delphij@ and the upstream maintainer were working on a autoconf-based
    solution, and this patch was not approved.  Remove it and mark
    port BROKEN on systems that changed qsort_r() for the GNU-like API.

    PR:             266227

 sysutils/e2fsprogs/Makefile                         |  6 +++++-
 .../files/patch-lib_support_sort__r.h (gone)        | 21 ---------------------
 2 files changed, 5 insertions(+), 22 deletions(-)
Comment 46 commit-hook freebsd_committer freebsd_triage 2022-10-01 10:46:07 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=5db803a6f26956fb47a211c29e34a0e5ccd82286

commit 5db803a6f26956fb47a211c29e34a0e5ccd82286
Author:     Matthias Andree <mandree@FreeBSD.org>
AuthorDate: 2022-10-01 10:40:13 +0000
Commit:     Matthias Andree <mandree@FreeBSD.org>
CommitDate: 2022-10-01 10:45:34 +0000

    sysutils/e2fsprogs: misc/e2fsprogs-libblkid: fixes

    - for libblkid, fix a buffer size when parsing device names
      to make room for a trailing '\0' character from sscanf().
      (This was a long-standing bug in our local patch.)

    - patch out qsort_r redeclarations from the sort_r library that are
      incompatible with FreeBSD since it aligned with GNU qsort_r() API

    - remove FreeBSD 14-CURRENT BROKEN= tag.

    Related to:
    PR:             266227

 misc/e2fsprogs-libblkid/Makefile                   |  2 +-
 sysutils/e2fsprogs/Makefile                        |  6 +-----
 sysutils/e2fsprogs/files/patch-lib_blkid_devname.c |  4 ++--
 .../files/patch-lib_support_sort__r.h (new)        | 24 ++++++++++++++++++++++
 4 files changed, 28 insertions(+), 8 deletions(-)