Skip to content

Commit

Permalink
prefer backtrace() on OSX
Browse files Browse the repository at this point in the history
It seems to work and _Unwind_Backtrace which is configured otherwise
doesn't.
  • Loading branch information
alk committed Mar 1, 2021
1 parent a015377 commit c2f6040
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Expand Up @@ -65,7 +65,7 @@ include(PCFromUContext)
define_target_variables()

# Currently only backtrace works on s390.
if(s390)
if(s390 OR OSX)
set(default_enable_libunwind OFF)
set(default_enable_backtrace ON)
else()
Expand Down Expand Up @@ -308,6 +308,9 @@ check_c_source_compiles("
#include <unwind.h>
int main()
{
#if __APPLE__
#error OSX _Unwind_Backtrace recurses back to malloc
#endif
&_Unwind_Backtrace;
return 0;
}"
Expand Down
1 change: 1 addition & 0 deletions cmake/DefineTargetVariables.cmake
Expand Up @@ -11,4 +11,5 @@ macro(define_target_variables)
check_cxx_source_compiles("int main() { return __FreeBSD__; }" FreeBSD)
check_cxx_source_compiles("int main() { return __MINGW__; }" MINGW)
check_cxx_source_compiles("int main() { return __linux; }" LINUX)
check_cxx_source_compiles("int main() { return __APPLE__; }" OSX)
endmacro()
15 changes: 12 additions & 3 deletions configure.ac
Expand Up @@ -55,8 +55,13 @@ case "$host" in
*-darwin*) default_enable_heap_checker=no;;
esac

# Currently only backtrace works on s390.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __s390__])],
# Currently only backtrace works on s390 and OSX.
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
#if !defined(__s390__) && !defined(__APPLE__)
#error not s390 and not osx
#endif
return 1
])],
[default_enable_libunwind=no
default_enable_backtrace=yes],
[default_enable_libunwind=yes
Expand Down Expand Up @@ -416,7 +421,11 @@ AC_CACHE_CHECK([if target has _Unwind_Backtrace],
[perftools_cv_have_unwind_backtrace],
[AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[#include <unwind.h>]],
[[#include <unwind.h>
#if defined(__APPLE__)
#error OSX _Unwind_Backtrace recurses back to malloc
#endif
]],
[[&_Unwind_Backtrace]])],
[perftools_cv_have_unwind_backtrace=yes],
[perftools_cv_have_unwind_backtrace=no])
Expand Down

0 comments on commit c2f6040

Please sign in to comment.