]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgo: Avoid some cases of getting callers recursively.
authorIan Lance Taylor <ian@gcc.gnu.org>
Sun, 1 Dec 2013 01:40:16 +0000 (01:40 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Sun, 1 Dec 2013 01:40:16 +0000 (01:40 +0000)
Avoids hanging inside older versions of glibc that do not
support recurive calls to dl_iterate_phdr.

From-SVN: r205561

libgo/runtime/go-callers.c
libgo/runtime/proc.c
libgo/runtime/runtime.h

index 291dfd0d666764296c13e8b9af6baa50486788d6..ae411d9c83a7c1db74fd5b7e1d6dcfeb60848985 100644 (file)
 #include "runtime.h"
 #include "array.h"
 
+/* This is set to non-zero when calling backtrace_full.  This is used
+   to avoid getting hanging on a recursive lock in dl_iterate_phdr on
+   older versions of glibc when a SIGPROF signal arrives while
+   collecting a backtrace.  */
+
+uint32 runtime_in_callers;
+
 /* Argument passed to callback function.  */
 
 struct callers_data
@@ -111,8 +118,10 @@ runtime_callers (int32 skip, Location *locbuf, int32 m)
   data.skip = skip + 1;
   data.index = 0;
   data.max = m;
+  runtime_xadd (&runtime_in_callers, 1);
   backtrace_full (__go_get_backtrace_state (), 0, callback, error_callback,
                  &data);
+  runtime_xadd (&runtime_in_callers, -1);
   return data.index;
 }
 
index de2a54bfa5e0e0819a4d940ea3af65b30eb9a5fa..47a472b6d0a3a6e11b58d5e3e2c652f9f92a418d 100644 (file)
@@ -2454,6 +2454,15 @@ runtime_sigprof()
                return;
        }
        n = 0;
+
+       if(runtime_atomicload(&runtime_in_callers) > 0) {
+               // If SIGPROF arrived while already fetching runtime
+               // callers we can have trouble on older systems
+               // because the unwind library calls dl_iterate_phdr
+               // which was not recursive in the past.
+               traceback = false;
+       }
+
        if(traceback) {
                n = runtime_callers(0, prof.locbuf, nelem(prof.locbuf));
                for(i = 0; i < n; i++)
index e82e83231e6c9d02c8143978d4e6ad2437765fff..b9a1686d385c4a6c8fdf75784649c01b67073c6c 100644 (file)
@@ -776,6 +776,7 @@ extern struct backtrace_state *__go_get_backtrace_state(void);
 extern _Bool __go_file_line(uintptr, String*, String*, intgo *);
 extern byte* runtime_progname();
 extern void runtime_main(void*);
+extern uint32 runtime_in_callers;
 
 int32 getproccount(void);