From patchwork Fri Jan 28 22:05:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 50556 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B667B3857C60 for ; Fri, 28 Jan 2022 22:06:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B667B3857C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643407568; bh=wqbsVNY134k20lizsSQxk35SxG7PGjtMwH46cryaAtc=; h=Subject:To:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=eX2F22PPuDSgxlI5TfW0rd3zxy0qDMvuz6RxiA6wtDS68yaaE0nA8hnfD1IM9aRye KRHoQUwcNvubvT92IfBEvQjKHN4F/7AMHTTzN/edIs8hN9qbwQzGx9OIxetq7+06R+ KuDgazg83xcOsOc2k8vZ3T2S5tiXrariqFZC11Cw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id D2EDF385841E for ; Fri, 28 Jan 2022 22:05:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D2EDF385841E Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 6092265BC4; Fri, 28 Jan 2022 17:05:45 -0500 (EST) Message-ID: <03e68d009c7a029270de44f2f2c4b7f3d787ddab.camel@mengyan1223.wang> Subject: [PATCH v3 1/3] add sysdeps/{generic,mips}/elfxx-r_debug.h To: Carlos O'Donell , "H.J. Lu" , GNU C Library Date: Sat, 29 Jan 2022 06:05:42 +0800 In-Reply-To: References: <046da3ae8fc57687b5a9480381904d3f53b1010f.camel@mengyan1223.wang> <4a518e0d1c617e248074db7b0cd122d3c86bb058.camel@mengyan1223.wang> User-Agent: Evolution 3.42.3 MIME-Version: 1.0 X-Spam-Status: No, score=-3037.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: syq@debian.org, Jiaxun Yang , Joseph Myers , xry111@mengyan1223.wang Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Some targets (notably, MIPS) have target-specific way to get the address of r_debug instead of the normal DT_DEBUG. Add a header wrapping the difference. --- sysdeps/generic/elfxx-r_debug.h | 26 ++++++++++++++++++ sysdeps/mips/elfxx-r_debug.h | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 sysdeps/generic/elfxx-r_debug.h create mode 100644 sysdeps/mips/elfxx-r_debug.h diff --git a/sysdeps/generic/elfxx-r_debug.h b/sysdeps/generic/elfxx- r_debug.h new file mode 100644 index 0000000000..7083c95e36 --- /dev/null +++ b/sysdeps/generic/elfxx-r_debug.h @@ -0,0 +1,26 @@ +/* Function to access r_debug structure. + Copyright (C) 2020-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +static EW(Addr) +E(r_debug_offset) (EW(Dyn) *d, int, EW(Addr)) +{ + if (d->d_tag == DT_DEBUG) + return (EW(Addr)) d->d_un.d_ptr; + + return 0; +} diff --git a/sysdeps/mips/elfxx-r_debug.h b/sysdeps/mips/elfxx-r_debug.h new file mode 100644 index 0000000000..a13d069c35 --- /dev/null +++ b/sysdeps/mips/elfxx-r_debug.h @@ -0,0 +1,48 @@ +/* Function to access r_debug structure, MIPS specific version. + Copyright (C) 2020-2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +static EW(Addr) +E(r_debug_offset) (EW(Dyn) *d, int memfd, EW(Addr) d_addr) +{ + EW(Addr) ptr; + +#ifdef R_DEBUG_IN_PROCESS + d_addr = (EW(Addr)) d; +#endif + + switch (d->d_tag) + { + case DT_MIPS_RLD_MAP_REL: + ptr = d_addr + d->d_un.d_val; + break; + case DT_MIPS_RLD_MAP: + ptr = d->d_un.d_ptr; + break; + default: + return 0; + } + +#ifdef R_DEBUG_IN_PROCESS + ptr = *(EW(Addr) *) ptr; +#else + if (pread (memfd, &ptr, sizeof (ptr), ptr) != sizeof (ptr)) + return 0; +#endif + + return ptr; +} From patchwork Fri Jan 28 22:07:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 50557 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 85E28385E010 for ; Fri, 28 Jan 2022 22:07:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85E28385E010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643407655; bh=2ghfjgMPsek3gCuzx8mFuOkHGahE0a+ay7y5ZV7WHXw=; h=Subject:To:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=MWXc+ZEw6u3YQFcD31ftnvQexgT6McyQumZZpbnQQk+7GMWcW0uJcmLKWI/nzcNGw dSyrn6bJcDbck6wXcQltwlRUPOptzQsSHy1YCT/DPKsI6rLDocBBUSgu24JzcgpgR1 jycOEv7PhTi++hztAyzdCxIhln4DFIARXgbAF0vw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 4C75E385840C for ; Fri, 28 Jan 2022 22:07:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C75E385840C Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 83C8665BC8; Fri, 28 Jan 2022 17:07:12 -0500 (EST) Message-ID: <289382368837057e769b963f9ebaacc62e5bcacd.camel@mengyan1223.wang> Subject: [PATCH v3 2/3] pldd: use target-specific r_debug_offset function To: Carlos O'Donell , "H.J. Lu" , GNU C Library Date: Sat, 29 Jan 2022 06:07:09 +0800 In-Reply-To: References: <046da3ae8fc57687b5a9480381904d3f53b1010f.camel@mengyan1223.wang> <4a518e0d1c617e248074db7b0cd122d3c86bb058.camel@mengyan1223.wang> User-Agent: Evolution 3.42.3 MIME-Version: 1.0 X-Spam-Status: No, score=-3037.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: syq@debian.org, Jiaxun Yang , Joseph Myers Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It allows pldd to work on MIPS. --- elf/pldd-xx.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/elf/pldd-xx.c b/elf/pldd-xx.c index 1cdfb49c53..5560afe049 100644 --- a/elf/pldd-xx.c +++ b/elf/pldd-xx.c @@ -22,6 +22,8 @@ #define EW_(e, w, t) EW__(e, w, _##t) #define EW__(e, w, t) e##w##t +#include + struct E(link_map) { EW(Addr) l_addr; @@ -126,21 +128,25 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv, != p[i].p_filesz) error (EXIT_FAILURE, 0, gettext ("cannot read dynamic section")); - /* Search for the DT_DEBUG entry. */ + /* Search for the r_debug struct. */ for (unsigned int j = 0; j < p[i].p_filesz / sizeof (EW(Dyn)); ++j) - if (dyn[j].d_tag == DT_DEBUG && dyn[j].d_un.d_ptr != 0) - { - struct E(r_debug) r; - if (pread (memfd, &r, sizeof (r), dyn[j].d_un.d_ptr) - != sizeof (r)) - error (EXIT_FAILURE, 0, gettext ("cannot read r_debug")); - - if (r.r_map != 0) - { - list = r.r_map; - break; - } - } + { + EW(Addr) d_addr = offset + p[i].p_vaddr + sizeof (EW(Dyn)) * j; + EW(Addr) off = E(r_debug_offset)(&dyn[j], memfd, d_addr); + if (off != 0) + { + struct E(r_debug) r; + if (pread (memfd, &r, sizeof (r), off) + != sizeof (r)) + error (EXIT_FAILURE, 0, gettext ("cannot read r_debug")); + + if (r.r_map != 0) + { + list = r.r_map; + break; + } + } + } free (dyn); break; From patchwork Fri Jan 28 22:08:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 50558 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0A2C385AC24 for ; Fri, 28 Jan 2022 22:08:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0A2C385AC24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643407731; bh=Mujdme6tt6ZDU9MJSH8xYMU2UrFv1OSHh+TrVfuGRvw=; h=Subject:To:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=qAKpAvw7av6pAUdGvPcx+CwFPk1yqYsSnRh2ZNwAvzAlDlTkroku2BYA/DYhRI/jy sVoz/66IKyswxISt1+PPbeEWKlFhbOGvDLuy0uxQw2kghZdofTHIbTOm4b87UbKY5i goNLZVg/YVAO7AP7mt6Pm8ITZrxPJePVgpkoQsRw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 2621A385840C for ; Fri, 28 Jan 2022 22:08:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2621A385840C Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 0210865BC8; Fri, 28 Jan 2022 17:08:27 -0500 (EST) Message-ID: <0a20f5ff9eba19fcf874932315e21f4cb1c1be14.camel@mengyan1223.wang> Subject: [PATCH v3 3/3] elf: tst-dlmopen4: use target specific r_debug_offset function To: Carlos O'Donell , "H.J. Lu" , GNU C Library Date: Sat, 29 Jan 2022 06:08:25 +0800 In-Reply-To: <03e68d009c7a029270de44f2f2c4b7f3d787ddab.camel@mengyan1223.wang> References: <046da3ae8fc57687b5a9480381904d3f53b1010f.camel@mengyan1223.wang> <4a518e0d1c617e248074db7b0cd122d3c86bb058.camel@mengyan1223.wang> <03e68d009c7a029270de44f2f2c4b7f3d787ddab.camel@mengyan1223.wang> User-Agent: Evolution 3.42.3 MIME-Version: 1.0 X-Spam-Status: No, score=-3037.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: syq@debian.org, Jiaxun Yang , Joseph Myers , xry111@mengyan1223.wang Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Fix the test failure on MIPS. --- elf/tst-dlmopen4.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/elf/tst-dlmopen4.c b/elf/tst-dlmopen4.c index d8bcf7e9d5..28e052f199 100644 --- a/elf/tst-dlmopen4.c +++ b/elf/tst-dlmopen4.c @@ -25,16 +25,10 @@ #include #include -#ifndef ELF_MACHINE_GET_R_DEBUG -# define ELF_MACHINE_GET_R_DEBUG(d) \ - (__extension__ ({ \ - struct r_debug_extended *debug; \ - if ((d)->d_tag == DT_DEBUG) \ - debug = (struct r_debug_extended *) (d)->d_un.d_ptr; \ - else \ - debug = NULL; \ - debug; })) -#endif +#define E(x) x +#define EW(x) ElfW(x) +#define R_DEBUG_IN_PROCESS +#include static int do_test (void) @@ -44,7 +38,7 @@ do_test (void) for (d = _DYNAMIC; d->d_tag != DT_NULL; ++d) { - debug = ELF_MACHINE_GET_R_DEBUG (d); + debug = (struct r_debug_extended *) r_debug_offset (d, 0, 0); if (debug != NULL) break; }