libc-misc.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Miscellaneous definitions for both glibc build and test.
  2. Copyright (C) 2024-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _INCLUDE_MISC_H
  16. #define _INCLUDE_MISC_H
  17. #include <config.h>
  18. /* Add the compiler optimization to inhibit loop transformation to library
  19. calls. This is used to avoid recursive calls in memset and memmove
  20. default implementations in tests. */
  21. #ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
  22. # define inhibit_loop_to_libcall \
  23. __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
  24. #else
  25. # define inhibit_loop_to_libcall
  26. #endif
  27. #ifdef HAVE_TEST_CC_INHIBIT_LOOP_TO_LIBCALL
  28. # define test_cc_inhibit_loop_to_libcall \
  29. __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
  30. #else
  31. # define test_cc_inhibit_loop_to_libcall
  32. #endif
  33. /* Used to disable stack protection in sensitive places, like ifunc
  34. resolvers and early static TLS init. */
  35. #ifdef __clang__
  36. # define cc_inhibit_stack_protector \
  37. __attribute__((no_stack_protector))
  38. #else
  39. # define cc_inhibit_stack_protector \
  40. __attribute__ ((__optimize__ ("-fno-stack-protector")))
  41. #endif
  42. #if IS_IN (testsuite) || IS_IN (testsuite_internal)
  43. # ifdef HAVE_TEST_CC_NO_STACK_PROTECTOR
  44. # define test_inhibit_stack_protector cc_inhibit_stack_protector
  45. # define inhibit_stack_protector cc_inhibit_stack_protector
  46. # else
  47. # define test_inhibit_stack_protector
  48. # define inhibit_stack_protector
  49. # endif
  50. #else
  51. # ifdef HAVE_CC_NO_STACK_PROTECTOR
  52. # define inhibit_stack_protector cc_inhibit_stack_protector
  53. # else
  54. # define inhibit_stack_protector
  55. # endif
  56. #endif
  57. #endif