From: Simon Marchi Date: Fri, 23 May 2025 16:30:52 +0000 (-0400) Subject: gdb/solib-svr4: check that solib is SVR4 in tls_maybe_fill_slot and tls_maybe_erase_slot X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f76436396f33f583ecec33188777ab73f4e59404;p=thirdparty%2Fbinutils-gdb.git gdb/solib-svr4: check that solib is SVR4 in tls_maybe_fill_slot and tls_maybe_erase_slot Functions tls_maybe_fill_slot and tls_maybe_erase_slot blindly assume that the passe solibs come from solib-svr4. This is not always the case, because they are called even on the systems where the solib implementation isn't solib-svr4. Add some checks to return early in that case. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32990 Change-Id: I0a281e1f4826aa1914460c2213f0fae1bdc9af7c Tested-By: Hannes Domani Approved-By: Andrew Burgess --- diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 9f56d861354..a1dc13cb6ff 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1728,6 +1728,10 @@ glibc_link_map_to_tls_module_id (CORE_ADDR lm_addr) static void tls_maybe_fill_slot (solib &so) { + auto *li = dynamic_cast (so.lm_info.get ()); + if (li == nullptr) + return; + struct svr4_info *info = get_svr4_info (current_program_space); if (!info->glibc_tls_slots_inited) { @@ -1753,7 +1757,6 @@ tls_maybe_fill_slot (solib &so) auto it = std::find (info->glibc_tls_slots.begin (), info->glibc_tls_slots.end (), 0); - auto *li = gdb::checked_static_cast (so.lm_info.get ()); if (it == info->glibc_tls_slots.end ()) info->glibc_tls_slots.push_back (li->lm_addr); else @@ -1771,8 +1774,11 @@ tls_maybe_erase_slot (program_space *pspace, const solib &so, if (still_in_use) return; + auto *li = dynamic_cast (so.lm_info.get ()); + if (li == nullptr) + return; + struct svr4_info *info = get_svr4_info (pspace); - auto *li = gdb::checked_static_cast (so.lm_info.get ()); auto it = std::find (info->glibc_tls_slots.begin (), info->glibc_tls_slots.end (), li->lm_addr);