From patchwork Fri Feb 28 13:32:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Remus X-Patchwork-Id: 107232 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 1815B385840C for ; Fri, 28 Feb 2025 13:35:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1815B385840C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Php2toXN X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id CCC2D3858406 for ; Fri, 28 Feb 2025 13:32:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CCC2D3858406 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CCC2D3858406 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740749533; cv=none; b=NfOj8QvI2L0tXhg6dWHgVfJ73NrVMuK1u0bHedHP/UNig0NeSsIUb4KSC/44wX+jCBmLRExtVjm/lNyhuvmqkSGaYdZfecEg7AAaLroiJrFpIxm+sQZxzMxJnR4AUeoCslffOUut55b+IAOeyHR04YsQDIGgLVs42rmW1GRKbis= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740749533; c=relaxed/simple; bh=Mj7i4CSzP5y661DU0F+qD94R0vefqPuTz/5XRLCQ2gE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LdfQztF3OsP/QqXezrnijC5QGBXDYDxOTqWn95w0w3Ws/KLKuPJa6Fy8sBHua2kEtbXfly0g48iTBBI71x3Hhts3wiRxIqJ0ahynV9uyacY1EgIG6GRHCtdqKrcLs8bQdB6bS/upEzqkm2C63hHqu3Eq3JEsHDOEZEzmSF/w5YE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCC2D3858406 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51S9W34P015498; Fri, 28 Feb 2025 13:32:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=r1c5t0moDnvXr+1Be 1Kp2jJNYvkU5zaukDZsqH4Y+f0=; b=Php2toXNCgqkX3YkxrvRC6Lmd3pix2y47 dGkp63D3zOJdKYWM0EENZQiab7BvztuUBRzjMXA6mDPIqqjK0xmpbpuybd1D0HzT lDtfMtGU/ffTm+Qa5VbrBsOajh3O8fuM+nMY1bAVl2rb3+0EEEF/sscB/5uim+IQ GISr29eZtg2gskOLzdrWsROj8QhWnTtrARuZZ8Z8oqrgCpVk8Ala8PD5KRIoW3IA cDlIxU8J0Uf/QkcaH4iRFPrbv3Vm2beKAcYZLaFhuQLt973vqCe/+suCmpmZ6urj cNF452d5mWa4PVJNaOsGPyEw1WtAXqyNWHsj1eSTnaiqNGKsaboPQ== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45316abnmu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Feb 2025 13:32:09 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51SA4ol0012470; Fri, 28 Feb 2025 13:32:08 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 44yrwt6v7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Feb 2025 13:32:08 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51SDW5YL15925538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Feb 2025 13:32:05 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A95C20049; Fri, 28 Feb 2025 13:32:05 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C0022004D; Fri, 28 Feb 2025 13:32:05 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 28 Feb 2025 13:32:04 +0000 (GMT) From: Jens Remus To: binutils@sourceware.org, Indu Bhagat Cc: Jens Remus , Andreas Krebbel , Jan Beulich , Andreas Schwab Subject: [PATCH v3 2/3] ld: Cleanup sframe_decoder_init_func_bfdinfo use of reloc cookie Date: Fri, 28 Feb 2025 14:32:01 +0100 Message-ID: <20250228133203.1470383-3-jremus@linux.ibm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250228133203.1470383-1-jremus@linux.ibm.com> References: <20250228133203.1470383-1-jremus@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: M-A0KDUSaI5w446mrZm4fbhM3rHBuib9 X-Proofpoint-GUID: M-A0KDUSaI5w446mrZm4fbhM3rHBuib9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-28_03,2025-02-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 adultscore=0 mlxlogscore=999 spamscore=0 phishscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502100000 definitions=main-2502280098 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org The loop did set cookie->rel to the i-th relocation twice. At the beginning using the loop counter. At the end by incrementing. One approach is sufficient. Change cookie to pointer-to-const, replace cookie->rel by rel, initialize before the loop and increment at the end, and merge the two assertions (for cookie->rel) into one. While at it change sec to pointer-to-const. bfd/ * elf-sframe.c (sframe_decoder_init_func_bfdinfo): Cleanup use of relocation cookie. Signed-off-by: Jens Remus --- Notes (jremus): Changes in V2: - Replaced "cookie->rel - cookie->rel" by "i". (Jan) - Merged assertions for cookie->rel. (Andreas) - Changed cookie into pointer-to-const. (Jan) - Changed sec into pointer-to-const. - Reworded commit subject and message and added missing GNU ChangeLog. bfd/elf-sframe.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c index 67ed874e0252..97e007345152 100644 --- a/bfd/elf-sframe.c +++ b/bfd/elf-sframe.c @@ -98,12 +98,13 @@ sframe_decoder_set_func_reloc_index (struct sframe_dec_info *sfd_info, static bool sframe_decoder_init_func_bfdinfo (bfd *abfd, - asection *sec, + const asection *sec, struct sframe_dec_info *sfd_info, - struct elf_reloc_cookie *cookie) + const struct elf_reloc_cookie *cookie) { unsigned int fde_count; unsigned int func_bfdinfo_size, i; + const Elf_Internal_Rela *rel; fde_count = sframe_decoder_get_num_fidx (sfd_info->sfd_ctx); sfd_info->sfd_fde_count = fde_count; @@ -118,19 +119,17 @@ sframe_decoder_init_func_bfdinfo (bfd *abfd, if ((sec->flags & SEC_LINKER_CREATED) && cookie->rels == NULL) return true; + BFD_ASSERT (cookie->rels + fde_count == cookie->relend); + rel = cookie->rels; for (i = 0; i < fde_count; i++) { - cookie->rel = cookie->rels + i; - BFD_ASSERT (cookie->rel < cookie->relend); /* Bookkeep the relocation offset and relocation index of each function for later use. */ - sframe_decoder_set_func_r_offset (sfd_info, i, cookie->rel->r_offset); - sframe_decoder_set_func_reloc_index (sfd_info, i, - (cookie->rel - cookie->rels)); + sframe_decoder_set_func_r_offset (sfd_info, i, rel->r_offset); + sframe_decoder_set_func_reloc_index (sfd_info, i, i); - cookie->rel++; + rel++; } - BFD_ASSERT (cookie->rel == cookie->relend); return true; }