From patchwork Fri Mar 9 21:16:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26261 Received: (qmail 27627 invoked by alias); 9 Mar 2018 21:16:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 27437 invoked by uid 89); 9 Mar 2018 21:16:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Mar 2018 21:16:17 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A877FD142C for ; Fri, 9 Mar 2018 21:16:15 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 563B32026DFD for ; Fri, 9 Mar 2018 21:16:15 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 03/11] Fix calling ifunc functions when resolver has debug info and different name Date: Fri, 9 Mar 2018 21:16:04 +0000 Message-Id: <20180309211612.12941-4-palves@redhat.com> In-Reply-To: <20180309211612.12941-1-palves@redhat.com> References: <20180309211612.12941-1-palves@redhat.com> Currently, on Fedora 27 (glibc 2.26), if you try to call strlen in the inferior you get: (gdb) p strlen ("hello") $1 = (size_t (*)(const char *)) 0x7ffff554aac0 <__strlen_avx2> strlen is an ifunc function, and what we see above is the result of calling the ifunc resolver in the inferior. That returns a pointer to the actual target function that implements strlen on my machine. GDB should have turned around and called the resolver automatically without the user noticing. This is was caused by commit: commit bf223d3e808e6fec9ee165d3d48beb74837796de Date: Mon Aug 21 11:34:32 2017 +0100 Handle function aliases better (PR gdb/19487, errno printing) which added the find_function_alias_target call to c-exp.y, to try to find an alias with debug info for a minsym. For ifunc symbols, that finds the ifunc's resolver if it has debug info (in the example it's called "strlen_ifunc"), with the result that GDB calls that as a regular function. After this commit, we get now get: (top-gdb) p strlen ("hello") '__strlen_avx2' has unknown return type; cast the call to its declared return type Which is correct, because __strlen_avx2 is written in assembly. That'll be improved in a following patch, though. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * c-exp.y (variable production): Skip finding an alias for ifunc symbols. --- gdb/c-exp.y | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 8dc3c068a5e..e2ea07cd792 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1081,7 +1081,9 @@ variable: name_not_typename is important for example for "p *__errno_location()". */ symbol *alias_target - = find_function_alias_target (msymbol); + = (msymbol.minsym->type != mst_text_gnu_ifunc + ? find_function_alias_target (msymbol) + : NULL); if (alias_target != NULL) { write_exp_elt_opcode (pstate, OP_VAR_VALUE);