Florian Weimer wrote: > lib/xmalloc.c contains this function definition, unconditionally: > > static void * _GL_ATTRIBUTE_PURE > nonnull (void *p) > { > if (!p) > xalloc_die (); > return p; > } > > But the declaration of xalloc_die in lib/xalloc.h is conditional: > > #if GNULIB_XALLOC_DIE > > /* This function is always triggered when memory is exhausted. > It must be defined by the application, either explicitly > or by using gnulib's xalloc-die module. This is the > function to call when one wants the program to die because of a > memory allocation failure. */ > /*extern*/ _Noreturn void xalloc_die (void); > > #endif /* GNULIB_XALLOC_DIE */
It's conditional on the C macro GNULIB_XALLOC_DIE, which is defined by the module 'xalloc-die' (file modules/xalloc-die, line 15). This conditional was added through <https://lists.gnu.org/archive/html/bug-gnulib/2020-10/msg00140.html> 1) to avoid link errors with a compiler that does not eliminate unused inline functions, 2) to trigger a compilation error instead of a link error or runtime error when a packages requerts 'xalloc-die' without 'xalloc' or vice versa but then actually uses both. > I have a package (lbzip2 <https://github.com/kjn/lbzip2/>) which > supplies its own definition of xalloc_die, and fails to build due to an > undeclared function. This package calls gnulib-tool like this: gnulib-tool --avoid=xalloc-die --add-import pthread utimens warnings \ timespec-add timespec-sub dtotimespec stat-time lstat malloc-gnu \ fprintf-posix inttypes xalloc largefile gitlog-to-changelog This means, the module 'xalloc-die' is not included, thus xalloc.h does not provide the declaration of xalloc_die(). There are at least three possible fixes: * Rather than '--avoid=xalloc-die', the package could override parts of the 'xalloc-die' module, as described in <https://www.gnu.org/software/gnulib/manual/html_node/Extending-Gnulib.html>. * The package could define the C macro GNULIB_XALLOC_DIE. * The package could declare xalloc_die(). I would probably pick the second one. Bruno