From 63af22eb25e69fe3ffed60848c98d4723c5b7431 Mon Sep 17 00:00:00 2001 From: Kareem Date: Fri, 27 Mar 2026 17:01:02 -0700 Subject: [PATCH 1/3] Define HAVE_LIMITS_H in options.h rather than config.h since types.h depends on this definition and config.h isn't consistently available at runtime. Fixes #9936. --- cmake/config.in | 3 --- cmake/options.h.in | 3 +++ configure.ac | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/config.in b/cmake/config.in index f2524e41e4..6054b6dbe7 100644 --- a/cmake/config.in +++ b/cmake/config.in @@ -19,9 +19,6 @@ /* Define to 1 if you have the `gmtime_r' function. */ #cmakedefine HAVE_GMTIME_R @HAVE_GMTIME_R@ -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_PCAP_PCAP_H @HAVE_PCAP_PCAP_H@ diff --git a/cmake/options.h.in b/cmake/options.h.in index 967fe7b2ad..76e80959f4 100644 --- a/cmake/options.h.in +++ b/cmake/options.h.in @@ -33,6 +33,9 @@ extern "C" { #endif #ifndef WOLFSSL_OPTIONS_IGNORE_SYS +/* Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. */ +#undef HAVE_LIMITS_H +#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ #undef _GNU_SOURCE #cmakedefine _GNU_SOURCE #undef _POSIX_THREADS diff --git a/configure.ac b/configure.ac index 7cd5cf6671..fffa5cf225 100644 --- a/configure.ac +++ b/configure.ac @@ -204,7 +204,9 @@ then fi fi -AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stddef.h time.h sys/ioctl.h sys/socket.h sys/time.h errno.h sys/un.h ctype.h sys/random.h]) +AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stddef.h time.h sys/ioctl.h sys/socket.h sys/time.h errno.h sys/un.h ctype.h sys/random.h]) +# Special case: Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. +AC_CHECK_HEADER([limits.h], [AM_CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIMITS_H=1"], []) AC_CHECK_LIB([network],[socket]) AC_C_BIGENDIAN AC_C___ATOMIC From 9328c2caa4c221c5ed9300bc91c507cdd80a35c5 Mon Sep 17 00:00:00 2001 From: Kareem Date: Wed, 29 Apr 2026 16:15:27 -0700 Subject: [PATCH 2/3] Move HAVE_LIMITS_H outside of WOLFSSL_OPTIONS_IGNORE_SYS. --- cmake/options.h.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/options.h.in b/cmake/options.h.in index 76e80959f4..dfdee642ca 100644 --- a/cmake/options.h.in +++ b/cmake/options.h.in @@ -33,14 +33,14 @@ extern "C" { #endif #ifndef WOLFSSL_OPTIONS_IGNORE_SYS -/* Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. */ -#undef HAVE_LIMITS_H -#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ #undef _GNU_SOURCE #cmakedefine _GNU_SOURCE #undef _POSIX_THREADS #cmakedefine _POSIX_THREADS #endif +/* Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. */ +#undef HAVE_LIMITS_H +#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ #undef ASIO_USE_WOLFSSL #cmakedefine ASIO_USE_WOLFSSL #undef BOOST_ASIO_USE_WOLFSSL From 588bab6f638c42617f6bb52cbdf47b3d198c9e03 Mon Sep 17 00:00:00 2001 From: Kareem Date: Thu, 28 May 2026 14:30:09 -0700 Subject: [PATCH 3/3] Fix HAVE_LIMITS_H definition in CMake. Also move SIZEOF_LONG and SIZEOF_LONG_LONG definitions to options.h. --- CMakeLists.txt | 19 +++++++++++++++++++ cmake/config.in | 6 ------ cmake/options.h.in | 7 ++++++- configure.ac | 9 +++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a2c0e9750..9cac3eec9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,14 @@ check_include_file("sys/stat.h" HAVE_SYS_STAT_H) check_include_file("sys/types.h" HAVE_SYS_TYPES_H) check_include_file("unistd.h" HAVE_UNISTD_H) +# types.h depends on HAVE_LIMITS_H, and it is defined in options.h (rather than +# config.h) so that applications consuming wolfSSL headers see it. The in-tree +# build, however, is configured through config.h/compile definitions and does +# not include options.h, so define it here as well. +if(HAVE_LIMITS_H) + add_definitions("-DHAVE_LIMITS_H") +endif() + include(CheckFunctionExists) # TODO: Also check if these functions are declared by the @@ -140,6 +148,17 @@ check_type_size("long" SIZEOF_LONG) check_type_size("time_t" SIZEOF_TIME_T) check_type_size("uintptr_t" HAVE_UINTPTR_T) +# SIZEOF_LONG/SIZEOF_LONG_LONG are exposed to applications through options.h +# (see cmake/options.h.in) so that application code computes the same +# CTC_SETTINGS as the library. The in-tree build does not include options.h, +# so define them here for the library and test programs. +if(HAVE_SIZEOF_LONG) + add_definitions("-DSIZEOF_LONG=${SIZEOF_LONG}") +endif() +if(HAVE_SIZEOF_LONG_LONG) + add_definitions("-DSIZEOF_LONG_LONG=${SIZEOF_LONG_LONG}") +endif() + # By default, HAVE___UINT128_T gets defined as TRUE, # but we want it as 1. if(HAVE___UINT128_T) diff --git a/cmake/config.in b/cmake/config.in index 6054b6dbe7..335034ce48 100644 --- a/cmake/config.in +++ b/cmake/config.in @@ -49,12 +49,6 @@ /* Define to the full name of this package. */ #define PACKAGE_NAME "@CMAKE_PROJECT_NAME@" -/* The size of `long', as computed by sizeof. */ -#cmakedefine SIZEOF_LONG @SIZEOF_LONG@ - -/* The size of `long long', as computed by sizeof. */ -#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@ - /* The size of `time_t', as computed by sizeof. */ #cmakedefine SIZEOF_TIME_T @SIZEOF_TIME_T@ diff --git a/cmake/options.h.in b/cmake/options.h.in index dfdee642ca..bc1b0a4d73 100644 --- a/cmake/options.h.in +++ b/cmake/options.h.in @@ -38,9 +38,14 @@ extern "C" { #undef _POSIX_THREADS #cmakedefine _POSIX_THREADS #endif -/* Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. */ +/* Since types.h depends on HAVE_LIMITS_H, SIZEOF_LONG and SIZEOF_LONG_LONG, + * we must define them in options.h. */ #undef HAVE_LIMITS_H #cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ +#undef SIZEOF_LONG +#cmakedefine SIZEOF_LONG @SIZEOF_LONG@ +#undef SIZEOF_LONG_LONG +#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@ #undef ASIO_USE_WOLFSSL #cmakedefine ASIO_USE_WOLFSSL #undef BOOST_ASIO_USE_WOLFSSL diff --git a/configure.ac b/configure.ac index fffa5cf225..3822870d92 100644 --- a/configure.ac +++ b/configure.ac @@ -207,6 +207,15 @@ fi AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stddef.h time.h sys/ioctl.h sys/socket.h sys/time.h errno.h sys/un.h ctype.h sys/random.h]) # Special case: Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. AC_CHECK_HEADER([limits.h], [AM_CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIMITS_H=1"], []) +# Propagate the measured integer sizes (from AC_CHECK_SIZEOF above) into +# options.h. The library obtains these from config.h, but config.h is not +# available to applications; without them, application code falls back to the +# limits.h/architecture heuristics in types.h and can compute a CTC_SETTINGS +# value that disagrees with the library's CheckRunTimeSettings(). +AS_IF([test "x$ac_cv_sizeof_long" != "x"], + [AM_CPPFLAGS="$AM_CPPFLAGS -DSIZEOF_LONG=$ac_cv_sizeof_long"]) +AS_IF([test "x$ac_cv_sizeof_long_long" != "x"], + [AM_CPPFLAGS="$AM_CPPFLAGS -DSIZEOF_LONG_LONG=$ac_cv_sizeof_long_long"]) AC_CHECK_LIB([network],[socket]) AC_C_BIGENDIAN AC_C___ATOMIC