From fece451c2aca57b095e7e4063e342781cf74aa75 Mon Sep 17 00:00:00 2001 From: Christian Biesinger Date: Tue, 9 Mar 2021 08:16:23 -0600 Subject: Use RAII to set the per-thread SIGSEGV handler This avoids using a thread-local extern variable, which causes link errors on some platforms, notably Cygwin. But I think this is a better pattern even outside of working around linker bugs because it encapsulates direct access to the variable inside the class, instead of having a global extern variable. The cygwin link error is: cp-support.o: in function `gdb_demangle(char const*, int)': /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x6472): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler' /home/Christian/binutils-gdb/obj/gdb/../../gdb/cp-support.c:1619:(.text+0x648b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler' collect2: error: ld returned 1 exit status 2021-03-12 Christian Biesinger PR threads/27239 * cp-support.c: Use scoped_segv_handler_restore. * event-top.c (thread_local_segv_handler): Made static. (scoped_segv_handler_restore::scoped_segv_handler_restore): New function. (scoped_segv_handler_restore::~scoped_segv_handler_restore): New function. * event-top.h (class scoped_segv_handler_restore): New class. (thread_local_segv_handler): Removed. --- gdb/cp-support.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gdb/cp-support.c') diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 1abc3e2..fb4e428 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1615,11 +1615,10 @@ gdb_demangle (const char *name, int options) int crash_signal = 0; #ifdef HAVE_WORKING_FORK - scoped_restore restore_segv - = make_scoped_restore (&thread_local_segv_handler, - catch_demangler_crashes - ? gdb_demangle_signal_handler - : nullptr); + scoped_segv_handler_restore restore_segv + (catch_demangler_crashes + ? gdb_demangle_signal_handler + : nullptr); bool core_dump_allowed = gdb_demangle_attempt_core_dump; SIGJMP_BUF jmp_buf; -- cgit v1.1