Bug 24517 – druntime tests fail on FreeBSD 14

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
FreeBSD
Creation time
2024-04-22T13:47:30Z
Last change time
2024-04-22T15:16:43Z
Keywords
pull
Assigned to
No Owner
Creator
Jonathan M Davis

Comments

Comment #0 by issues.dlang — 2024-04-22T13:47:30Z
Running gmake unittest in dmd/druntime on FreeBSD results in a segfault: --- ../generated/freebsd/debug/64/unittest/test_runner core.internal.qsort 0x82331f618 <_D4core7runtime18runModuleUnitTestsUZ19unittestSegvHandlerUNbiPSQCk3sys5posix6signal9siginfo_tPvZv+56> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x822f5c54d <pthread_sigmask+1357> at /lib/libthr.so.3 0x822f5bafb <pthread_setschedparam+2107> at /lib/libthr.so.3 0x820f692d3 <???+0> at ??? 0x8233d53fc <_adSort+96> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x8233d56c6 <_D4core8internal5qsort18__unittest_L133_C1FZv+654> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x8233d5e41 <_D4core8internal5qsort9__modtestFZv+9> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x202d14 <???+0> at /home/jmdavis/Programming/github/dmd/generated/freebsd/debug/64/unittest/test_runner 0x202c1a <???+0> at /home/jmdavis/Programming/github/dmd/generated/freebsd/debug/64/unittest/test_runner 0x202a50 <???+0> at /home/jmdavis/Programming/github/dmd/generated/freebsd/debug/64/unittest/test_runner 0x82331f393 <runModuleUnitTests+163> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x8234c1dc2 <_D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv+38> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x8234c1d3d <_D2rt6dmain212_d_run_main2UAAamPUQgZiZ7tryExecMFMDFZvZv+49> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x8234c1ca3 <_d_run_main2+707> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x8234c19d7 <_d_run_main+267> at ../generated/freebsd/debug/64/unittest/libdruntime-ut.so 0x202f52 <???+0> at /home/jmdavis/Programming/github/dmd/generated/freebsd/debug/64/unittest/test_runner 0x821d1bafa <__libc_start1+298> at /lib/libc.so.7 0x2028d0 <???+0> at /home/jmdavis/Programming/github/dmd/generated/freebsd/debug/64/unittest/test_runner gmake[1]: *** [Makefile:489: ../generated/freebsd/debug/64/unittest/core/internal/qsort] Segmentation fault (core dumped) gmake[1]: *** Deleting file '../generated/freebsd/debug/64/unittest/core/internal/qsort' gmake[1]: Leaving directory '/home/jmdavis/Programming/github/dmd/druntime' gmake: *** [Makefile:446: unittest-debug] Error 2 --- The cause is that the signature for qsort_r was changed in FreeBSD 14 to be POSIX compliant (the old signature had some parameters in the wrong order).
Comment #1 by dlang-bot — 2024-04-22T14:06:11Z
@jmdavis created dlang/dmd pull request #16405 "Fix bugzilla issue 24517: druntime tests crash on FreeBSD 14" fixing this issue: - Fix bugzilla issue 24517: druntime tests crash on FreeBSD 14 FreeBSD 14 changed the signature of qsort_r to be POSIX-compliant with POSIX, making it so that our binding for it no longer matches, resulting in a crash when it's used. This implements a fix similar to what the FreeBSD headers do to avoid breaking code (they provide a static inline extern(C++) overload for the old signature). This provides a deprecated extern(D) overload for the old signature. The extern(C) overload now matches the new signature. The changes have been versioned so that they only affect FreeBSD 14 and newer. Technically, if someone used Cmp when declaring their function for qsort_r, this would still break them (though with a compilation error that should be easy to fix rather than silent breakage or a crash), but I don't really see a way around that, and Cmp is not part of the POSIX API, so no one would have a clue that it was a thing without digging through the bindings. Arguably, we should make it private, since it's not part of POSIX, but I haven't done anything with that in this commit. My guess is that in reality, no D programs are both written to use qsort_r and run on FreeBSD (outside of the druntime tests), but this way, they won't break unless they use Cmp to declare their comparator function. They'll just get a deprecation message that they should update their code. Regardless, we have to change the signature for FreeBSD 14 for it to work, and this does that. https://github.com/dlang/dmd/pull/16405
Comment #2 by dlang-bot — 2024-04-22T15:16:43Z
dlang/dmd pull request #16405 "Fix bugzilla issue 24517: druntime tests crash on FreeBSD 14" was merged into master: - df9a56d192579a92cffd237fb81707c65240ee46 by Jonathan M Davis: Fix bugzilla issue 24517: druntime tests crash on FreeBSD 14 FreeBSD 14 changed the signature of qsort_r to be POSIX-compliant with POSIX, making it so that our binding for it no longer matches, resulting in a crash when it's used. This implements a fix similar to what the FreeBSD headers do to avoid breaking code (they provide a static inline extern(C++) overload for the old signature). This provides a deprecated extern(D) overload for the old signature. The extern(C) overload now matches the new signature. The changes have been versioned so that they only affect FreeBSD 14 and newer. Technically, if someone used Cmp when declaring their function for qsort_r, this would still break them (though with a compilation error that should be easy to fix rather than silent breakage or a crash), but I don't really see a way around that, and Cmp is not part of the POSIX API, so no one would have a clue that it was a thing without digging through the bindings. Arguably, we should make it private, since it's not part of POSIX, but I haven't done anything with that in this commit. My guess is that in reality, no D programs are both written to use qsort_r and run on FreeBSD (outside of the druntime tests), but this way, they won't break unless they use Cmp to declare their comparator function. They'll just get a deprecation message that they should update their code. Regardless, we have to change the signature for FreeBSD 14 for it to work, and this does that. https://github.com/dlang/dmd/pull/16405