diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index d9397623ee1..f1f7cbe4eff 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2018-11-30 Janne Blomqvist + + PR libfortran/88137 + * runtime/backtrace.c (show_backtrace): Make lbstate a static + variable, initialize once. + 2018-11-23 Janne Blomqvist * runtime/error.c (MAGIC): Remove. diff --git a/libgfortran/runtime/backtrace.c b/libgfortran/runtime/backtrace.c index e0c277044b6..3fc973a5e6d 100644 --- a/libgfortran/runtime/backtrace.c +++ b/libgfortran/runtime/backtrace.c @@ -146,11 +146,15 @@ full_callback (void *data, uintptr_t pc, const char *filename, void show_backtrace (bool in_signal_handler) { - struct backtrace_state *lbstate; + /* Note that libbacktrace allows the state to be accessed from + multiple threads, so we don't need to use a TLS variable for the + state here. */ + static struct backtrace_state *lbstate; struct mystate state = { 0, false, in_signal_handler }; - - lbstate = backtrace_create_state (NULL, __gthread_active_p (), - error_callback, NULL); + + if (!lbstate) + lbstate = backtrace_create_state (NULL, __gthread_active_p (), + error_callback, NULL); if (lbstate == NULL) return;