0002-configure.ac-add-detection-of-symver-gcc-attribute.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 365426c28f8bf73d34d77cc06b7d5ffeae17f13a Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  3. Date: Tue, 6 Feb 2024 15:33:15 +0100
  4. Subject: [PATCH] configure.ac: add detection of symver gcc attribute
  5. On non-ELF platforms, such as microblaze, builds will fail when trying
  6. to add symver information because __attribute__((symver ..)) is not
  7. supported even though __has_attribute(__symver__) returns true.
  8. Support for symver needs to be detected via a compile test since
  9. __has_attribute can report false positives [0].
  10. Add a configure compile check for __attribute__((symver ..)) to ensure
  11. it is supported and define a variable to advertise support.
  12. [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101766#c1
  13. Upstream: https://git.savannah.nongnu.org/cgit/attr.git/commit/?id=943c776089dbb24ebbfb7432ba9841f1845bf95a
  14. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  15. [Giulio: rework local patch for #if nesting]
  16. Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
  17. ---
  18. configure.ac | 15 +++++++++++++++
  19. libattr/syscalls.c | 8 ++++----
  20. 2 files changed, 19 insertions(+), 4 deletions(-)
  21. diff --git a/configure.ac b/configure.ac
  22. index 7e362e9..98477b5 100644
  23. --- a/configure.ac
  24. +++ b/configure.ac
  25. @@ -57,6 +57,21 @@ AS_CASE([$host_os],
  26. [linux*], [os_linux=yes])
  27. AM_CONDITIONAL([OS_LINUX], [test "x$os_linux" = "xyes"])
  28. +AC_CACHE_CHECK(whether __attribute__((__symver__())) is supported,
  29. + gcc_cv_symver_attribute,
  30. + [cat > conftest.c <<EOF
  31. +void foo (void) {}
  32. +__typeof(foo) foo __attribute__ ((__symver__("foo@foo")));
  33. +EOF
  34. + gcc_cv_symver_attribute=no
  35. + if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then \
  36. + gcc_cv_symver_attribute=yes
  37. + fi
  38. + rm -f conftest.[cs]
  39. +])
  40. +AS_IF([test $gcc_cv_symver_attribute = yes],
  41. + [AC_DEFINE(HAVE_SYMVER_ATTRIBUTE, [], [GCC supports symver attribute])])
  42. +
  43. AC_CONFIG_COMMANDS([include/attr],
  44. [dnl
  45. rm -rf include/attr
  46. diff --git a/libattr/syscalls.c b/libattr/syscalls.c
  47. index 907560a..7ee6d39 100644
  48. --- a/libattr/syscalls.c
  49. +++ b/libattr/syscalls.c
  50. @@ -31,10 +31,10 @@
  51. * prefer symver attribute if available (since gcc 10),
  52. * fall back to traditional .symver asm directive otherwise.
  53. */
  54. -#ifdef __has_attribute
  55. -# if __has_attribute(__symver__)
  56. -# define SYMVER(cn, vn) __typeof(cn) cn __attribute__((__symver__(vn)))
  57. -# elif __has_attribute(__no_reorder__)
  58. +#if defined(HAVE_SYMVER_ATTRIBUTE)
  59. +# define SYMVER(cn, vn) __typeof(cn) cn __attribute__((__symver__(vn)))
  60. +#elif defined(__has_attribute)
  61. +# if __has_attribute(__no_reorder__)
  62. /*
  63. * Avoid wrong partitioning with older gcc and LTO. May not work reliably
  64. * with all versions; use -flto-partition=none if you encounter problems.
  65. --
  66. 2.34.1