From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id dntAKz1MmGokKh8AWB0awg (envelope-from ) for ; Wed, 02 Sep 2026 12:18:05 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YiTi8fjX; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9791D1E166; Wed, 02 Sep 2026 12:18:05 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D1B391E033 for ; Wed, 02 Sep 2026 12:18:04 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBFA54B9DB65 for ; Wed, 2 Sep 2026 16:18:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBFA54B9DB65 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YiTi8fjX Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 37A814BAE7C4 for ; Wed, 2 Sep 2026 16:16:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37A814BAE7C4 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 37A814BAE7C4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788365796; cv=none; b=GkDxdEx+lbDIRlZERIJs0nl1g87jjYOEjlqJjCr2W2eLHG8DwdriXIn3VLSrQXjiKLHmRpElXx7cxYMSMnNrU/vI13E5teEMJMLRVoR82DVQz6Yxe90zYfV/+Zc4y6ErygOOBbYuGzyBfUKJ1YVx+Ubo+u5XsjQpUGjNdnos85w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788365796; c=relaxed/simple; bh=oyE9BGuVGW5Wl6Wk0CZnrl2roivk+PwZPNvo3RtVEWw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=wIhlvZh5FyyjPalUHw53e5dZJ977ad7OOkd27aTCZKVuy1kKKDXPNQMyRFULmVpEQP6IdBMylmYHsWSXw09FlUBuDsSBUj7FyZjgqeHQ36h4LweVmhudkkaz70hy/jHhNlUtsNThaGY+vjmx/jGpLygFqakF6WZUftAiynsAQOc= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YiTi8fjX DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37A814BAE7C4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788365794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RxXCovhPYC21cIqrKDxkSE3GszZeQ6ygizX+ZyLVcVM=; b=YiTi8fjXmyS0DR0f8VvYzaZ+mn6ClMv+DJq7KfhUWB7j0EDIMyzIlWpX7v6DxQQUG5hNfB PdQGeGQ9eowmREOO3aglMo+hSU/7srKDUNjyqtRBJnGBplXDx6+IVdJpSaBpXnQ8XnMOiD 11g9AV1H5GAhXSi6LXCUA4dC/ca5SPA= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-Kt_9ehojNU6tO6HB7Otpag-1; Wed, 02 Sep 2026 12:16:32 -0400 X-MC-Unique: Kt_9ehojNU6tO6HB7Otpag-1 X-Mimecast-MFC-AGG-ID: Kt_9ehojNU6tO6HB7Otpag_1788365791 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-49b0d7a07acso14030365e9.3 for ; Wed, 02 Sep 2026 09:16:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788365791; x=1788970591; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RxXCovhPYC21cIqrKDxkSE3GszZeQ6ygizX+ZyLVcVM=; b=ciNmd2HNZjcRhfjnlR/WkMoiTgsJpkYJb9WTju0ejquCuBtcoFE0K4yD9Sip8funvC fzQbY/P4W0zG910u1u73mPTepov693YLl+0pTBdSYEA14Ol128og+82a+skU6A7+wYg9 +Nj/QvZAfZC6f1RhrDHHzn+Gou4b0YoQ3zF17eug+IYhDHtNIV4DCSDWbm8au3y3i99j 04ry5p+2lOFhelDSPjnziIMwo2Bszdqv19eppNc6mJpCrO7REY490dHYhl3+UlQHMb6W MuJI7RQtSfNTnj+j9WrNlQmXxbJr6ttnWRughiPZci7rRCHaquJylvrMsmYa4LNhJOSS Emcw== X-Gm-Message-State: AFuF++lEuP60vMnNR5/+f0duAnfjcQx6FQRnAikwXtwiE+35Y3+pCS2G YWNYTO6kTKigP/yGxkYz84vp64inT1CDsWGJY04iCpdly7P/naUdSUiF4nD/hc8k/tAXYN/lto/ tIyWDu0WatPpNKeRlwPrWVz0m5EPEn2Ic2W6OQ4qsYAzl1nPe6wi4/RnguDldUVax31hJbMEITB NAMOxGnrfIyy4neQ88LfYqPQIHGVwEMeuiWnViYCxgKxGbJhs= X-Gm-Gg: AR+sD13COPGdRlp0ObwIERhOeisJRf5lUeIzqeECePhiGKuV7RVVtqxiFZFmmvKMOFQ t41GqNq8Lg2WV+gn7qlRYEOcJqGNBRBQubnxf1staxR+KxacKQSQhMYS3JNJ+sEZ0cg/+ye+7p2 YfDfHlWlU7JqoCn1RQenQzKq70qoNt11ccsXsyPIjD9lhbekE5elJVPsPfho7XJcviGNGFqUlAX DAd9tMqeLXWOcmNGhuEYcei9Ut3X5aX8DVYH3jFHSK/iPOCWmCD31mPsfuyFmzMjUiMCG4NW0kc U7YDN0o618cnFEl1e2WYW+xo7qZV/ggYU7zkXZxjhdPAf446nv9F/hTqvfP2Pqa9E8m1t+HVd8V Unq0p1dZ5CBQa02eURDgSOtAtNK8= X-Received: by 2002:a05:600d:19:b0:49c:edd8:ba35 with SMTP id 5b1f17b1804b1-49cedd8ba5emr32091625e9.6.1788365791448; Wed, 02 Sep 2026 09:16:31 -0700 (PDT) X-Received: by 2002:a05:600d:19:b0:49c:edd8:ba35 with SMTP id 5b1f17b1804b1-49cedd8ba5emr32090305e9.6.1788365790817; Wed, 02 Sep 2026 09:16:30 -0700 (PDT) Received: from localhost (128.223.159.143.dyn.plus.net. [143.159.223.128]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cee5d2019sm2651425e9.2.2026.09.02.09.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2026 09:16:29 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb: fix incorrect search domain in find_function_in_inferior Date: Wed, 2 Sep 2026 17:16:25 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7D77O8UdS69lgFmtCA8UCUOtnKM5frjPQQlkYqB8HIE_1788365791 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org The find_function_in_inferior function is used when GDB needs to make an inferior function call as part of expression evaluation, for example, calling malloc to allocate space in the inferior, or calling an object's constructor. The function lookup has two phases, first we search for full symbols. If that search fails then we fallback to looking for a minimal symbol. The problem I see here is that the full symbol search uses SEARCH_TYPE_DOMAIN, and has done since commit: commit ccf41c248737eb6650211481366c4e1156ce01ae Date: Thu Mar 30 23:00:26 2023 -0600 Use domain_search_flags in lookup_symbol et al Prior to this commit the search was done using VAR_DOMAIN, which would find types, variables, and functions, there was even code in place to raise an error if the symbol we found was not a function. The ccf41c248737eb66 commit switched to SEARCH_TYPE_DOMAIN and removed the "is a function" check. I think this was a mistake. Given that find_function_in_inferior is always used to look for a function, I think we should have switched to SEARCH_FUNCTION_DOMAIN. The "is a function" check can be removed as the search will now only find functions. So the first thing I fixed in this commit is to change SEARCH_TYPE_DOMAIN to SEARCH_FUNCTION_DOMAIN in find_function_in_inferior. With that done the next problem we encounter is that if the full symbol is for a GNU IFUNC then we need to handle this via the minimal symbol path. For inspiration here I looked at the 'variable: name_not_typename' rule in the c-exp.y file, where we say: /* If we found a function, see if it's an ifunc resolver that has the same address as the ifunc symbol itself. If so, prefer the ifunc symbol. */ I think find_function_in_inferior should apply the same logic. To achieve this I added a call to find_gnu_ifunc and restructured the code slightly so that after the full symbol lookup the minimal symbol can come from either calling lookup_minimal_symbol, or from the find_gnu_ifunc path. There are no new tests, but I have been using gdb.base/gnu-ifunc.exp as a smoke test for this change. When I have glibc debug information installed I can (by attaching GDB to GDB) see the full symbol lookup path now triggering, so I know that the updated code path is now being used. It was while reviewing commits: commit ca0908d623605250e6d84afb90d742c328e6bb90 Date: Tue Aug 11 13:12:19 2026 +0000 gdb: Keep original IFUNC return type when target type is unknown commit de930032d883219559d1dba575f2c0f5359e80fc Date: Tue Aug 11 13:12:18 2026 +0000 gdb: Preserve IFUNC marker when finding inferior functions which touched gdb.base/gnu-ifunc.exp that I spotted this bug. --- gdb/valops.c | 79 ++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/gdb/valops.c b/gdb/valops.c index 82c796bd254..e214342c40d 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -113,52 +113,53 @@ struct value * find_function_in_inferior (const char *name, struct objfile **objf_p) { struct block_symbol sym; + bound_minimal_symbol msymbol; - sym = lookup_symbol (name, nullptr, SEARCH_TYPE_DOMAIN, nullptr); - if (sym.symbol != NULL) + sym = lookup_symbol (name, nullptr, SEARCH_FUNCTION_DOMAIN, nullptr); + if (sym.symbol != nullptr) { - if (objf_p) - *objf_p = sym.symbol->objfile (); + msymbol = find_gnu_ifunc (sym.symbol); + if (msymbol.minsym == nullptr) + { + if (objf_p != nullptr) + *objf_p = sym.symbol->objfile (); + return value_of_variable (sym.symbol, sym.block); + } + } + else + msymbol = lookup_minimal_symbol (current_program_space, name); - return value_of_variable (sym.symbol, sym.block); + if (msymbol.minsym != nullptr) + { + struct objfile *objfile = msymbol.objfile; + struct gdbarch *gdbarch = objfile->arch (); + + struct type *type; + CORE_ADDR maddr; + type = lookup_pointer_type (builtin_type (gdbarch)->builtin_char); + type = lookup_function_type (type); + type = lookup_pointer_type (type); + maddr = msymbol.value_address (); + minimal_symbol_type minsym_type = msymbol.minsym->type (); + + if (minsym_type == mst_text_gnu_ifunc + || minsym_type == mst_data_gnu_ifunc) + type->target_type ()->set_is_gnu_ifunc (true); + + if (objf_p != nullptr) + *objf_p = objfile; + + return value_from_pointer (type, maddr); } else { - bound_minimal_symbol msymbol - = lookup_minimal_symbol (current_program_space, name); - - if (msymbol.minsym != NULL) - { - struct objfile *objfile = msymbol.objfile; - struct gdbarch *gdbarch = objfile->arch (); - - struct type *type; - CORE_ADDR maddr; - type = lookup_pointer_type (builtin_type (gdbarch)->builtin_char); - type = lookup_function_type (type); - type = lookup_pointer_type (type); - maddr = msymbol.value_address (); - minimal_symbol_type minsym_type = msymbol.minsym->type (); - - if (minsym_type == mst_text_gnu_ifunc - || minsym_type == mst_data_gnu_ifunc) - type->target_type ()->set_is_gnu_ifunc (true); - - if (objf_p) - *objf_p = objfile; - - return value_from_pointer (type, maddr); - } + if (!target_has_execution ()) + error (_("evaluation of this expression " + "requires the target program to be active")); else - { - if (!target_has_execution ()) - error (_("evaluation of this expression " - "requires the target program to be active")); - else - error (_("evaluation of this expression requires the " - "program to have a function \"%s\"."), - name); - } + error (_("evaluation of this expression requires the " + "program to have a function \"%s\"."), + name); } } base-commit: 9c1937eb7103bee8c329b9c4f5137fcd1726b23d -- 2.25.4