]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix AIX build break.
authorAditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Fri, 26 Jan 2024 08:19:52 +0000 (02:19 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 1 Feb 2024 00:30:25 +0000 (17:30 -0700)
A recent commit broke AIX build. The thread_local type defined functions
were being considered a weak symbol and hence while creating the binary these
symbols were not visible.

This patch is a fix for the same.

gdb/complaints.c
gdb/complaints.h
gdb/defs.h
gdb/interps.c
gdb/top.c
gdb/utils.c
gdb/utils.h

index 0c46cd7c84fb358b692b6756649cac83c69841bd..496736fe95f9ef87b2f1afb7d54104650dcb9656 100644 (file)
@@ -57,8 +57,9 @@ complaint_internal (const char *fmt, ...)
 
   va_start (args, fmt);
 
-  if (deprecated_warning_hook)
-    (*deprecated_warning_hook) (fmt, args);
+  warning_hook_handler handler = get_warning_hook_handler ();
+  if (handler != nullptr)
+    handler (fmt, args);
   else
     {
       gdb_puts (_("During symbol reading: "), gdb_stderr);
@@ -84,15 +85,15 @@ thread_local complaint_interceptor *complaint_interceptor::g_complaint_intercept
 /* See complaints.h.  */
 
 complaint_interceptor::complaint_interceptor ()
-  : m_saved_warning_hook (&deprecated_warning_hook, issue_complaint),
-    m_saved_complaint_interceptor (&g_complaint_interceptor, this)
+  : m_saved_complaint_interceptor (&g_complaint_interceptor, this),
+    m_saved_warning_hook (issue_complaint)
 {
 }
 
 /* A helper that wraps a warning hook.  */
 
 static void
-wrap_warning_hook (void (*hook) (const char *, va_list), ...)
+wrap_warning_hook (warning_hook_handler hook, ...)
 {
   va_list args;
   va_start (args, hook);
@@ -109,8 +110,9 @@ re_emit_complaints (const complaint_collection &complaints)
 
   for (const std::string &str : complaints)
     {
-      if (deprecated_warning_hook)
-       wrap_warning_hook (deprecated_warning_hook, str.c_str ());
+      warning_hook_handler handler = get_warning_hook_handler ();
+      if (handler != nullptr)
+       wrap_warning_hook (handler, str.c_str ());
       else
        gdb_printf (gdb_stderr, _("During symbol reading: %s\n"),
                    str.c_str ());
index baf10fd7dd7bcc23a82606b6f009894c3325ff50..8ac4c5034eefb2a968ef29403ad0f55ed794301c 100644 (file)
@@ -89,11 +89,6 @@ private:
   /* The issued complaints.  */
   complaint_collection m_complaints;
 
-  typedef void (*saved_warning_hook_ftype) (const char *, va_list);
-
-  /* The saved value of deprecated_warning_hook.  */
-  scoped_restore_tmpl<saved_warning_hook_ftype> m_saved_warning_hook;
-
   /* The saved value of g_complaint_interceptor.  */
   scoped_restore_tmpl<complaint_interceptor *> m_saved_complaint_interceptor;
 
@@ -104,6 +99,9 @@ private:
 
   /* This object.  Used by the static callback function.  */
   static thread_local complaint_interceptor *g_complaint_interceptor;
+
+  /* Object to initialise the warning hook.  */
+  scoped_restore_warning_hook m_saved_warning_hook;
 };
 
 /* Re-emit complaints that were collected by complaint_interceptor.
index f46640006418f8cd28fc7b747e374179ca5565d5..cf471bf5d6629f93f9aa16dca7fbce9a9c88f2dc 100644 (file)
@@ -562,8 +562,6 @@ extern void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
                                                         int noerror);
 extern int (*deprecated_query_hook) (const char *, va_list)
      ATTRIBUTE_FPTR_PRINTF(1,0);
-extern thread_local void (*deprecated_warning_hook) (const char *, va_list)
-     ATTRIBUTE_FPTR_PRINTF(1,0);
 extern void (*deprecated_readline_begin_hook) (const char *, ...)
      ATTRIBUTE_FPTR_PRINTF_1;
 extern char *(*deprecated_readline_hook) (const char *);
index eddc7f3c8719cfb656918ae3ac4e0d2d7a8d12e2..391fea1da038565d3dc2d3d8a67ada2f1c80fd05 100644 (file)
@@ -273,7 +273,6 @@ clear_interpreter_hooks (void)
   deprecated_print_frame_info_listing_hook = 0;
   /*print_frame_more_info_hook = 0; */
   deprecated_query_hook = 0;
-  deprecated_warning_hook = 0;
   deprecated_readline_begin_hook = 0;
   deprecated_readline_hook = 0;
   deprecated_readline_end_hook = 0;
index fb15c719564ff20431f9e2bd8baeb28997e5472e..5114713baa47ac1dfe3529c2ab99be79c184d1db 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -219,10 +219,6 @@ void (*deprecated_print_frame_info_listing_hook) (struct symtab * s,
 
 int (*deprecated_query_hook) (const char *, va_list);
 
-/* Replaces most of warning.  */
-
-thread_local void (*deprecated_warning_hook) (const char *, va_list);
-
 /* These three functions support getting lines of text from the user.
    They are used in sequence.  First deprecated_readline_begin_hook is
    called with a text string that might be (for example) a message for
index b326033e9ffe05d426c32ba4ec033bda82490244..702c3f1582604b60d526599aa23b8224ebcc8a64 100644 (file)
@@ -128,7 +128,26 @@ show_pagination_enabled (struct ui_file *file, int from_tty,
 }
 
 \f
+/* Warning hook pointer.  This has to be 'static' to avoid link
+   problems with thread-locals on AIX.  */
 
+static thread_local void (*warning_hook) (const char *, va_list);
+
+/* See utils.h.  */
+
+warning_hook_handler
+get_warning_hook_handler ()
+{
+  return warning_hook;
+}
+
+/* See utils.h.  */
+
+scoped_restore_warning_hook::scoped_restore_warning_hook
+     (warning_hook_handler new_handler)
+       : m_save (make_scoped_restore (&warning_hook, new_handler))
+{
+}
 
 /* Print a warning message.  The first argument STRING is the warning
    message, used as an fprintf format string, the second is the
@@ -139,8 +158,8 @@ show_pagination_enabled (struct ui_file *file, int from_tty,
 void
 vwarning (const char *string, va_list args)
 {
-  if (deprecated_warning_hook)
-    (*deprecated_warning_hook) (string, args);
+  if (warning_hook != nullptr)
+    warning_hook (string, args);
   else
     {
       std::optional<target_terminal::scoped_restore_terminal_state> term_state;
index a9d04746b2161ca13d45cb47ffc6b3fcb9755896..7487590902a3335a84b08e86159f4f9ec8258239 100644 (file)
@@ -373,6 +373,23 @@ assign_return_if_changed (T &lval, const T &val)
   return true;
 }
 
+/* A function that can be used to intercept warnings.  */
+typedef void (*warning_hook_handler) (const char *, va_list);
+
+/* Set the thread-local warning hook, and restore the old value when
+   finished.  */
+class scoped_restore_warning_hook
+{
+public:
+  explicit scoped_restore_warning_hook (warning_hook_handler new_handler);
+
+private:
+  scoped_restore_tmpl<warning_hook_handler> m_save;
+};
+
+/* Return the current warning handler.  */
+extern warning_hook_handler get_warning_hook_handler ();
+
 /* In some cases GDB needs to try several different solutions to a problem,
    if any of the solutions work then as far as the user is concerned the
    problem is solved, and GDB should continue without warnings.  However,