From patchwork Fri Feb 28 13:32:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Remus X-Patchwork-Id: 107231 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 7A54F385840B for ; Fri, 28 Feb 2025 13:34:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A54F385840B 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=L3pEpRer X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id C29ED3858C56 for ; Fri, 28 Feb 2025 13:32:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C29ED3858C56 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 C29ED3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740749531; cv=none; b=MLkshcie0wPJ2Gg++Xcz0mrqB/dMHHUqKaseeTTD/LLDQeXdkxdNdjF/DB5g3ujsHloPfCJjpVcC+PqST5LxOWTm5ngUhrBbPI05D9UDRclTFRkCbnJmpu0+dnSu2ZPnQFjX7nd6tE9tBE8rJjJZuVYY2hL0VidTIZGQ4VLi3Do= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740749531; c=relaxed/simple; bh=G2u+hENRklxmRp/LziK6OOQoTHlvFvmb8B2H1FVCsqU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KnpBosuS0jrMKHYMTXFfNhvjiJBWqANqzSUFWP0r2gCuHiY/+W3FmR2UDa1upcfkDmg9GtY4QvtHXagH8apGVrLy+Lt0y441x7DM3VDRrpYPuMNmoCj9LyVVi6wbUD20b+F/KAs42npQkG+XRSckDPDeMee6DW9DVxf6UChS94w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C29ED3858C56 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51S7X0Da025592; 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=nwvTcssccKs6UBqGh U09qADa5w+NgQ439yL0/IdKfr0=; b=L3pEpRer0BJUwyvnAxjiC1egq+DgUJjxQ MgvRQ0d1xkiaNnFr0QR4k+dJd/eiIhEsgA5vc5LTuKxYehiKXZf3k78OqUV6HHpd PSSUF7D8Mpp1V9ZRl4nofekMTAiNSVVpbHTsm1pcqwhksNpv5V516Bj8XlzJm8rj 1AjWhIMNdiIg779bSVfkBNFCwBIaiGtuQ9s5QH+bWQsW44A/V5aytVVEFhyo/5pb IN8W/Bz5tKrEneS1U62HA1Nvzj7iALIzQjRLPKH+OM4L1VYEjeysJJ71jZ3Gu0JA YREGkV/gaTb3aqnQamwWbEt58DtIV2E6Zw3Wr+C9qJhlfL54ObrGg== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4538uq1md4-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 (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51SDJBFu012131; Fri, 28 Feb 2025 13:32:08 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 44ys9yxvgc-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 51SDW5wI35128040 (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 06F0120040; 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 E21BF2004B; Fri, 28 Feb 2025 13:32:04 +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 Subject: [PATCH v3 1/3] gas: Use SFrame header and FDE field sizes when generating .sframe Date: Fri, 28 Feb 2025 14:32:00 +0100 Message-ID: <20250228133203.1470383-2-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-GUID: gsbXekjW6lcZL0mS_doBuvh_Dfpl6g_3 X-Proofpoint-ORIG-GUID: gsbXekjW6lcZL0mS_doBuvh_Dfpl6g_3 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 mlxscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=880 clxscore=1015 suspectscore=0 priorityscore=1501 spamscore=0 malwarescore=0 adultscore=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 use of SFRAME_RELOC_SIZE in generation of SFrame stack trace information from CFI directives erroneously suggested that this could be used to configure a different relocation size. But in practice it is tied to the SFrame field sizes it is used for and therefore cannot be changed. Replace the uses of SFRAME_RELOC_SIZE by the size of the respective SFrame header and FDE fields when emitting SFrame information. While at it enhance some comments. gas/ * gen-sframe.c (SFRAME_RELOC_SIZE): Delete. (sizeof_member): Define. (output_sframe_funcdesc): Use size of SFrame FDE fields instead of SFRAME_RELOC_SIZE. (output_sframe_internal): Use size of SFrame header fields instead of SFRAME_RELOC_SIZE. Signed-off-by: Jens Remus --- gas/gen-sframe.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c index 947faf366d3d..dd5fb25e367f 100644 --- a/gas/gen-sframe.c +++ b/gas/gen-sframe.c @@ -26,9 +26,8 @@ #ifdef support_sframe_p -/* By default, use 32-bit relocations from .sframe into .text. */ -#ifndef SFRAME_RELOC_SIZE -# define SFRAME_RELOC_SIZE 4 +#ifndef sizeof_member +# define sizeof_member(type, member) (sizeof (((type *)0)->member)) #endif /* Whether frame row entries track RA. @@ -613,11 +612,9 @@ output_sframe_funcdesc (symbolS *start_of_fre_section, struct sframe_func_entry *sframe_fde) { expressionS exp; - unsigned int addr_size; symbolS *dw_fde_start_addrS, *dw_fde_end_addrS; unsigned int pauth_key; - addr_size = SFRAME_RELOC_SIZE; dw_fde_start_addrS = get_dw_fde_start_addrS (sframe_fde->dw_fde); dw_fde_end_addrS = get_dw_fde_end_addrS (sframe_fde->dw_fde); @@ -626,21 +623,24 @@ output_sframe_funcdesc (symbolS *start_of_fre_section, exp.X_add_symbol = dw_fde_start_addrS; /* to location. */ exp.X_op_symbol = symbol_temp_new_now (); /* from location. */ exp.X_add_number = 0; - emit_expr (&exp, addr_size); + emit_expr (&exp, sizeof_member (sframe_func_desc_entry, + sfde_func_start_address)); /* Size of the function in bytes. */ exp.X_op = O_subtract; exp.X_add_symbol = dw_fde_end_addrS; exp.X_op_symbol = dw_fde_start_addrS; exp.X_add_number = 0; - emit_expr (&exp, addr_size); + emit_expr (&exp, sizeof_member (sframe_func_desc_entry, + sfde_func_size)); /* Offset to the first frame row entry. */ exp.X_op = O_subtract; exp.X_add_symbol = fre_symbol; /* Minuend. */ exp.X_op_symbol = start_of_fre_section; /* Subtrahend. */ exp.X_add_number = 0; - emit_expr (&exp, addr_size); + emit_expr (&exp, sizeof_member (sframe_func_desc_entry, + sfde_func_start_fre_off)); /* Number of FREs. */ out_four (sframe_fde->num_fres); @@ -681,9 +681,6 @@ output_sframe_internal (void) unsigned char abi_arch = 0; int fixed_fp_offset = SFRAME_CFA_FIXED_FP_INVALID; int fixed_ra_offset = SFRAME_CFA_FIXED_RA_INVALID; - unsigned int addr_size; - - addr_size = SFRAME_RELOC_SIZE; /* The function descriptor entries as dumped by the assembler are not sorted on PCs. */ @@ -738,26 +735,26 @@ output_sframe_internal (void) out_four (num_fdes); /* Number of FDEs. */ out_four (num_fres); /* Number of FREs. */ - /* FRE sub-section len. */ + /* Size of FRE sub-section. */ exp.X_op = O_subtract; exp.X_add_symbol = end_of_frame_section; exp.X_op_symbol = start_of_fre_section; exp.X_add_number = 0; - emit_expr (&exp, addr_size); + emit_expr (&exp, sizeof_member (sframe_header, sfh_fre_len)); - /* Offset of Function Index sub-section. */ + /* Offset of FDE sub-section. */ exp.X_op = O_subtract; exp.X_add_symbol = end_of_frame_hdr; exp.X_op_symbol = start_of_func_desc_section; exp.X_add_number = 0; - emit_expr (&exp, addr_size); + emit_expr (&exp, sizeof_member (sframe_header, sfh_fdeoff)); /* Offset of FRE sub-section. */ exp.X_op = O_subtract; exp.X_add_symbol = start_of_fre_section; exp.X_op_symbol = end_of_frame_hdr; exp.X_add_number = 0; - emit_expr (&exp, addr_size); + emit_expr (&exp, sizeof_member (sframe_header, sfh_freoff)); symbol_set_value_now (end_of_frame_hdr); symbol_set_value_now (start_of_func_desc_section); 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; } From patchwork Fri Feb 28 13:32:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Remus X-Patchwork-Id: 107233 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 12818385840B for ; Fri, 28 Feb 2025 13:35:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12818385840B 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=EUtpWHd8 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 006B53858C30 for ; Fri, 28 Feb 2025 13:32:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 006B53858C30 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 006B53858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740749532; cv=none; b=NWmqr/aTrU9TofnlQak7SJ+/oJXgaE/lG98pxWQj1MntOndcw3HsTqe/y3D+xAlYMIPc27P3xMNEfok+qW/M4M7x7aOtxqIAR7zIRLeq+zdY+5okr0tkaZBXAQjM3NNdnU8uk8noSDJmp3DYWzmpNkMn8q9oX3VO4wIe9w9uZFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740749532; c=relaxed/simple; bh=QRe4ZoxgRuN3RZ0rWuk04hhwwtGf7MRw0/Mbih1I4wg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZH9/KGBvBqgy9H0aZCD38H5/Ju5cheiDWesI1YUzzPYDLTiUXzW8Y1n21WgcFKojuH+hZhi0KPZakFzQO3c8uO9e0MFS+Ez/8E4U2fXSiCKnLWaTw/mq4gchzyJeLhFJZAmav9iRTUppLUPug+6SZHxySRvSr3o+NDtRdKzRA9U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 006B53858C30 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51S7WqrE025557; 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=D8/rFv0ofefCo1YiB ZOcreO2o+qvhgR+t7vQGLkb1y4=; b=EUtpWHd87q5FIqkvSBB6IhsiPE4n6xhLq cXtVGifd6ojw89Tj2apld+KFo5Ur9yaKA96jG+w+byMbFJtBOXihGjZUR16Tuh7w ThLQEUKMqx1ICnSVJeQL3mCN+MUgBDDw++Jhev1e3GW+cgPD153uIVAyC3NH+7Xj QTmHT/nAaFRo2IIhDnGmyvh7nmthELp/GAYGc8/CpIqDAD8zZqvWf/saKx+wA+jw icvQHPhECecJasY6MJfbqKWzNAIEcS4qvKy+pgdWxIfHiBkggVYVhldEaUFdfjro PexJsSNm+AT9rZsEMC8tuZ3hmqnE8MviLksICOdl426ZP804E/uqA== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4538uq1md3-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 (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51SC7B4d002567; Fri, 28 Feb 2025 13:32:08 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 44yu4k6b12-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 51SDW5TJ15925540 (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 4D25620040; 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 2F62D2004B; 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:05 +0000 (GMT) From: Jens Remus To: binutils@sourceware.org, Indu Bhagat Cc: Jens Remus , Andreas Krebbel , Jan Beulich Subject: [PATCH v3 3/3] sframe: FDE function start address relative to SFrame section Date: Fri, 28 Feb 2025 14:32:02 +0100 Message-ID: <20250228133203.1470383-4-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-GUID: BVYL1DtwrzxLUX6TzGZ9SuQlWnbH62pl X-Proofpoint-ORIG-GUID: BVYL1DtwrzxLUX6TzGZ9SuQlWnbH62pl 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 mlxscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 suspectscore=0 priorityscore=1501 spamscore=0 malwarescore=0 adultscore=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 SFrame FDE sfde_func_start_address field is specified to contain the function offset from .sframe section. This is true in executables and shared libraries after final link. In assembler generated objects it contained the function offset from SFrame FDE (using a PC-relative relocation) and the linker performed a respective fixup when merging the .sframe sections. Change the assembler to emit sfde_func_start_address relative from the .sframe section. Change the linker to only apply the output .sframe section offset as fixup when merging the sections. While at it enhance the comments in the code, fix a typo in SFD_INFO, and remove commented out debugging code. gas/ * gen-sframe.c (output_sframe_internal): Create temporary symbol for start of SFrame section. Pass it to output_sframe_funcdesc. (output_sframe_funcdesc): Emit SFrame FDE function start address as offset from SFrame section instead of FDE. bfd/ * elf-sframe.c (_bfd_elf_merge_section_sframe): Fixup SFrame FDE function start address by adding output .sframe offset. Enhance comments. (sframe_decoder_set_func_reloc_index): Correct typo in comment. Signed-off-by: Jens Remus --- Notes (jremus): Changes in V3: - New patch. Replaces V2 patch ("sframe: Enhance comments and documentation on FDE function start address"). bfd/elf-sframe.c | 44 ++++++++++++++++++++++++++------------------ gas/gen-sframe.c | 11 +++++++---- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c index 97e007345152..83611921e015 100644 --- a/bfd/elf-sframe.c +++ b/bfd/elf-sframe.c @@ -93,7 +93,7 @@ sframe_decoder_set_func_reloc_index (struct sframe_dec_info *sfd_info, sfd_info->sfd_func_bfdinfo[func_idx].func_reloc_index = reloc_index; } -/* Initialize the set of additional information in CFD_INFO, +/* Initialize the set of additional information in SFD_INFO, needed for linking SEC. Returns TRUE if setup is done successfully. */ static bool @@ -446,27 +446,28 @@ _bfd_elf_merge_section_sframe (bfd *abfd, { if (!(sec->flags & SEC_LINKER_CREATED)) { - /* Get relocated contents by reading the value of the - relocated function start address at the beginning of the - function descriptor entry. */ + /* Offset to SFrame FDE sfde_func_start_address from input + .sframe section. It contains the relocated function + offset from input .sframe section. */ r_offset = sframe_decoder_get_func_r_offset (sfd_info, i); } else { /* Expected to land here when SFrame stack trace info is - created dynamically for the .plt* sections. These - sections are expected to have upto two SFrame FDE entries. + created dynamically for the .plt* sections. These .sframe + sections are expected to have upto two SFrame FDEs. Although the code should work for > 2, leaving this assert here for safety. */ BFD_ASSERT (num_fidx <= 2); - /* For the first entry, we know the offset of the SFrame FDE's - sfde_func_start_address. Side note: see how the value - of PLT_SFRAME_FDE_START_OFFSET is also set to the - same. */ + /* Offset to the first linker-generated SFrame FDE (for PLT0) + sfde_func_start_address from input .sframe section. It + contains the PLT0 offset from FDE. NB: See how it is set + using PLT_SFRAME_FDE_START_OFFSET. */ r_offset = sframe_decoder_get_hdr_size (sfd_ctx); - /* For any further SFrame FDEs, the generator has already put - in an offset in place of sfde_func_start_address of the - corresponding FDE. We will use it by hand to relocate. */ + /* Offset to any subsequent linker-generated SFrame FDE (for + PLTn) sfde_func_start_address from input .sframe section. + It contains the PLTn offset from PLT0. We will use it by + hand to relocate. */ if (i > 0) { pltn_r_offset @@ -475,15 +476,22 @@ _bfd_elf_merge_section_sframe (bfd *abfd, } } - /* Get the SFrame FDE function start address after relocation. */ + /* Get the SFrame FDE sfde_func_start_address value after + relocation. In object files it is the function offset + from input .sframe section. For linker-generated FDE + it is the PLT0 offset from FDE. */ address = sframe_read_value (abfd, contents, r_offset, 4); + /* For linker-generated PLTn add the PLTn offset from PLT0. */ if (pltn_reloc_by_hand) address += sframe_read_value (abfd, contents, pltn_r_offset, 4); - address += (sec->output_offset + r_offset); - - /* FIXME For testing only. Cleanup later. */ - // address += (sec->output_section->vma); + /* Fixup by adding the output .sframe section offset. For + linker-generated FDE additionally add the first FDE + offset from input .sframe section. */ + if (!(sec->flags & SEC_LINKER_CREATED)) + address += sec->output_offset; + else + address += (sec->output_offset + r_offset); func_start_addr = address; } diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c index dd5fb25e367f..b50c6613c5a6 100644 --- a/gas/gen-sframe.c +++ b/gas/gen-sframe.c @@ -607,7 +607,8 @@ output_sframe_row_entry (symbolS *fde_start_addr, } static void -output_sframe_funcdesc (symbolS *start_of_fre_section, +output_sframe_funcdesc (symbolS *start_of_sframe_section, + symbolS *start_of_fre_section, symbolS *fre_symbol, struct sframe_func_entry *sframe_fde) { @@ -618,10 +619,10 @@ output_sframe_funcdesc (symbolS *start_of_fre_section, dw_fde_start_addrS = get_dw_fde_start_addrS (sframe_fde->dw_fde); dw_fde_end_addrS = get_dw_fde_end_addrS (sframe_fde->dw_fde); - /* Start address of the function. */ + /* Start address of the function (function offset from .sframe section). */ exp.X_op = O_subtract; exp.X_add_symbol = dw_fde_start_addrS; /* to location. */ - exp.X_op_symbol = symbol_temp_new_now (); /* from location. */ + exp.X_op_symbol = start_of_sframe_section; /* from location. */ exp.X_add_number = 0; emit_expr (&exp, sizeof_member (sframe_func_desc_entry, sfde_func_start_address)); @@ -672,6 +673,7 @@ output_sframe_internal (void) expressionS exp; unsigned int i = 0; + symbolS *start_of_sframe_section = symbol_temp_new_now (); symbolS *end_of_frame_hdr; symbolS *end_of_frame_section; symbolS *start_of_func_desc_section; @@ -763,7 +765,8 @@ output_sframe_internal (void) i = 0; for (sframe_fde = all_sframe_fdes; sframe_fde; sframe_fde = sframe_fde->next) { - output_sframe_funcdesc (start_of_fre_section, + output_sframe_funcdesc (start_of_sframe_section, + start_of_fre_section, fre_symbols[i], sframe_fde); i += sframe_fde->num_fres; }