]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
string: Check if attribute can declared after function declaration
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 31 Oct 2025 20:00:42 +0000 (17:00 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 10 Nov 2025 11:57:56 +0000 (08:57 -0300)
Some symbols that might be auto-generated by the compiler are redefined
to internal alias (for instance mempcpy to __mempcpy).  However, if fortify
is enabled, the fortify wrapper is define before the alias re-defined and
clang warns attribute declaration must precede definition.

Use an asm alias if compiler does not support it, instead of an
attribute.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
config.h.in
configure
configure.ac
include/string.h

index c31990705e1770a6e003588fb6957b3417bd4b29..5fea143d6929efc651e645c80995d36841424f6d 100644 (file)
 /* Define if trunc is inlined on x86.  */
 #undef HAVE_X86_INLINE_TRUNC
 
+/* Define if compiler allows add attribute after function declaration.  */
+#undef ATTR_AFTER_FUNC_DECL
+
 #endif
index 09d877aabbcaa8c3b7bfb56e65497c34924bcebe..a69097453738e2e06a2a1d3416ec30d88d38ca5a 100755 (executable)
--- a/configure
+++ b/configure
@@ -9580,6 +9580,35 @@ if test "$pthread_in_libc" = yes; then
 fi
 
 
+# Some symbols that might be auto-generated by the compiler are redefined
+# to internal alias (for instance mempcpy to __mempcpy).  However, if fortify
+# is enabled, the fortify wrapper is define before the alias re-defined and
+# clang warns attribute declaration must precede definition.
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking attribute can declared after function declaration" >&5
+printf %s "checking attribute can declared after function declaration... " >&6; }
+if test ${libc_cv_attr_after_func_decl+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) cat > conftest.c <<EOF
+extern __inline int foo (void) { return 0; };
+extern __typeof (foo) foo __asm__ ("__foo");
+EOF
+libc_cv_attr_after_func_decl=no
+if ${CC-cc} $CFLAGS $CPPFLAGS -fgnu89-inline -Werror conftest.c -c \
+   1>&5 2>&5 ; then
+   libc_cv_attr_after_func_decl=yes
+fi
+rm -rf conftest* ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_attr_after_func_decl" >&5
+printf "%s\n" "$libc_cv_attr_after_func_decl" >&6; }
+if test "$libc_cv_attr_after_func_decl" = yes; then
+   printf "%s\n" "#define ATTR_AFTER_FUNC_DECL 1" >>confdefs.h
+
+fi
+
 ac_config_files="$ac_config_files config.make Makefile"
 
 ac_config_commands="$ac_config_commands default"
index 8fb3e12343becddc38dd523473af8c4242afd61f..2409f07dc9367031f67e199dcd16734cb4d94dea 100644 (file)
@@ -2232,6 +2232,26 @@ if test "$pthread_in_libc" = yes; then
 fi
 AC_SUBST(pthread_in_libc)
 
+# Some symbols that might be auto-generated by the compiler are redefined
+# to internal alias (for instance mempcpy to __mempcpy).  However, if fortify
+# is enabled, the fortify wrapper is define before the alias re-defined and
+# clang warns attribute declaration must precede definition.
+AC_CACHE_CHECK([attribute can declared after function declaration],
+              libc_cv_attr_after_func_decl, [dnl
+cat > conftest.c <<EOF
+extern __inline int foo (void) { return 0; };
+extern __typeof (foo) foo __asm__ ("__foo");
+EOF
+libc_cv_attr_after_func_decl=no
+if ${CC-cc} $CFLAGS $CPPFLAGS -fgnu89-inline -Werror conftest.c -c \
+   1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
+   libc_cv_attr_after_func_decl=yes
+fi
+rm -rf conftest*])
+if test "$libc_cv_attr_after_func_decl" = yes; then
+   AC_DEFINE(ATTR_AFTER_FUNC_DECL)
+fi
+
 AC_CONFIG_FILES([config.make Makefile])
 AC_CONFIG_COMMANDS([default],[[
 case $CONFIG_FILES in *config.make*)
index c26ca0927ca7b5dcda935f6e5bce5a495ed78e96..59015c7819d9844c5df64eaa87368583120c84b3 100644 (file)
@@ -188,8 +188,13 @@ extern __typeof (strsep) strsep attribute_hidden;
   && !defined NO_MEMPCPY_STPCPY_REDIRECT
 /* Redirect calls to __builtin_mempcpy and __builtin_stpcpy to call
    __mempcpy and __stpcpy if not inlined.  */
+# ifdef ATTR_AFTER_FUNC_DECL
 extern __typeof (mempcpy) mempcpy __asm__ ("__mempcpy");
 extern __typeof (stpcpy) stpcpy __asm__ ("__stpcpy");
+# else
+__asm__ ("mempcpy = __mempcpy");
+__asm__ ("stpcpy = __stpcpy");
+# endif
 #endif
 
 extern void *__memcpy_chk (void *__restrict __dest,