In sg3_utils-1.46, code was added that utilized the reentrant versions of the mrand48 and srand48 functions (mrand48_r and srand48_r, respectively; see man page drand_r(3)), as well as struct drand48_data. These three elements are not implemented in current musl libc, and not likely to be supported, since it looks like these functions are not defined by POSIX. The last version of sg3_utils that I compiled under musl libc was 1.45. The one lead I have on a patch is for a different package, mtproxy, that had a similar compilation failure under musl libc. Its solution was to locally implement the missing functions by copying code from glibc: https://github.com/alexdoesh/mtproxy/blob/master/patches/randr_compat.patch
Created attachment 733312 [details, diff] convert to non-reentrant drand48(3) functions for portability I took a look at where in sg3_utils' code the reentrant functions were being used. It's just a single file, src/sg_dd.c, and it contains a single invocation of srand48_r() followed ~300 lines later by mrand48_r(). Converting these to their non-reentrant functions is trivial, so I opted to go that route. This allows the source to compile, and a simple test of sg_dd to copy 20M from /dev/urandom to a file works without issue under a MIPS musl chroot.
Created attachment 733315 [details, diff] ebuild patch Quick patch to the ebuild to bump it to EAPI 8 (note, I quoted the EAPI value, since PMS notes it's not always an integer) and apply the previous patch to convert to the non-reentrant versions of the drand48(3) family of functions in src/sg_dd.c.
Swapping bug ownership to base-system for review. The proposed changes are not specific to musl and should work under other POSIX-compliant libc's as well. I'll pass the patch on to the author as well. Doesn't seem like there's a public bug tracker for this package.
Created attachment 733324 [details, diff] convert to non-reentrant drand48(3) functions for portability Missed some cases in the testing/ subdirectory and also tweaked the sg_dd manpage.
Let's wait a bit to see if the patch is accepted by the author. Say, 2 weeks? If the author accepts the patch or there's no response, please go ahead and add it to the gentoo repo.
(In reply to Mike Gilbert from comment #5) > Let's wait a bit to see if the patch is accepted by the author. Say, 2 > weeks? > > If the author accepts the patch or there's no response, please go ahead and > add it to the gentoo repo. Sure, there's no rush on my end. I will resurrect the older 1.45 release in a local repo for my musl environment, since that was the last legit version I built for MIPS netboots last year.
(In reply to Mike Gilbert from comment #5) > Let's wait a bit to see if the patch is accepted by the author. Say, 2 > weeks? > > If the author accepts the patch or there's no response, please go ahead and > add it to the gentoo repo. Looks like we're good, the author replied: """ Hi, Thanks for finding, analyzing and providing a patch for this problem. Not often someone goes to the extra effort of finding all occurrences, including in the manpage. I have applied that patch and it is in revision 909 (of my beta sg3_utils-1.47). My primary sg3_utils subversion repository is mirrored at: https://github.com/doug-gilbert/sg3_utils thanks to the git-svn tools. """ If there are no additional issues, I'll commit this change later tonight.
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=38cd2e8f37c164f42abaf9de696610d9053d27c1 commit 38cd2e8f37c164f42abaf9de696610d9053d27c1 Author: Joshua Kinard <kumba@gentoo.org> AuthorDate: 2021-08-17 03:57:24 +0000 Commit: Joshua Kinard <kumba@gentoo.org> CommitDate: 2021-08-17 03:58:34 +0000 sys-apps/sg3_utils: Fix a compile issue under musl libc Fix a compile issue under musl libc where the sg_dd utility internally uses the reentrant functions srand48_r(3) and mrand48_r(3), which are glibc-specific extensions. Changed to using the portable non-reentrant versions, and sent a patch upstream, which was acknowledged by the author for the next release. Closes: https://bugs.gentoo.org/808600 Signed-off-by: Joshua Kinard <kumba@gentoo.org> Package-Manager: Portage-3.0.20, Repoman-3.0.3 .../files/sg3_utils-1.46-musl-drand48-compat.patch | 99 ++++++++++++++++++++++ sys-apps/sg3_utils/sg3_utils-1.46-r1.ebuild | 7 +- 2 files changed, 105 insertions(+), 1 deletion(-)
Great work, thank you!