Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Muhammad Kamran <muhammad.kamran@arm.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simark@simark.ca>,
	Andrew Burgess <aburgess@redhat.com>,
	Wilco Dijkstra <Wilco.Dijkstra@arm.com>,
	Yury Khrustalev <Yury.Khrustalev@arm.com>,
	Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
	Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	Carlos O'Donell <carlos@redhat.com>,
	Muhammad Kamran <muhammad.kamran@arm.com>
Subject: [PATCH v3 2/2] gdb: Keep original IFUNC return type when target type is unknown
Date: Mon, 29 Jun 2026 15:32:03 +0000	[thread overview]
Message-ID: <20260629153203.10142-3-muhammad.kamran@arm.com> (raw)
In-Reply-To: <20260629153203.10142-1-muhammad.kamran@arm.com>

When find_function_addr resolves a GNU IFUNC, it tries to replace the
original function type with the resolved target type, or with the type
returned by the resolver.  If neither source provides a useful return
type, keep the return type from the original function value.

This matters for internal inferior calls such as
find_function_in_inferior ("malloc"), where GDB creates a synthetic
function type with a known fallback return type.

Remove the guard from the IFUNC inferior-call test so the no-debug
resolver/no-debug target variants are tested too.
---
 gdb/infcall.c                        | 12 ++++++++++--
 gdb/testsuite/gdb.base/gnu-ifunc.exp |  7 -------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/gdb/infcall.c b/gdb/infcall.c
index e6b24ff5310..077407073ac 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -395,6 +395,9 @@ find_function_addr (struct value *function,
 	     FUNCTION_TYPE have been asked for.  */
 	  if (retval_type != NULL || function_type != NULL)
 	    {
+	      /* Default to original function type's return type.  Target type
+		 replaces this only if it provides a usable return type.  */
+	      value_type = ftype->target_type ();
 	      type *target_ftype = find_function_type (funaddr);
 	      /* If we don't have debug info for the target function,
 		 see if we can instead extract the target function's
@@ -403,8 +406,13 @@ find_function_addr (struct value *function,
 		target_ftype = find_gnu_ifunc_target_type (resolver_addr);
 	      if (target_ftype != NULL)
 		{
-		  value_type = check_typedef (target_ftype)->target_type ();
-		  ftype = target_ftype;
+		  struct type *target_value_type
+		    = check_typedef (target_ftype)->target_type ();
+		  if (target_value_type != NULL)
+		    {
+		      value_type = target_value_type;
+		      ftype = target_ftype;
+		    }
 		}
 	    }
 	}
diff --git a/gdb/testsuite/gdb.base/gnu-ifunc.exp b/gdb/testsuite/gdb.base/gnu-ifunc.exp
index e2626b9cc0c..cf199daca83 100644
--- a/gdb/testsuite/gdb.base/gnu-ifunc.exp
+++ b/gdb/testsuite/gdb.base/gnu-ifunc.exp
@@ -411,13 +411,6 @@ proc_with_prefix test_inferior_call {resolver_attr resolver_debug final_debug} {
 	return
     }
 
-    # Without debug info for both the resolver and the resolved target,
-    # find_function_addr currently loses the synthetic return type after
-    # resolving the IFUNC.
-    if {!$resolver_debug && !$final_debug} {
-	unsupported "internal call resolves IFUNC malloc"
-	return
-    }
     gdb_test "print (get_string (\"hello-ifunc\"), str_in_arena ())" \
 	" = 1" \
 	"internal call resolves IFUNC malloc"
-- 
2.43.0


      parent reply	other threads:[~2026-06-29 15:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 15:32 [PATCH v3 0/2] gdb: Fix internal inferior calls through GNU IFUNCs Muhammad Kamran
2026-06-29 15:32 ` [PATCH v3 1/2] gdb: Preserve IFUNC marker when finding inferior functions Muhammad Kamran
2026-06-29 15:32 ` Muhammad Kamran [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260629153203.10142-3-muhammad.kamran@arm.com \
    --to=muhammad.kamran@arm.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=Yury.Khrustalev@arm.com \
    --cc=aburgess@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=carlos@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    --cc=thiago.bauermann@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox