You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2026/09/29 22:02:23 UTC

(kudu) branch master updated: [thirdparty] fix Postgres memset_s() build issue on macOS

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f4ec13d5 [thirdparty] fix Postgres memset_s() build issue on macOS
2f4ec13d5 is described below

commit 2f4ec13d527ebe9c0190d0c6dc42a29c8c7cf028
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Sun Sep 27 21:30:44 2026 -0700

    [thirdparty] fix Postgres memset_s() build issue on macOS
    
    This changelist adds an extra patch from PostgreSQL's upstream git repo
    to address compilation error on macOS after the recent update in Kudu's
    3rd-party to enable building with GCC 15 [2]:
    
      thirdparty/src/postgresql-17.2/src/port/explicit_bzero.c:22:9: error:
            call to undeclared function 'memset_s'; ISO C99 and later do not
            support implicit function declarations
            [-Wimplicit-function-declaration]
         22 |         (void) memset_s(buf, len, 0, len);
    
    Also, it updates the CFLAGS used to build PostgreSQL: keeping the flags
    compatible with GCC 7, it switches the default C standard mode
    from C17 to C11, replacing -std=c17 with -std=c11.
    
    [1] https://github.com/postgres/postgres/commit/12eee85e5
    [2] https://github.com/apache/kudu/commit/2acbccb8c
    
    Change-Id: I88651ddd056c90c02f65148905c61eb0f4e54f94
    Reviewed-on: http://gerrit.cloudera.org:8080/24964
    Tested-by: Kudu Jenkins
    Reviewed-by: Zoltan Martonka <zm...@cloudera.com>
---
 thirdparty/build-definitions.sh            |   7 +-
 thirdparty/patches/postgres-memset_s.patch | 175 +++++++++++++++++++++++++++++
 thirdparty/vars.sh                         |   3 +-
 3 files changed, 183 insertions(+), 2 deletions(-)

diff --git a/thirdparty/build-definitions.sh b/thirdparty/build-definitions.sh
index 30bbf372c..f0adc54d8 100644
--- a/thirdparty/build-definitions.sh
+++ b/thirdparty/build-definitions.sh
@@ -1227,10 +1227,15 @@ build_postgres() {
   # latter allows for more flexibility when deploying Postgres and its utility
   # binaries, so there isn't a need to override the compiled-in linker hints
   # using LD_LIBRARY_PATH -- that's useful for dist-test and alike.
+  # Add '-std=c11' to avoid compilation errors with GCC 15 (e.g., Ubuntu26)
+  # and newer versions, switching it from its default C23 standard. Also,
+  # keep it compilable at least with GCC 7 (e.g., Ubuntu18) since '-std=c17'
+  # (i.e. the C17 standard) is supported only starting GCC 8 [3].
   #
   # [1] https://stackoverflow.com/questions/70931415/
   # [2] https://stackoverflow.com/questions/38058041/
-  CFLAGS="$EXTRA_CFLAGS -std=c17" \
+  # [3] https://gcc.gnu.org/projects/c-status.html
+  CFLAGS="$EXTRA_CFLAGS -std=c11" \
     LDFLAGS="$EXTRA_LDFLAGS" \
     $POSTGRES_SOURCE/configure \
     --prefix=$PREFIX \
diff --git a/thirdparty/patches/postgres-memset_s.patch b/thirdparty/patches/postgres-memset_s.patch
new file mode 100644
index 000000000..9431ca34e
--- /dev/null
+++ b/thirdparty/patches/postgres-memset_s.patch
@@ -0,0 +1,175 @@
+commit 12eee85e511ff8854ac61e8caad8cec218b20513
+Author: Tom Lane <tg...@sss.pgh.pa.us>
+Date:   Sun May 18 12:45:55 2025 -0400
+
+    Make our usage of memset_s() conform strictly to the C11 standard.
+    
+    Per the letter of the C11 standard, one must #define
+    __STDC_WANT_LIB_EXT1__ as 1 before including <string.h> in order to
+    have access to memset_s().  It appears that many platforms are lenient
+    about this, because we weren't doing it and yet the code appeared to
+    work anyway.  But we now find that with -std=c11, macOS is strict and
+    doesn't declare memset_s, leading to compile failures since we try to
+    use it anyway.  (Given the lack of prior reports, perhaps this is new
+    behavior in the latest SDK?  No matter, we're clearly in the wrong.)
+    
+    In addition to the immediate problem, which could be fixed merely by
+    adding the needed #define to explicit_bzero.c, it seems possible that
+    our configure-time probe for memset_s() could fail in case a platform
+    implements the function in some odd way due to this spec requirement.
+    This concern can be fixed in largely the same way that we dealt with
+    strchrnul() in 6da2ba1d8: switch to using a declaration-based
+    configure probe instead of a does-it-link probe.
+    
+    Back-patch to v13 where we started using memset_s().
+    
+    Reported-by: Lakshmi Narayana Velayudam <de...@gmail.com>
+    Author: Tom Lane <tg...@sss.pgh.pa.us>
+    Discussion: https://postgr.es/m/CAA4pTnLcKGG78xeOjiBr5yS7ZeE-Rh=FaFQQGOO=nPzA1L8yEA@mail.gmail.com
+    Backpatch-through: 13
+
+diff --git a/configure b/configure
+index 275c67ee67c..4f15347cc95 100755
+--- a/configure
++++ b/configure
+@@ -15616,7 +15616,7 @@ fi
+ LIBS_including_readline="$LIBS"
+ LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
+ 
+-for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
++for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
+ do :
+   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+@@ -16192,6 +16192,19 @@ cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_STRCHRNUL $ac_have_decl
+ _ACEOF
+ 
++ac_fn_c_check_decl "$LINENO" "memset_s" "ac_cv_have_decl_memset_s" "#define __STDC_WANT_LIB_EXT1__ 1
++#include <string.h>
++"
++if test "x$ac_cv_have_decl_memset_s" = xyes; then :
++  ac_have_decl=1
++else
++  ac_have_decl=0
++fi
++
++cat >>confdefs.h <<_ACEOF
++#define HAVE_DECL_MEMSET_S $ac_have_decl
++_ACEOF
++
+ 
+ # This is probably only present on macOS, but may as well check always
+ ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include <fcntl.h>
+diff --git a/configure.ac b/configure.ac
+index 7ea91d56adb..4b8335dc613 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1792,7 +1792,6 @@ AC_CHECK_FUNCS(m4_normalize([
+ 	kqueue
+ 	localeconv_l
+ 	mbstowcs_l
+-	memset_s
+ 	posix_fallocate
+ 	ppoll
+ 	pthread_is_threaded_np
+@@ -1838,6 +1837,8 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen, strsep, timingsafe_bcmp])
+ AC_CHECK_DECLS([preadv], [], [], [#include <sys/uio.h>])
+ AC_CHECK_DECLS([pwritev], [], [], [#include <sys/uio.h>])
+ AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
++AC_CHECK_DECLS([memset_s], [], [], [#define __STDC_WANT_LIB_EXT1__ 1
++#include <string.h>])
+ 
+ # This is probably only present on macOS, but may as well check always
+ AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
+diff --git a/meson.build b/meson.build
+index 12de5e80c31..d142e3e408b 100644
+--- a/meson.build
++++ b/meson.build
+@@ -2654,6 +2654,7 @@ decl_checks += [
+   ['preadv', 'sys/uio.h'],
+   ['pwritev', 'sys/uio.h'],
+   ['strchrnul', 'string.h'],
++  ['memset_s', 'string.h', '#define __STDC_WANT_LIB_EXT1__ 1'],
+ ]
+ 
+ # Check presence of some optional LLVM functions.
+@@ -2667,21 +2668,23 @@ endif
+ foreach c : decl_checks
+   func = c.get(0)
+   header = c.get(1)
+-  args = c.get(2, {})
++  prologue = c.get(2, '')
++  args = c.get(3, {})
+   varname = 'HAVE_DECL_' + func.underscorify().to_upper()
+ 
+   found = cc.compiles('''
+-#include <@0@>
++@0@
++#include <@1@>
+ 
+ int main()
+ {
+-#ifndef @1@
+-    (void) @1@;
++#ifndef @2@
++    (void) @2@;
+ #endif
+ 
+ return 0;
+ }
+-'''.format(header, func),
++'''.format(prologue, header, func),
+     name: 'test whether @0@ is declared'.format(func),
+     # need to add cflags_warn to get at least
+     # -Werror=unguarded-availability-new if applicable
+@@ -2880,7 +2883,6 @@ func_checks = [
+   ['kqueue'],
+   ['localeconv_l'],
+   ['mbstowcs_l'],
+-  ['memset_s'],
+   ['mkdtemp'],
+   ['posix_fadvise'],
+   ['posix_fallocate'],
+diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
+index c3cc9fa856d..726a7c1be1f 100644
+--- a/src/include/pg_config.h.in
++++ b/src/include/pg_config.h.in
+@@ -91,6 +91,10 @@
+    `LLVMCreatePerfJITEventListener', and to 0 if you don't. */
+ #undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
+ 
++/* Define to 1 if you have the declaration of `memset_s', and to 0 if you
++   don't. */
++#undef HAVE_DECL_MEMSET_S
++
+ /* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
+    don't. */
+ #undef HAVE_DECL_POSIX_FADVISE
+@@ -291,9 +295,6 @@
+ /* Define to 1 if you have the <memory.h> header file. */
+ #undef HAVE_MEMORY_H
+ 
+-/* Define to 1 if you have the `memset_s' function. */
+-#undef HAVE_MEMSET_S
+-
+ /* Define to 1 if you have the `mkdtemp' function. */
+ #undef HAVE_MKDTEMP
+ 
+diff --git a/src/port/explicit_bzero.c b/src/port/explicit_bzero.c
+index 1d37b119bab..53766e86e94 100644
+--- a/src/port/explicit_bzero.c
++++ b/src/port/explicit_bzero.c
+@@ -12,9 +12,11 @@
+  *-------------------------------------------------------------------------
+  */
+ 
++#define __STDC_WANT_LIB_EXT1__ 1	/* needed to access memset_s() */
++
+ #include "c.h"
+ 
+-#if defined(HAVE_MEMSET_S)
++#if HAVE_DECL_MEMSET_S
+ 
+ void
+ explicit_bzero(void *buf, size_t len)
diff --git a/thirdparty/vars.sh b/thirdparty/vars.sh
index df9fd7b23..e7f517071 100644
--- a/thirdparty/vars.sh
+++ b/thirdparty/vars.sh
@@ -608,7 +608,7 @@ GUMBO_QUERY_PATCHES=(
 )
 
 POSTGRES_VERSION=17.2
-POSTGRES_PATCHLEVEL=2
+POSTGRES_PATCHLEVEL=3
 POSTGRES_NAME=postgresql-$POSTGRES_VERSION
 POSTGRES_SOURCE=$TP_SOURCE_DIR/$POSTGRES_NAME
 POSTGRES_ARCHIVE=$POSTGRES_NAME.tar.gz
@@ -616,6 +616,7 @@ POSTGRES_PATCHES=(
  "patch -p0 < $TP_DIR/patches/postgres-root-can-run-initdb.patch"
  "patch -p0 < $TP_DIR/patches/postgres-no-check-root.patch"
  "patch -p1 < $TP_DIR/patches/postgres-fix-strchrnul-macos-check.patch"
+ "patch -p1 < $TP_DIR/patches/postgres-memset_s.patch"
 )
 
 POSTGRES_JDBC_VERSION=42.7.4