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; +}