1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-11-30 11:41:39 +03:00

string: Check if attribute can declared after function declaration

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>
This commit is contained in:
Adhemerval Zanella
2025-10-31 17:00:42 -03:00
parent 9044d61ff9
commit bd6b49e11d
4 changed files with 57 additions and 0 deletions

View File

@@ -320,4 +320,7 @@
/* Define if trunc is inlined on x86. */ /* Define if trunc is inlined on x86. */
#undef HAVE_X86_INLINE_TRUNC #undef HAVE_X86_INLINE_TRUNC
/* Define if compiler allows add attribute after function declaration. */
#undef ATTR_AFTER_FUNC_DECL
#endif #endif

29
configure vendored
View File

@@ -9580,6 +9580,35 @@ if test "$pthread_in_libc" = yes; then
fi 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_files="$ac_config_files config.make Makefile"
ac_config_commands="$ac_config_commands default" ac_config_commands="$ac_config_commands default"

View File

@@ -2232,6 +2232,26 @@ if test "$pthread_in_libc" = yes; then
fi fi
AC_SUBST(pthread_in_libc) 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_FILES([config.make Makefile])
AC_CONFIG_COMMANDS([default],[[ AC_CONFIG_COMMANDS([default],[[
case $CONFIG_FILES in *config.make*) case $CONFIG_FILES in *config.make*)

View File

@@ -188,8 +188,13 @@ extern __typeof (strsep) strsep attribute_hidden;
&& !defined NO_MEMPCPY_STPCPY_REDIRECT && !defined NO_MEMPCPY_STPCPY_REDIRECT
/* Redirect calls to __builtin_mempcpy and __builtin_stpcpy to call /* Redirect calls to __builtin_mempcpy and __builtin_stpcpy to call
__mempcpy and __stpcpy if not inlined. */ __mempcpy and __stpcpy if not inlined. */
# ifdef ATTR_AFTER_FUNC_DECL
extern __typeof (mempcpy) mempcpy __asm__ ("__mempcpy"); extern __typeof (mempcpy) mempcpy __asm__ ("__mempcpy");
extern __typeof (stpcpy) stpcpy __asm__ ("__stpcpy"); extern __typeof (stpcpy) stpcpy __asm__ ("__stpcpy");
# else
__asm__ ("mempcpy = __mempcpy");
__asm__ ("stpcpy = __stpcpy");
# endif
#endif #endif
extern void *__memcpy_chk (void *__restrict __dest, extern void *__memcpy_chk (void *__restrict __dest,