The hppa*-*-hpux* target does not support __sync builtins. As a result, libbacktrace does not support backtraces when threads are active.
Instead of always assuming threads are active in libgfortran/runtime/backtrace.c, the attached patch uses __gthread_active_p() to determine whether threads are active or not. In addition, if backtrace_create_state returns NULL, we just return from show_backtrace(). This avoids a segmentation fault when threads are active. This fixes the failure of gfortran.dg/backtrace_1.f90 on hpux. Tested on hppa2.0w-hp-hpux11.11 and hppa64-hp-hpux11.11. Okay for trunk? Dave -- John David Anglin dave.ang...@bell.net
2015-12-28 John David Anglin <dang...@gcc.gnu.org> PR libfortran/68744 * runtime/backtrace.c: Include gthr.h. (show_backtrace): Use __gthread_active_p() to determine whether threads are active. Return if lbstate is NULL. Index: runtime/backtrace.c =================================================================== --- runtime/backtrace.c (revision 231814) +++ runtime/backtrace.c (working copy) @@ -24,6 +24,8 @@ #include "libgfortran.h" +#include <gthr.h> + #include <string.h> #include <stdlib.h> #include <errno.h> @@ -137,8 +139,12 @@ struct backtrace_state *lbstate; struct mystate state = { 0, false, in_signal_handler }; - lbstate = backtrace_create_state (NULL, 1, error_callback, NULL); + lbstate = backtrace_create_state (NULL, __gthread_active_p (), + error_callback, NULL); + if (lbstate == NULL) + return; + if (!BACKTRACE_SUPPORTED || (in_signal_handler && BACKTRACE_USES_MALLOC)) { /* If symbolic backtrace is not supported on this target, or would