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: 1585970 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=cozj29Tr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jls3c10Vhz9t3b for ; Sat, 29 Jan 2022 09:06:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01D8A3858423 for ; Fri, 28 Jan 2022 22:06:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01D8A3858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643407562; 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=cozj29TrZQ+gKdXYUURI125mtaUztFb+uUB48eFI80U2LfvCU1W3qUN36adF1oOTV 8vbH/QLEByEWrothuqBgUoJb/3NRFK65A3C62/72SPkxGDUwMwQoxojlkHbGUUXiO6 8T/J/gu94X5zB0Skmngns2vrSu+pv/Bdlp984x8E= 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+incoming=patchwork.ozlabs.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: 1585971 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Ew3BpAdH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jls5H0rCSz9t3b for ; Sat, 29 Jan 2022 09:07:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE5543858420 for ; Fri, 28 Jan 2022 22:07:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE5543858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643407648; 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=Ew3BpAdHNfi45D7XXZXPr2MbaCvZGVDEPqgGzqC9GwNMfXpi5mRqIOmq3FABZkziq 96RuktPQHS0PZ+mUFqJKXKSzsMDut7BWpR3ThADSq8faQNR4LZiHzYwrnFdXyn+RrG aQrAQw2WvXH29KywtmIO3UDevhyAWbYLqUIW0Qqo= 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+incoming=patchwork.ozlabs.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: 1585972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=T/bYFDfm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jls6m1JKGz9t3b for ; Sat, 29 Jan 2022 09:08:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41D093857C60 for ; Fri, 28 Jan 2022 22:08:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41D093857C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643407725; 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=T/bYFDfmgmwZWg7xOmpjSwXrY5hEspRlHFeuco/IRc1W09cSbOoA3MrVwA0oRCMf+ RWsf6t0nkG6swsHUeFrlxfdNssV5GKSERA8RlGsxVzY5aB3QDzkBxfc211smRPZ5J8 buhp1EKmDL+5kD8QdCFYdVAwm/8opgDVuGCGQQ28= 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+incoming=patchwork.ozlabs.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; }