[PATCH 4/5] configure: check for zero-sized empty structure support

H. Peter Anvin hpa@zytor.com
Thu Dec 3 22:01:38 GMT 2026


Add a compile-only configure probe for empty structures with zero size,
including construction and passing by value. Cache the result and
expose it as _HAVE_EMPTY_STRUCT in thread-local reentrancy builds.

This patch only detects the capability; it does not yet make use of it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 newlib/configure    | 31 +++++++++++++++++++++++++++++++
 newlib/configure.ac | 13 +++++++++++++
 newlib/newlib.hin   |  3 +++
 3 files changed, 47 insertions(+)

diff --git a/newlib/configure b/newlib/configure
index 711fae515f90..68a4a45f87a4 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -6664,6 +6664,37 @@ if test "${newlib_reent_thread_local}" = "yes"; then
 
 $as_echo "#define _WANT_REENT_THREAD_LOCAL 1" >>confdefs.h
 
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zero-sized empty structures" >&5
+$as_echo_n "checking for zero-sized empty structures... " >&6; }
+if ${newlib_cv_empty_struct+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+__extension__ struct __null_reent_ptr {};
+typedef char __empty_struct_size[(sizeof (struct __null_reent_ptr) == 0) ? 1 : -1];
+void __empty_struct_arg (struct __null_reent_ptr);
+void __empty_struct_call (void)
+{
+  __empty_struct_arg (__extension__ (struct __null_reent_ptr) {});
+}
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  newlib_cv_empty_struct=yes
+else
+  newlib_cv_empty_struct=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $newlib_cv_empty_struct" >&5
+$as_echo "$newlib_cv_empty_struct" >&6; }
+  if test "${newlib_cv_empty_struct}" = "yes"; then
+
+$as_echo "#define _HAVE_EMPTY_STRUCT 1" >>confdefs.h
+
+  fi
 fi
 
 _mb_len_max=1
diff --git a/newlib/configure.ac b/newlib/configure.ac
index 4640e69c55dd..8c846a8b8a68 100644
--- a/newlib/configure.ac
+++ b/newlib/configure.ac
@@ -476,6 +476,19 @@ fi
 
 if test "${newlib_reent_thread_local}" = "yes"; then
   AC_DEFINE(_WANT_REENT_THREAD_LOCAL, 1, [Define to enable thread-local storage objects as a replacment for struct _reent members.])
+  AC_CACHE_CHECK([for zero-sized empty structures], [newlib_cv_empty_struct],
+    [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+__extension__ struct __null_reent_ptr {};
+typedef char __empty_struct_size[(sizeof (struct __null_reent_ptr) == 0) ? 1 : -1];
+void __empty_struct_arg (struct __null_reent_ptr);
+void __empty_struct_call (void)
+{
+  __empty_struct_arg (__extension__ (struct __null_reent_ptr) {});
+}
+]])], [newlib_cv_empty_struct=yes], [newlib_cv_empty_struct=no])])
+  if test "${newlib_cv_empty_struct}" = "yes"; then
+    AC_DEFINE(_HAVE_EMPTY_STRUCT, 1, [Define if the compiler supports zero-sized empty structures.])
+  fi
 fi
 
 _mb_len_max=1
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index 52cd500dbfe7..73ddf6947db2 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -47,6 +47,9 @@
 /* Define if compiler supports -fno-tree-loop-distribute-patterns. */
 #undef _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
 
+/* Define if the compiler supports zero-sized empty structures. */
+#undef _HAVE_EMPTY_STRUCT
+
 /* Define if hardware has little to no penalty for misaligned memory access.
    */
 #undef _HAVE_HW_MISALIGNED_ACCESS
-- 
2.56.1



More information about the Newlib mailing list