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