Skip to contentSkip to conversation

xfsprogs-7.2.0: build failure on musl (undefined reference to 'mallinfo')

DISCUSSION Theron York 1 participant 2 messages Sep 19

lore
Share & tools
lore
#0 lore raw

Hi,

xfsprogs-7.2.0 fails to build on a musl-based system. The link step for xfs_scrub dies with an undefined reference to mallinfo(). This has also been reported in Gentoo as bug 982752:

  https://bugs.gentoo.org/982752

I'm reporting it here because it's a musl libc compatibility issue rather than a distribution-specific packaging bug.

System:
  - Gentoo, amd64, musl profile (x86_64-pc-linux-musl)
  - binutils 2.47, gcc (or clang) as the toolchain, both reproduce
  - xfsprogs-7.2.0 from upstream tarball (also reproduced via Gentoo ebuild)
  - musl version: 1.2.6-r1

Error (with gcc + bfd, same with clang + lld):

  ld.bfd: .../ltrans1.ltrans.o: in function `phase_end':
  <artificial>:(.text+0xdb7): undefined reference to `mallinfo'
  collect2: error: ld returned 1 exit status gmake[2]: *** [../include/buildrules:65: xfs_scrub] Error 1

The call site is scrub/xfs_scrub.c in phase_end():

  #ifdef HAVE_MALLINFO
      ...
      mallinfo();
      ...
  #endif

The build is being compiled with -DHAVE_MALLINFO on the command line, so the configure check is reporting mallinfo() as available when it is not. musl does not provide mallinfo() at all (nor mallinfo2()). Both are glibc extensions, and mallinfo() itself is deprecated in glibc since 2.33 in favor of mallinfo2().

I suspect the autoconf check in configure.ac (or the relevant m4 macro) is doing a compile-only or declaration-only test that passes on musl even though the symbol is never defined by the C library. Whatever the mechanism, HAVE_MALLINFO ends up defined and the link fails.

A minimal fix would be to make the mallinfo() check a link test, or to gate it on __GLIBC__ specifically. Something like:

  #if defined(HAVE_MALLINFO) && defined(__GLIBC__)

in scrub/xfs_scrub.c would also work as a local workaround, but the root cause is in the configure check.

I've also reproduced this with clang + lld; the error is identical apart from the linker driver. Happy to provide that log as well if useful.

I checked the list archives first but couldn't find a recent thread covering this exact failure on 7.2.0. If there's a known fix or an existing patch I've missed, a pointer would be appreciated.

Thanks,
Theron York,

#1 lore raw
Quoted 65 lines · Theron York

Hi,

xfsprogs-7.2.0 fails to build on a musl-based system. The link step for xfs_scrub dies with an undefined reference to mallinfo(). This has also been reported in Gentoo as bug 982752:

  https://bugs.gentoo.org/982752

I'm reporting it here because it's a musl libc compatibility issue rather than a distribution-specific packaging bug.

System:
  - Gentoo, amd64, musl profile (x86_64-pc-linux-musl)
  - binutils 2.47, gcc (or clang) as the toolchain, both reproduce
  - xfsprogs-7.2.0 from upstream tarball (also reproduced via Gentoo ebuild)
  - musl version: 1.2.6-r1

Error (with gcc + bfd, same with clang + lld):

  ld.bfd: .../ltrans1.ltrans.o: in function `phase_end':
  <artificial>:(.text+0xdb7): undefined reference to `mallinfo'
  collect2: error: ld returned 1 exit status gmake[2]: *** [../include/buildrules:65: xfs_scrub] Error 1

The call site is scrub/xfs_scrub.c in phase_end():

  #ifdef HAVE_MALLINFO
      ...
      mallinfo();
      ...
  #endif

The build is being compiled with -DHAVE_MALLINFO on the command line, so the configure check is reporting mallinfo() as available when it is not. musl does not provide mallinfo() at all (nor mallinfo2()). Both are glibc extensions, and mallinfo() itself is deprecated in glibc since 2.33 in favor of mallinfo2().

I suspect the autoconf check in configure.ac (or the relevant m4 macro) is doing a compile-only or declaration-only test that passes on musl even though the symbol is never defined by the C library. Whatever the mechanism, HAVE_MALLINFO ends up defined and the link fails.

A minimal fix would be to make the mallinfo() check a link test, or to gate it on __GLIBC__ specifically. Something like:

  #if defined(HAVE_MALLINFO) && defined(__GLIBC__)

in scrub/xfs_scrub.c would also work as a local workaround, but the root cause is in the configure check.

I've also reproduced this with clang + lld; the error is identical apart from the linker driver. Happy to provide that log as well if useful.

I checked the list archives first but couldn't find a recent thread covering this exact failure on 7.2.0. If there's a known fix or an existing patch I've missed, a pointer would be appreciated.

Thanks,
Theron York,

after further review it’s expected behavior. Sorry for the noise; this can be closed,