aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-12-29 00:07:06 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-12-29 00:07:06 +0000
commite20bfbd18e64b8ab9428aa518b5d7b74a73461d9 (patch)
treea5200fb4bd7b40981b58590f089defa85c251512
parent50bec22834e0b147fca92bea80501bccc309ce4d (diff)
downloadgcc-e20bfbd18e64b8ab9428aa518b5d7b74a73461d9.zip
gcc-e20bfbd18e64b8ab9428aa518b5d7b74a73461d9.tar.gz
gcc-e20bfbd18e64b8ab9428aa518b5d7b74a73461d9.tar.bz2
runtime: prevent deadlock when profiling signal arrives in stack scan
Precise stack scan needs to unwind the stack. When it is unwinding the stack, if a profiling signal arrives, which also does a traceback, it may deadlock in dl_iterate_phdr. Prevent this deadlock by setting up runtime_in_callers before traceback. Reviewed-on: https://go-review.googlesource.com/c/155766 From-SVN: r267457
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--libgo/runtime/go-callers.c8
-rw-r--r--libgo/runtime/go-unwind.c2
-rw-r--r--libgo/runtime/runtime.h6
4 files changed, 13 insertions, 5 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 2552025..a36396c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d9a30434440469c640a120fe7132057f5644d38c
+0e482bef69d73b9381dbc543e200a1fe57275e81
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/libgo/runtime/go-callers.c b/libgo/runtime/go-callers.c
index b16ae0c..78ada7a 100644
--- a/libgo/runtime/go-callers.c
+++ b/libgo/runtime/go-callers.c
@@ -16,7 +16,7 @@
older versions of glibc when a SIGPROF signal arrives while
collecting a backtrace. */
-static uint32 runtime_in_callers;
+uint32 __go_runtime_in_callers;
/* Argument passed to callback function. */
@@ -185,7 +185,7 @@ bool alreadyInCallers(void)
bool
alreadyInCallers()
{
- return runtime_atomicload(&runtime_in_callers) > 0;
+ return runtime_atomicload(&__go_runtime_in_callers) > 0;
}
/* Gather caller PC's. */
@@ -203,9 +203,9 @@ runtime_callers (int32 skip, Location *locbuf, int32 m, bool keep_thunks)
data.max = m;
data.keep_thunks = keep_thunks;
state = __go_get_backtrace_state ();
- runtime_xadd (&runtime_in_callers, 1);
+ runtime_xadd (&__go_runtime_in_callers, 1);
backtrace_full (state, 0, callback, error_callback, &data);
- runtime_xadd (&runtime_in_callers, -1);
+ runtime_xadd (&__go_runtime_in_callers, -1);
/* For some reason GCC sometimes loses the name of a thunk function
at the top of the stack. If we are skipping thunks, skip that
diff --git a/libgo/runtime/go-unwind.c b/libgo/runtime/go-unwind.c
index 58cb270..158cbd0 100644
--- a/libgo/runtime/go-unwind.c
+++ b/libgo/runtime/go-unwind.c
@@ -792,7 +792,9 @@ bool
scanstackwithmap (void *gcw)
{
_Unwind_Reason_Code code;
+ runtime_xadd (&__go_runtime_in_callers, 1);
code = _Unwind_Backtrace (scanstackwithmap_callback, gcw);
+ runtime_xadd (&__go_runtime_in_callers, -1);
return code == _URC_END_OF_STACK;
}
diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h
index 21921ec..9f6e251 100644
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -515,3 +515,9 @@ bool runtime_usestackmaps;
bool probestackmaps(void)
__asm__("runtime.probestackmaps");
+
+// 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.
+extern uint32 __go_runtime_in_callers;