diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-01-05 00:40:04 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-01-05 00:40:04 +0000 |
commit | f6be1179bb66624403d0f55620d67344d9d98c51 (patch) | |
tree | 29cb9bb891a22723eb9b089c40e3f32bff282e09 /libgo | |
parent | 869fbd357e1936b0c1239bc2a336de34fd45b79e (diff) | |
download | gcc-f6be1179bb66624403d0f55620d67344d9d98c51.zip gcc-f6be1179bb66624403d0f55620d67344d9d98c51.tar.gz gcc-f6be1179bb66624403d0f55620d67344d9d98c51.tar.bz2 |
runtime: prevent deadlock when profiling signal arrives during traceback
Traceback routines, e.g. callers and funcentry, may call
__go_get_backtrace_state. If a profiling signal arrives while we
are in the critical section of __go_get_backtrace_state, it tries
to do a traceback, which also calls __go_get_backtrace_state,
which tries to enter the same critical section and will deadlock.
Prevent this deadlock by setting up runtime_in_callers before
calling __go_get_backtrace_state.
Found while investigating golang/go#29448. Will add a test in the
next CL.
Updates golang/go#29448.
Reviewed-on: https://go-review.googlesource.com/c/156037
From-SVN: r267590
Diffstat (limited to 'libgo')
-rw-r--r-- | libgo/runtime/go-caller.c | 9 | ||||
-rw-r--r-- | libgo/runtime/go-callers.c | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/libgo/runtime/go-caller.c b/libgo/runtime/go-caller.c index 9d22f9f..6fe4340 100644 --- a/libgo/runtime/go-caller.c +++ b/libgo/runtime/go-caller.c @@ -137,7 +137,9 @@ __go_file_line (uintptr pc, int index, String *fn, String *file, intgo *line) runtime_memclr (&c, sizeof c); c.index = index; + runtime_xadd (&__go_runtime_in_callers, 1); state = __go_get_backtrace_state (); + runtime_xadd (&__go_runtime_in_callers, -1); backtrace_pcinfo (state, pc, callback, error_callback, &c); *fn = c.fn; *file = c.file; @@ -169,8 +171,13 @@ syminfo_callback (void *data, uintptr_t pc __attribute__ ((unused)), static _Bool __go_symbol_value (uintptr pc, uintptr *val) { + struct backtrace_state *state; + *val = 0; - backtrace_syminfo (__go_get_backtrace_state (), pc, syminfo_callback, + runtime_xadd (&__go_runtime_in_callers, 1); + state = __go_get_backtrace_state (); + runtime_xadd (&__go_runtime_in_callers, -1); + backtrace_syminfo (state, pc, syminfo_callback, error_callback, val); return *val != 0; } diff --git a/libgo/runtime/go-callers.c b/libgo/runtime/go-callers.c index 78ada7a..7ea70851 100644 --- a/libgo/runtime/go-callers.c +++ b/libgo/runtime/go-callers.c @@ -202,8 +202,8 @@ runtime_callers (int32 skip, Location *locbuf, int32 m, bool keep_thunks) data.index = 0; data.max = m; data.keep_thunks = keep_thunks; - state = __go_get_backtrace_state (); runtime_xadd (&__go_runtime_in_callers, 1); + state = __go_get_backtrace_state (); backtrace_full (state, 0, callback, error_callback, &data); runtime_xadd (&__go_runtime_in_callers, -1); |