diff mbox

Fix failure of gfortran.dg/backtrace_1.f90 on hppa*-*-hpux*

Message ID DD7394A3-7E09-41F7-9809-CB0EEC81F65A@bell.net
State New
Headers show

Commit Message

John David Anglin Dec. 28, 2015, 7:58 p.m. UTC
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.anglin@bell.net
2015-12-28  John David Anglin  <danglin@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.

Comments

John David Anglin Jan. 23, 2016, 10:40 p.m. UTC | #1
Ping.

On 2015-12-28, at 2:58 PM, John David Anglin wrote:

> 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.anglin@bell.net
> 
> 
> <backtrace.c.d.2.txt>

--
John David Anglin	dave.anglin@bell.net
Jerry DeLisle Jan. 23, 2016, 11:12 p.m. UTC | #2
On 01/23/2016 02:40 PM, John David Anglin wrote:
> Ping.
> 
> On 2015-12-28, at 2:58 PM, John David Anglin wrote:
> 
>> 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?
>>

OK,

Jerry
diff mbox

Patch

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