Source: unbound
Version: 1.22.0-1
Severity: important
Justification: impacts architecture cross bootstrap
User: [email protected]
Usertags: rebootstrap

unbound fails to cross build from source when built with gcc-15. What
actually happens is that unbound has a custom check for malloc(0)
returning non-NULL that employs AC_RUN_IFELSE with a cross compilation
default of "no". As a result, it adds a compatibility layer that
declares void *malloc(); and gcc-15 is then unhappy about there being
too many arguments. Boom.

Now glibc's malloc(0) does return non-NULL, but we cannot test this
during cross compilation. Native unbound builds are unaffected. If the
cross build were to recognize this, it would succeed (by avoiding the
broken compatibility code).

I'm proposing the attached patch. It wraps the AC_RUN_IFELSE in
AC_CACHE_CHECK and uses the standard variable
ac_cv_func_malloc_0_nonnull which is also used by AC_FUNC_MALLOC. In
principle, AC_FUNC_MALLOC could be used here, but it comes with its own
replacement and I've left that part alone. Cross builds can now set that
cache variable and succeed.

Please consider applying it in forky. Also consider sending it upstream.
Last but not least, consider fixing the malloc wrappers to not declare
"void *malloc();" without a size argument.

Helmut
--- unbound-1.22.0.orig/acx_nlnetlabs.m4
+++ unbound-1.22.0/acx_nlnetlabs.m4
@@ -1190,8 +1190,9 @@
 dnl $1: unique name for compat code
 AC_DEFUN([ACX_FUNC_MALLOC],
 [
-	AC_MSG_CHECKING([for GNU libc compatible malloc])
-	AC_RUN_IFELSE([AC_LANG_PROGRAM(
+	AC_CACHE_CHECK([for GNU libc compatible malloc],[ac_cv_func_malloc_0_nonnull],
+	[
+		AC_RUN_IFELSE([AC_LANG_PROGRAM(
 [[#if defined STDC_HEADERS || defined HAVE_STDLIB_H
 #include <stdlib.h>
 #else
@@ -1199,14 +1200,16 @@
 #endif
 ]], [ if(malloc(0) != 0) return 1;])
 ],
-	[AC_MSG_RESULT([no])
-	AC_LIBOBJ(malloc)
-	AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if  replacement function should be used.])] ,
-	[AC_MSG_RESULT([yes])
-	AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])],
-	[AC_MSG_RESULT([no (crosscompile)])
-	AC_LIBOBJ(malloc)
-	AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if  replacement function should be used.])] )
+		[ac_cv_func_malloc_0_nonnull=no],
+		[ac_cv_func_malloc_0_nonnull=yes],
+		[ac_cv_func_malloc_0_nonnull="no (crosscompile)"])
+	])
+	AS_IF([test "$ac_cv_func_malloc_0_nonnull" = yes],
+		[AC_DEFINE([HAVE_MALLOC], 1, [If have GNU libc compatible malloc])],
+	[
+		AC_LIBOBJ(malloc)
+		AC_DEFINE_UNQUOTED([malloc], [rpl_malloc_$1], [Define if  replacement function should be used.])
+	])
 ])
 
 dnl Define fallback for fseeko and ftello if needed.
--- unbound-1.22.0.orig/configure.ac
+++ unbound-1.22.0/configure.ac
@@ -628,19 +628,19 @@
 if test x_$enable_alloc_nonregional = x_yes; then
 	AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
 fi
-if test x_$enable_alloc_checks = x_yes; then
+AS_IF([test x_$enable_alloc_checks = x_yes],[
 	AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
 	SLDNS_ALLOCCHECK_EXTRA_OBJ="alloc.lo log.lo"
 	AC_SUBST(SLDNS_ALLOCCHECK_EXTRA_OBJ)
 	ASYNCLOOK_ALLOCCHECK_EXTRA_OBJ="alloc.lo"
 	AC_SUBST(ASYNCLOOK_ALLOCCHECK_EXTRA_OBJ)
-else
-	if test x_$enable_alloc_lite = x_yes; then
+],[
+	AS_IF([test x_$enable_alloc_lite = x_yes],[
 		AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
-	else
+	],[
 		ACX_FUNC_MALLOC([unbound])
-	fi
-fi
+	])
+])
 
 # check windows threads (we use them, not pthreads, on windows).
 if test "$on_mingw" = "yes"; then

Reply via email to