glibc/include/libc-misc.h
H.J. Lu b587e7d45c Fix build without stack protector [BZ #32494]
Without stack protector, inhibit_stack_protector is undefined during build:

In file included from <command-line>:
./../include/libc-symbols.h:665:3: error: expected ';' before '__typeof'
  665 |   __typeof (type_name) *name##_ifunc (__VA_ARGS__)
         \
      |   ^~~~~~~~
./../include/libc-symbols.h:676:3: note: in expansion of macro
'__ifunc_resolver'
  676 |   __ifunc_resolver (type_name, name, expr, init, static, __VA_ARGS__)
      |   ^~~~~~~~~~~~~~~~
./../include/libc-symbols.h:703:3: note: in expansion of macro '__ifunc_args'
  703 |   __ifunc_args (type_name, name, expr, init, arg)
      |   ^~~~~~~~~~~~
./../include/libc-symbols.h:790:3: note: in expansion of macro '__ifunc'
  790 |   __ifunc (redirected_name, name, expr, void, INIT_ARCH)
      |   ^~~~~~~
../sysdeps/x86_64/multiarch/memchr.c:29:1: note: in expansion of macro
'libc_ifunc_redirected'
   29 | libc_ifunc_redirected (__redirect_memchr, memchr, IFUNC_SELECTOR ());
      | ^~~~~~~~~~~~~~~~~~~~~

1. Fix a typo in include/libc-symbols.h to define inhibit_stack_protector
for build.
2. Don't include <config.h> in include/libc-symbols.h since it has been
included in include/libc-misc.h.
3. Change #include "libc-misc.h" to #include <libc-misc.h> in
string/test-string.h.

This fixes BZ #32494.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
2024-12-23 04:51:30 +08:00

67 lines
2.3 KiB
C

/* Miscellaneous definitions for both glibc build and test.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#ifndef _INCLUDE_MISC_H
#define _INCLUDE_MISC_H
#include <config.h>
/* Add the compiler optimization to inhibit loop transformation to library
calls. This is used to avoid recursive calls in memset and memmove
default implementations in tests. */
#ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
# define inhibit_loop_to_libcall \
__attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
#else
# define inhibit_loop_to_libcall
#endif
#ifdef HAVE_TEST_CC_INHIBIT_LOOP_TO_LIBCALL
# define test_cc_inhibit_loop_to_libcall \
__attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
#else
# define test_cc_inhibit_loop_to_libcall
#endif
/* Used to disable stack protection in sensitive places, like ifunc
resolvers and early static TLS init. */
#ifdef __clang__
# define cc_inhibit_stack_protector \
__attribute__((no_stack_protector))
#else
# define cc_inhibit_stack_protector \
__attribute__ ((__optimize__ ("-fno-stack-protector")))
#endif
#if IS_IN (testsuite) || IS_IN (testsuite_internal)
# ifdef HAVE_TEST_CC_NO_STACK_PROTECTOR
# define test_inhibit_stack_protector cc_inhibit_stack_protector
# define inhibit_stack_protector cc_inhibit_stack_protector
# else
# define test_inhibit_stack_protector
# define inhibit_stack_protector
# endif
#else
# ifdef HAVE_CC_NO_STACK_PROTECTOR
# define inhibit_stack_protector cc_inhibit_stack_protector
# else
# define inhibit_stack_protector
# endif
#endif
#endif