From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 From: Xi Ruoyao To: Carlos O'Donell , "H.J. Lu" , GNU C Library Cc: syq@debian.org, Joseph Myers , Jiaxun Yang , xry111@mengyan1223.wang Date: Sat, 29 Jan 2022 06:05:42 +0800 In-Reply-To: References: <046da3ae8fc57687b5a9480381904d3f53b1010f.camel@mengyan1223.wang> <4a518e0d1c617e248074db7b0cd122d3c86bb058.camel@mengyan1223.wang> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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-List-Received-Date: Fri, 28 Jan 2022 22:05:49 -0000 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; +} -- 2.35.0