Fix relocation of R_X86_64_PC32 against `TLS init function for thread_local_segv_handler' [Cygwin]

Александр Сергеевич Герасимов aleksandr.gerasimov@phystech.edu
Thu Nov 26 21:38:38 GMT 2020


This path fixes the following error while building GDB on Windows under Cygwin:
CXXLD  gdb.exe    
cp-support.o: in function `gdb_demangle(char const*, int)':
    /home/mario/Gcc101_maker/build/gdb/gdb/../../../source/gdb-9.1/gdb/cp-support.c:1552:(.text+0x1d14): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TLS init function for thread_local_segv_handler'
    /home/mario/Gcc101_maker/build/gdb/gdb/../../../source/gdb-9.1/gdb/cp-support.c:1552:(.text+0x1d2d): 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
    make[2]: *** [Makefile:1908: gdb.exe] Error 1
    make[2]: Leaving directory '/home/mario/Gcc101_maker/build/gdb/gdb'
    make[1]: *** [Makefile:9567: all-gdb] Error 2
    make[1]: Leaving directory '/home/mario/Gcc101_maker/build/gdb'
    make: *** [Makefile:855: all] Error 2
Issue reacked on GDB versions a least 9.1 and 9.2.
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index c1d62f17..30195f79 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1539,21 +1539,40 @@ report_failed_demangle (const char *name, bool core_dump_allowed,
 
 #endif
 
-/* A wrapper for bfd_demangle.  */
+#ifdef __CYGWIN__ 
+extern void set_segv_handler(void* hdl);
+#endif
 
+/* A wrapper for bfd_demangle.  */
 char *
 gdb_demangle (const char *name, int options)
 {
   char *result = NULL;
   int crash_signal = 0;
-
+  
 #ifdef HAVE_WORKING_FORK
+#ifdef __CYGWIN__ 
+  thread_local void (*thread_local_segv_handler_l) (int);
+  thread_local_segv_handler_l = NULL;
+
   scoped_restore restore_segv
+    = make_scoped_restore (&thread_local_segv_handler_l,
+              catch_demangler_crashes
+              ? gdb_demangle_signal_handler
+              : nullptr);
+  set_segv_handler((void*)thread_local_segv_handler_l);
+  
+#else
+  
+ scoped_restore restore_segv
     = make_scoped_restore (&thread_local_segv_handler,
               catch_demangler_crashes
               ? gdb_demangle_signal_handler
               : nullptr);
-
+#endif
+  
   bool core_dump_allowed = gdb_demangle_attempt_core_dump;
   SIGJMP_BUF jmp_buf;
   scoped_restore restore_jmp_buf
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 8ac6965f..982ab284 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -846,12 +846,20 @@ gdb_readline_no_editing_callback (gdb_client_data client_data)
   result = buffer_finish (&line_buffer);
   ui->input_handler (gdb::unique_xmalloc_ptr<char> (result));
 }
-
 
 /* See event-top.h.  */
 
 thread_local void (*thread_local_segv_handler) (int);
 
+#ifdef __CYGWIN__ 
+void set_segv_handler(void* hdl)
+{
+  thread_local_segv_handler = (void (*)(int))hdl;
+}
+#endif
+
 static void handle_sigsegv (int sig);
 
 /* Install the SIGSEGV handler.  */
@@ -879,9 +887,12 @@ static void
 handle_sigsegv (int sig)
 {
   install_handle_sigsegv ();
   if (thread_local_segv_handler == nullptr)
+  {
     abort ();
+  }
   thread_local_segv_handler (sig);
 }



More information about the Gdb-patches mailing list