Respected community members, Hi, Thank you so much for the feedback. We can fix this but I need your guidance as I feel I have missed something in my way to fix this for GDB. > Does the AIX build detect that threads work? If not then we could >perhaps make the use of 'thread_local' dependent on CXX_STD_THREAD. Std::thread works and CXX_STD_THREAD is set in AIX in our build Tom. Is that what you are asking for? So I was trying to fix this issue and currently am still facing the symbol not found issue as pasted below. ld: 0711-317 ERROR: Undefined symbol: _ZN29deprecated_warning_hook_class23 deprecated_member_funcE collect2: error: ld returned 8 exit status gmake: *** [Makefile:2184: gdb] Error 1 I have pasted the git diff below this email that I tried to. As per my understanding, the deprecated_warning_hook is an extern variable declared, which is defined in top.c. I get the idea that this link is doing https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=fece451c2aca57b095e7e4063e342781cf74aa75. Thanks Tom for this. The design to fix this, that I have in mind is that we should declare a function pointer of deprecated hook and intialise it to NULL. This pointer which is global will be the one that will be used everywhere (named as deprecated_warning_hook in defs.h in the git diff) and this pointer will be set by only by the constructor in the class deprecated_warning_hook_class (defined in defs.h in the git diff). So whether complaints.c wants to use this or utils.c one can define an object of this class and then through constructor one must set the pointer deprecated_warning_hook. The older pointer is held by old_handler in the class. When the object goes out of scope, the destructor will reset the deprecated_warning_hook to its previous value be it NULL or anything else. By this way our functions will be able to use the hook and unset the same whenever out of scope. The function pointer that deprecated_warning_hook will point to deprecated_member_func which is a private member function that is static. This is the logic I was applying but it did not work. Kindly let me know where I went wrong and what I missed out. Your expertise will help me fix this for GDB and learn. Have a nice day ahead. Thanks and regards, Aditya. # git diff diff --git a/gdb/complaints.c b/gdb/complaints.c index eb648c655ed..533aa1470a2 100644 --- a/gdb/complaints.c +++ b/gdb/complaints.c @@ -40,6 +40,8 @@ int stop_whining = 0; static std::mutex complaint_mutex; #endif /* CXX_STD_THREAD */ +deprecated_warning_hook_class deprecated_warning_hook_obj(); + /* See complaints.h. */ void diff --git a/gdb/defs.h b/gdb/defs.h index 2f771d8dc49..5c298979614 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -562,8 +562,30 @@ 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); +thread_local void (*deprecated_warning_hook) (const char *, va_list) = NULL; +typedef void (*deprecated_warning_hook_handler) (const char *, va_list) ATTRIBUTE_FPTR_PRINTF(1,0); + +class deprecated_warning_hook_class +{ + public: + deprecated_warning_hook_class (); + ~deprecated_warning_hook_class (); + private: + deprecated_warning_hook_handler old_handler; + static void (*deprecated_member_func) (const char *, va_list); +}; + +deprecated_warning_hook_class::deprecated_warning_hook_class () +{ + old_handler = deprecated_warning_hook; + deprecated_warning_hook = deprecated_member_func; +} + +deprecated_warning_hook_class::~deprecated_warning_hook_class () +{ + deprecated_warning_hook = old_handler; +} + extern void (*deprecated_readline_begin_hook) (const char *, ...) ATTRIBUTE_FPTR_PRINTF_1; extern char *(*deprecated_readline_hook) (const char *); diff --git a/gdb/interps.c b/gdb/interps.c index bec2c85e2fd..c39a5017718 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -273,7 +273,7 @@ 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_warning_hook = 0; */ deprecated_readline_begin_hook = 0; deprecated_readline_hook = 0; deprecated_readline_end_hook = 0; diff --git a/gdb/top.c b/gdb/top.c index 009bf2b0c1c..1afbdb5e19a 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -221,8 +221,6 @@ 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 diff --git a/gdb/utils.c b/gdb/utils.c index 9ae9494d51d..70db397e4fb 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -82,6 +82,8 @@ #include "pager.h" #include "run-on-main-thread.h" +deprecated_warning_hook_class deprecated_warning_hook_obj(); + void (*deprecated_error_begin_hook) (void); /* Prototypes for local functions */ From: Tom Tromey Date: Friday, 12 January 2024 at 9:26 PM To: Tom de Vries Cc: Aditya Kamath1 , Ulrich Weigand , Aditya Kamath1 via Gdb-patches , Sangamesh Mallayya , Tom Tromey Subject: [EXTERNAL] Re: [PATCH] Fix AIX build break >>>>> "Tom" == Tom de Vries writes: Tom> I think this is triggered by using thread-local with extern. Ugh. > Use RAII to set the per-thread SIGSEGV handler Tom> which seems related, given that it mentions link errors. Perhaps we Tom> can do something similar here. That would by fine with me. Does the AIX build detect that threads work? If not then we could perhaps make the use of 'thread_local' dependent on CXX_STD_THREAD. Tom