2
1

0001-configure-refactor-backtrace-detection.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. From 9bef473d17ec01efe760462271791dfaaea280c0 Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. Date: Wed, 29 Jul 2015 22:35:19 +0200
  4. Subject: [PATCH 1/3] configure: refactor backtrace() detection
  5. The current code assumes that if __GLIBC__ is not defined, backtrace
  6. support is not available, and defines BTRFS_DISABLE_BACKTRACE.
  7. However, this macro is already defined by the configure.ac script when
  8. --disable-backtrace is passed. This means that if you are using a C
  9. library like musl which does not define __GLIBC__, and you pass
  10. --disable-backtrace, you get a macro redefinition.
  11. Instead of relying on __GLIBC__, this commit implements a proper
  12. configure.ac based detection of backtrace support:
  13. * If the user passes --enable-backtrace, we check if the backtrace()
  14. function is available. If not, we abort the configure process with
  15. an error. Otherwise we enable backtrace support by defining
  16. HAVE_BACKTRACE.
  17. * If the user passes --disable-backtrace, then we don't enable
  18. backtrace support.
  19. * If the user passes nothing special, we auto-detect: if backtrace()
  20. is available, we use it, otherwise we simply warn at configure time
  21. but not fail.
  22. Upstream-status: pending
  23. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  24. Signed-off-by: Brendan Heading <brendanheading@gmail.com>
  25. ---
  26. configure.ac | 32 ++++++++++++++++++++++----------
  27. kerncompat.h | 9 ++++-----
  28. 2 files changed, 26 insertions(+), 15 deletions(-)
  29. diff --git a/configure.ac b/configure.ac
  30. index c3a22d1..e936a10 100644
  31. --- a/configure.ac
  32. +++ b/configure.ac
  33. @@ -63,22 +63,34 @@ AC_DEFUN([PKG_STATIC], [
  34. fi
  35. ])
  36. -
  37. +# Provide a --{enable,disable}-backtrace option. If not passed, set
  38. +# enable_backtrace to 'auto' so that we try to enable backtrace
  39. +# support if available, but if not available, we gracefully fallback
  40. +# without backtrace support.
  41. AC_ARG_ENABLE([backtrace],
  42. AS_HELP_STRING([--disable-backtrace], [disable btrfs backtrace]),
  43. - [], [enable_backtrace=yes]
  44. + [enable_backtrace=${enableval}], [enable_backtrace=auto]
  45. )
  46. -AS_IF([test "x$enable_backtrace" = xno], [
  47. - AC_DEFINE([BTRFS_DISABLE_BACKTRACE], [1], [disable backtrace stuff in kerncompat.h ])
  48. -])
  49. -
  50. -if test "x$enable_backtrace" = xyes; then
  51. - AC_CHECK_HEADERS([execinfo.h])
  52. - AC_CHECK_FUNCS([backtrace backtrace_symbols_fd], [],
  53. - AC_MSG_ERROR([standard library does not have backtrace support]))
  54. +# Backtrace support requested (enable_backtrace is either 'yes' or
  55. +# 'auto'), so check for needed headers and functions.
  56. +if test "x$enable_backtrace" != xno; then
  57. + AC_CHECK_HEADERS([execinfo.h])
  58. + AC_CHECK_FUNCS([backtrace backtrace_symbols_fd])
  59. fi
  60. +if test "x$ac_cv_func_backtrace" = xno; then
  61. + # If backtrace support was requested but not available, we fail if
  62. + # --enable-backtrace was passed, or we simply warn if we're
  63. + # auto-detecting.
  64. + if test "x$enable_backtrace" = xyes ; then
  65. + AC_MSG_ERROR([standard library does not have backtrace support])
  66. + elif test "x$enable_backtrace" = xauto ; then
  67. + AC_MSG_WARN([standard library does not have backtrace support, disabled])
  68. + fi
  69. +else
  70. + AC_DEFINE([HAVE_BACKTRACE], [1], [Enable backtrace support])
  71. +fi
  72. AC_ARG_ENABLE([documentation],
  73. AS_HELP_STRING([--disable-documentation], [do not build domumentation]),
  74. diff --git a/kerncompat.h b/kerncompat.h
  75. index 5d92856..8318665 100644
  76. --- a/kerncompat.h
  77. +++ b/kerncompat.h
  78. @@ -33,11 +33,10 @@
  79. #include <features.h>
  80. #ifndef __GLIBC__
  81. -#define BTRFS_DISABLE_BACKTRACE
  82. #define __always_inline __inline __attribute__ ((__always_inline__))
  83. #endif
  84. -#ifndef BTRFS_DISABLE_BACKTRACE
  85. +#ifdef HAVE_BACKTRACE
  86. #include <execinfo.h>
  87. #endif
  88. @@ -65,7 +64,7 @@
  89. #define ULONG_MAX (~0UL)
  90. #endif
  91. -#ifndef BTRFS_DISABLE_BACKTRACE
  92. +#ifdef HAVE_BACKTRACE
  93. #define MAX_BACKTRACE 16
  94. static inline void print_trace(void)
  95. {
  96. @@ -285,7 +284,7 @@ static inline long IS_ERR(const void *ptr)
  97. #define vmalloc(x) malloc(x)
  98. #define vfree(x) free(x)
  99. -#ifndef BTRFS_DISABLE_BACKTRACE
  100. +#ifdef HAVE_BACKTRACE
  101. #define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, !(c))
  102. #else
  103. #define BUG_ON(c) assert(!(c))
  104. @@ -293,7 +292,7 @@ static inline long IS_ERR(const void *ptr)
  105. #define WARN_ON(c) BUG_ON(c)
  106. -#ifndef BTRFS_DISABLE_BACKTRACE
  107. +#ifdef HAVE_BACKTRACE
  108. #define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (c))
  109. #else
  110. #define ASSERT(c) assert(c)
  111. --
  112. 2.4.3