[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
memset_explicit: Fix compilation error on some OpenSolaris derivatives
From: |
Bruno Haible |
Subject: |
memset_explicit: Fix compilation error on some OpenSolaris derivatives |
Date: |
Sat, 20 Apr 2024 00:12:18 +0200 |
Compiling a testdir for 'memset_explicit' on Solaris 11 SmartOS with clang
as compiler, I get an error:
clang -O2 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -DNO_XMALLOC
-DEXEEXT=\"\" -I. -I../../gllib -I.. -DGNULIB_STRICT_CHECKING=1
-I/root/prefix64clang/include -I/opt/tools/include -Wall -D_REENTRANT
-fvisibility=hidden -g -O2 -MT memset_explicit.o -MD -MP -MF $depbase.Tpo -c -o
memset_explicit.o ../../gllib/memset_explicit.c &&\
mv -f $depbase.Tpo $depbase.Po
../../gllib/memset_explicit.c:34:10: error: call to undeclared function
'memset_s'; ISO C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
(void) memset_s (s, len, c, len);
^
../../gllib/memset_explicit.c:34:10: note: did you mean 'memset'?
/usr/include/iso/string_iso.h:72:14: note: 'memset' declared here
extern void *memset(void *, int, size_t);
^
1 error generated.
gmake[4]: *** [Makefile:11453: memset_explicit.o] Error 1
The reason is that on this system, the function 'memset_s' exists in libc,
but is only declared (in /usr/include/iso/string_iso.h) if __EXT1_VISIBLE
is set. __EXT1_VISIBLE is defined by <sys/feature_tests.h> if
__STDC_WANT_LIB_EXT1__ is defined to non-zero at that point.
gnulib's lib/memset_explicit.c defines __STDC_WANT_LIB_EXT1__, but it comes
too late, because <config.h> has already included <stdalign.h>, <stddef.h>,
<stdbool.h>, or <assert.h>. <stdbool.h> and <assert.h> include
<sys/feature_tests.h>.
This patch fixes it.
Note that this may break programs which define errno_t and rsize_t. Such
programs will need to change, because these are now standardized types.
2024-04-19 Bruno Haible <bruno@clisp.org>
memset_explicit: Fix compilation error on some OpenSolaris derivatives.
* m4/extensions.m4 (gl_USE_SYSTEM_EXTENSIONS): Arrange to define
__STDC_WANT_LIB_EXT1__ to 1.
* modules/memset_explicit (Depends-on): Add extensions.
* m4/memset_explicit.m4 (gl_FUNC_MEMSET_EXPLICIT): Require
gl_USE_SYSTEM_EXTENSIONS.
* lib/memset_explicit.c (__STDC_WANT_LIB_EXT1__): Remove definition.
diff --git a/lib/memset_explicit.c b/lib/memset_explicit.c
index cf6cc64784..33c0987348 100644
--- a/lib/memset_explicit.c
+++ b/lib/memset_explicit.c
@@ -16,11 +16,7 @@
#include <config.h>
-/* memset_s need this define */
-#if HAVE_MEMSET_S
-# define __STDC_WANT_LIB_EXT1__ 1
-#endif
-
+/* Specification. */
#include <string.h>
/* Set S's bytes to C, where S has LEN bytes. The compiler will not
diff --git a/m4/extensions.m4 b/m4/extensions.m4
index 887c651564..fae4141358 100644
--- a/m4/extensions.m4
+++ b/m4/extensions.m4
@@ -1,5 +1,5 @@
# extensions.m4
-# serial 23 -*- Autoconf -*-
+# serial 24 -*- Autoconf -*-
dnl Copyright (C) 2003, 2006-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -230,4 +230,10 @@ AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS]
[Define to enable the declarations of ISO C 11 types and functions.])
;;
esac
+
+ dnl On OpenSolaris derivatives, the include files contains a couple of
+ dnl declarations that are only activated with an explicit
+ dnl -D__STDC_WANT_LIB_EXT1__.
+ AC_DEFINE([__STDC_WANT_LIB_EXT1__], [1],
+ [Define to enable the declarations of ISO C 23 Annex K types and
functions.])
])
diff --git a/m4/memset_explicit.m4 b/m4/memset_explicit.m4
index a47973ec4a..499a95968a 100644
--- a/m4/memset_explicit.m4
+++ b/m4/memset_explicit.m4
@@ -1,5 +1,5 @@
# memset_explicit.m4
-# serial 2
+# serial 3
dnl Copyright 2022-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -8,6 +8,8 @@
AC_DEFUN([gl_FUNC_MEMSET_EXPLICIT],
[
AC_REQUIRE([gl_STRING_H_DEFAULTS])
+ dnl Persuade OpenSolaris derivatives' <string.h> to declare memset_s().
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
gl_CHECK_FUNCS_ANDROID([memset_explicit], [[#include <string.h>]])
if test $ac_cv_func_memset_explicit = no; then
diff --git a/modules/memset_explicit b/modules/memset_explicit
index da16edefd6..294c9f4d8e 100644
--- a/modules/memset_explicit
+++ b/modules/memset_explicit
@@ -7,6 +7,7 @@ m4/memset_explicit.m4
Depends-on:
string
+extensions
configure.ac:
gl_FUNC_MEMSET_EXPLICIT