From patchwork Sat Mar 8 07:38:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 107538 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 7609C3858C98 for ; Sat, 8 Mar 2025 07:41:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7609C3858C98 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=EY9KkBBJ; dkim=pass (1024-bit key, unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=rbDxKrEU X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 236343858D28 for ; Sat, 8 Mar 2025 07:39:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 236343858D28 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 236343858D28 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1741419562; cv=pass; b=ZzF4jCKFUDiW5pLXI2STscJQAxeXssohqsJmooqAGACjQ9ho34qWnsppNzmEDL0QB047PMz8yRECsgOoKd5ZbFB+dvIx4G6mreqEJKQWSKLKJjHcrsnEeepIkLBg+mu0MZrukER6+S5CXjEWz82fAM2QNH5O8ysr4+2wS/GFQVE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1741419562; c=relaxed/simple; bh=Ra22/OuwnWDJE9zN1TMMfIQhedgMW1Zgn/e7Zd8xf1Q=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=kxqb+W/6AV2A4S1m40aHrrDgfpVZD5JAjsJTs/yJcXoj09KRg5YNzuBt5P/V+LE7PCvPEecor9R/t3VKRJjlwW3viIbpbUSQZkOhy9jW+tiTP3A5bI51mpDbJ13vgV7pIPlFciPJFHuqv5+qo5yrHiHcMZLIcSVdRXFeAhNYpmM= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 236343858D28 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5286namm029657; Sat, 8 Mar 2025 07:39:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=aRmngLYvaPYjsUCn8ESJtMHqGA8ZxwgnnshylvcxLQk=; b= EY9KkBBJYjo7c7YADLnVrZQgxZwr2lB/Tfx0uqTpVECLW01KKkZ3JkYSaVyq2WyN R4JxzIsmqQ7SMZ9NeYfiZHT6Rubrl0qDPYnKYmLGnZ3TR7wZLb6SVAvh/u6nZntq FJHAigMbq0GJA/4KFC3Mb+1HJAaiSRpMnxgvqOPMFDs8RXfl5V/PVv0vJ7IdWC41 N4rHVfkLZipcd/Gvh+90NkuoRFxu6W0bQPtIAKXduLuNNHvdN4U+aTrBDZwXoKJP HhVkGtli+1fC8DvXteJ2gd7Mfh5XuEJyXVp7X6/y28k7YrhTydG7oYFuqYYxcLp9 HtyUtZr+bDQ+O+ldRkeOjQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 458cac85aw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 08 Mar 2025 07:39:17 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 52869V4N030901; Sat, 8 Mar 2025 07:39:17 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2176.outbound.protection.outlook.com [104.47.56.176]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 458gcj9c7y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 08 Mar 2025 07:39:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BYP0RANVjC/RXoknu8YpEwxiFNzgx8xSjYRiWsDdnvDbQ6s447qRwdNHZayTmDlmO5nuasRz+uidMEA6O4jbwMBdaUDyzSroSNiUEFpqaAYOBtR+B5prclzF0J/gN/AVZpgIdcAcq7vBYZVJicDOS3NYF4Tx7FMCUDGP54fGpPsjqRgQgVZnmSeCYNRCIGA+fELhARc+3mkswqwxaj/W/fCg1rvczlpLshPMxFGUpHEeHYpuXNu2JiUxx9efb5MsjgRltd3+dVAR/jvr4Ck0NtDzhndVNO4F5Yv/WXmKZwvLpEAo1FzZ5Tu4AndKUBi97pKYOX38xyZekyW1jiYUZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aRmngLYvaPYjsUCn8ESJtMHqGA8ZxwgnnshylvcxLQk=; b=Bz7lrDN1YIplZUNkQb8FtuzMfwLCyNEImJC1jHCk5xDUPlyC1JAToBMxjR917lXXmATGxSMhg/v3MpbYT/tNjG7H9YjiyIEUjfWVYkq5loP9ywfIkY5h3k2KPMnXeskS/mY47Ze7AOvO6dCF9Dg7VQzYxgtIh4kJlKjKqAkZOs+raF1dU/ztJ2GuVsWE/iknP64NJEigVQCN8QwVUUh/lzoDObWoXqMot3BNAhkZQfOTIBkwKAQJcuKsLtrlngYe4Ug29H8PpiXK9Ff0Znt415GGvbu8jtqhoJVszxrEV+Qf+wYBog3s4XvNoCUfEBQnlloFjzQy7tmtuY7KwzqP0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aRmngLYvaPYjsUCn8ESJtMHqGA8ZxwgnnshylvcxLQk=; b=rbDxKrEUm/BonlT+YvFY9RoV5GwfYN51Ke/bMlC9FzDw35CvaP9U3D11rLV/b57iX9ZIPVgBLcKRNWK2jQ678OcmQlN0Al3iwaY8nyywrPgzWvYbT5oA330giHCeacq+0BijH2Pz8pDmIEk1i96WdU5S5AFsgj6lLr9q/5x82MQ= Received: from SA1PR10MB6365.namprd10.prod.outlook.com (2603:10b6:806:255::12) by PH0PR10MB7080.namprd10.prod.outlook.com (2603:10b6:510:28c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.24; Sat, 8 Mar 2025 07:39:15 +0000 Received: from SA1PR10MB6365.namprd10.prod.outlook.com ([fe80::81bb:1fc4:37c7:a515]) by SA1PR10MB6365.namprd10.prod.outlook.com ([fe80::81bb:1fc4:37c7:a515%5]) with mapi id 15.20.8511.017; Sat, 8 Mar 2025 07:39:15 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: nickc@redhat.com, amodra@gmail.com, jbeulich@suse.com, jremus@linux.ibm.com, Indu Bhagat Subject: [RFC 3/4] ld: bfd: sframe: fix incorrect r_offset in RELA entries Date: Fri, 7 Mar 2025 23:38:52 -0800 Message-ID: <20250308073853.78738-4-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250308073853.78738-1-indu.bhagat@oracle.com> References: <20250308073853.78738-1-indu.bhagat@oracle.com> X-ClientProxiedBy: MW2PR16CA0031.namprd16.prod.outlook.com (2603:10b6:907::44) To SA1PR10MB6365.namprd10.prod.outlook.com (2603:10b6:806:255::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR10MB6365:EE_|PH0PR10MB7080:EE_ X-MS-Office365-Filtering-Correlation-Id: 313719d2-c27f-4f1b-c20b-08dd5e145362 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|366016|10070799003; X-Microsoft-Antispam-Message-Info: ylrgIevuyawTx5wBO3EIKGTW4/G8hjk37jDYo5lfhcQG60hecf5ufOD+LC4pBjFSLWlX0l5VVn1E2IKJ55tXpV4mUxglWDdAkBTuGaTTqYiGBfeF+bLFOsDOa2axPyFumHFpxpex2c7wLb1Y4G5vDHqJlNT5jJJueKm/OWIn9mHucBI4aSswnm+a9tnvWyENonchjIGeo+Ujdtlz4Mwjt0ciR04GQxNtAO6ZYhQC6xVkId0/8XzQlAxGzkwvLpF679grrZaOpsfRJvdG0P8u0DLRfzRH41fe2yIkL7Q3S6fQ8ENHwCVIbeHdHsh3JaQ0a1hBle0fwWvTW2UJJQyV2zM9RaGL8Pyeypgi47DLEGcruhBswpeoQ+fBynZFzI6Gj/Gjdhul2QgSFcfrVzKVWGOm6BJ7706xhKlQiVPAeMMDQg1/jnWWq3/X5T2JnboSMqPOseLOn8olv/Tv+zB1l1D9eupNnsC/aaaoZJhLQ7A3ZNprx0ken8c7XM+Pg/FtWBAVdoCxgMs/gIucdSLBU5fe/DWeKqXo17oaf19IgYdwwhSQ5mZC5B1Zd0p06M8fMwlpqPD4Uq1dY08hDTjWNZfQ4Ajc2qAT0y1QhpWk1BytA8biDoQoBAjACIyP/wXI4hIiigL1psHFMR2iaF9irCOrM0cCNpnt7WyOlPSwkzL1cVHeL4O4h7PXBmO8KIy76PuHKrHzkmQC7oM6huAPNWJ06B4gP1u+S9V3tmSs/2TJqqxLouyQnNZqpefA4ecZ/IgP0QFK33CuSKz5hkkGeOeOASwyVUjGv9jho/3TK4WIfs+5XGW1Fh5TZy2V5xapJ+/K8GNm07cvknq76QV7uUBb1igVRu2TGBRYpSV1sX61kd8bzLfwSCJPobYtUZa2HobLPpRRab+o8g02Wk5EcfqqqeKfgPFVdMXrgUtZROAJMOd5sc/LC20E7+STQxS3gZ7ArzuAfKolqKd4dOjGBo4zz8ifjA+Iz16i6vQsxNSyaVk9QrYRxgrAUGWc5Q6UwNe3XZhH2q9GlWNmOCG3t4zI+ufDpPMJ1tDgf3zk+XyBI0f7gnpRycw9NOiBea1LFitojn6pfFEdJ6+YzwhuCo09CTDwdCXSNYYcfeo6dqa/TGrlcPQ21q0CrgQIvbLBij3RerFfSs6+/Ok/SzIAw3ofN35TDMGnyj3GaHuLbk/xeE4eN7FtwnHbA7WWVXOdoAM64wuiN3aMgAKHgz9acYvAby1ZMxeevgXmnYB1t/SMZYik4OCcORIi1vfUw+cQoEVllM33gS66erJE1wtwFsBTavoOZvOm21lJ1fjR7BJ2r9e+VE6HRvOGYSWA2LtN+0uwR9z10meVzlVYmxIq1S1auZ3okazGvfkg3fGY8kf9BKmhNJjLaFKeaPlWQytH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR10MB6365.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(10070799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QUKB1sZd/x4PlJDTfJe9Bse1lqepU9N7E4fSiTAD32A0FdXJ+yj6Lxga0/N3gP9VJcPezG6sndVFZlv56qCcDs8yxedtH1NMEbfCMEgpRqoiEOvuI7ueYh0k5e00af7rHyMc10c5Z5pElHHYBVRzj8tDrORQn1Y1oMJwapRMz/577wukVcgDHXaUcssTBfEjjmr250Re8gs/gLPoyXQ4HIn5D1DMGZ22B6IOS7JVJamSM/FB1DTFrvAipTrWISqRgJZZkSQTDvFdKcLb6Qmu62Xa4OFNsoYad/utfqC3PePLyn17V23R6oE9KawCoWn//JOaj+Va3PiP2MkUscFMUfYbBk2HyMA7hsb1VvE2dzrPZacJLDG8BMyELicazSabNHVcsRzCbnpLG237jSY+jBWla5hLN1U06zho+8l7lur+eB4rUKbvhJ9yVVhspT3GpRnsmjjR2J1bPgD/ohsjzKmbpZRqLySSSeYdEWuXUHbP7cFUn9JGwyF50VEZv6BLCY8/We/mACaag3/knvOHWa7wpMPss+HjubIVWz4pnmtwSO7mWARLgZFNxkqSc6GqUqs+lbjX/I+Ib5pd8AJRgwiZag+IUl7htbK/rM/sQX9BYFvXP+mp29gm1V2jbquJXIBHF+UELFAV6cRk8O9dw+pDSejNBt7WmlRW2Bzp8TA2LeStt1ahIM6/MMDizIeBF9WLPPY7mWIGgRh3SAKg2oMTnWqP/oMYlzjl5QKqY0crrIJL4GtT+xQfX6oD/NN5xyQd8fcA7mk/DArVMs6NU7H8khKoSo5/7DNLeLNfTwDnEz1xFyOsiDtIhk5u5wZLqDSPBROxhOFgKxC5ggTW6MHt+8Nm4V++ETLIJGI50UuV8IbNAw5obWUXW7N17vNq2Dd8/En8ORrwks1tzxHJgAtLp+PoBqgj2Xgjt9Ew0Go06W4EiV/E8frROZoIH1iR7rypevvBbPS3qYI/z7oCMtrrE6nVAHafxer703zneR6g3hfNcvIzZsVxHc74LYa6VinaAEktO7AuAjloaxllm3wuQjYooMsz49XwYch1DPLj30MOHuKGgOPzX3Wp0tK2e2XxDLtaaiIXF17exgvL0+4ZwkW7/nsZ8wL89j3SFstJQ2ee2DO+SYzSLRxyUXj6Xr9Sn4qIGLOIOffdyo/9wjQBJvSMEVherMY0jovujqktS+6u34JEOLYLWDDuxl3QmFmlqTwUtfO5ymnchTgmPelnZP6Inc97xAj2oRNK3wDsyqN2KogrL20fxiilmdLBhJYMW7bqE1TrSxkB7YdqrVpoP4Kfpuz8ADojC7Mk8fvlCjsX94XkvV3sHm9tqy2wmBClfHfhi8395DpXh07tFVkC/pBv/l2AcD05gHmFy931Bd34UpWPfj9mujnHAySol6V5hPODsCPe9pzfpqGgMrJ3LKMZ/PbeIhcfy0r50eVROwIT3foB6rAwn9wbLRmk2gcA7LJKuSaJ/FGFj5S/IDAyf8yAOcH6J42mURUzaKl3MfVukQf1/fzEQQWqZSYlwm5eXKrTuMavRB14GEVeXtMw02pqgc6A77Wd4AuVJOc3WmdQ7oMhzPDjXMpo9V9SEdPhkFe/jQv+FJmoJ6/A7mP2l/NrRljBjWzw14Nr7RA= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: aMHQCMZD/Y3ldeinxO2Kjs6Ekx80lvtthtfgUuYZ7FC5dKjUyNTC5Z70KUw3X+I0PazHkJByGmUPn6X9Roj4PPhheyl77t/vJQnNafJ8se4y32yOmgzsFaLP8jg9zbVQhiC/7OdI7k/+H6Jt7AzCOkmZOooR1zmjlCMtxzZJpi/6y24SJXlRLb9UG4osIKXxWPkp0X69Hhnm5caQgeKRFMB2JQGHP9QIEVZ75XS18Zqv1l7N7w2bjVfff4ddA693yFysubGemsY5gttS5jrRLtSVkSNEADm0qsvMXnfgVdRwc3K69c//VIjaoW007lnX8EAil084MEPamOocHCovhCCMVbwcGXzScq2/Eyf8+6pmeHdrZATmgjz+sVqBSVhP9OWVEjA/Ns5GNhLtr55cKXVMIhtaAwpVo29JR/TPK9TDSkZL4l192nrd9ILKnYOiio63utMt9rQ9kpgPjBlONQlkljdqUpVayRo0MpjY/ZyvTyQ3IGYSoXXM/nAOPE9vSMmkEvWI1mBKWwp3loBZNkyeLFbDXKWStkVeFjDsCbFjFpf4etAyKt0Y1qYC8wec9Q6xiWaYYBEDX8oRVKPVT2UknIdkSicuabb1fD4ilHw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 313719d2-c27f-4f1b-c20b-08dd5e145362 X-MS-Exchange-CrossTenant-AuthSource: SA1PR10MB6365.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2025 07:39:14.9669 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DHKxLL2+j8lP65WSGQMFFCqDVSOBfjq3SfHMNP1lt/6fB2ZWYeHt0io15T7PD6lkAItlVpeUGDHmDHxSuMl9Cg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB7080 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-08_03,2025-03-07_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502100000 definitions=main-2503080052 X-Proofpoint-ORIG-GUID: 8bzTKrOv4IyE6Y_a35i_FFZtjcf1VqUh X-Proofpoint-GUID: 8bzTKrOv4IyE6Y_a35i_FFZtjcf1VqUh X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 PR/32666 Incorrect .rela.sframe when using ld -r Input SFrame sections are merged using _bfd_elf_merge_section_sframe (), which clubs all SFrame FDEs together in one blob and all SFrame FREs in another. This, of course, means the offset of an SFrame FDE in the output section cannot be simply derived from the output_offset of the sections. Fix this by providing _bfd_elf_sframe_section_offset () which returns the new offset of the SFrame FDE in the merged SFrame section. Unlike EH_Frame sections, which also use the _bfd_elf_section_offset (), to update the r_offset, SFrame sections additionally need : if (o->sec_info_type != SEC_INFO_TYPE_SFRAME) irela->r_offset += o->output_offset; because information in SFrame and EH_Frame sections is organised differently. In case of SFrame, the SFrame FDE will not simply sit at location "o->output_offset + offset of SFrame FDE in o". Recall that information layout in an SFrame section is as follows: SFrame Header SFrame FDE 1 SFrame FDE 2 ... SFrame FDEn SFrame FREs (Frame Row Entries) Note how the SFrame FDEs and SFrame FREs are clubber together in groups of their own. Taking the above into account, the correct offset has already been calculated via _bfd_elf_section_offset (). So for SFrame sections, the r_offset of the RELA should not be offset further by the o->output_offset (offset of the input SFrame section in the output SFrame section). Add a new enum to track the current state of the SFrame input section during the linking process (SFRAME_SEC_DECODED, SFRAME_SEC_MERGED) for each input SFrame section. This is then used to assert an assumption that _bfd_elf_sframe_section_offset () is being used on an input SFrame sections which have not been merged (via _bfd_elf_merge_section_sframe ()) yet. bfd/ * elf-bfd.h: New declaration. * elf-sframe.c (_bfd_elf_sframe_section_offset): New definition. * elf.c (_bfd_elf_section_offset): Adjust offset if SFrame section. * elflink.c (elf_link_input_bfd): RELA offset adjust be done conditionally. ld/testsuite/ * ld-x86-64/x86-64.exp: New test. * ld-x86-64/sframe-reloc-1.d: New test. --- bfd/elf-bfd.h | 11 +++++ bfd/elf-sframe.c | 63 ++++++++++++++++++++++++- bfd/elf.c | 3 ++ bfd/elflink.c | 6 ++- ld/testsuite/ld-x86-64/sframe-reloc-1.d | 34 +++++++++++++ ld/testsuite/ld-x86-64/x86-64.exp | 1 + 6 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-x86-64/sframe-reloc-1.d diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 5903d857faa..f62570919d5 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -503,12 +503,21 @@ struct sframe_func_bfdinfo unsigned int func_reloc_index; }; +/* Link state information of the SFrame section. */ +enum sframe_sec_state +{ + SFRAME_SEC_DECODED = 1, + SFRAME_SEC_MERGED, +}; + /* SFrame decoder info. Contains all information for a decoded .sframe section. */ struct sframe_dec_info { /* Decoder context. */ struct sframe_decoder_ctx *sfd_ctx; + /* SFrame section state as it progresses through the link process. */ + enum sframe_sec_state sfd_state; /* Number of function descriptor entries in this .sframe. */ unsigned int sfd_fde_count; /* Additional information for linking. */ @@ -2540,6 +2549,8 @@ extern bool _bfd_elf_discard_section_sframe (asection *, bool (*) (bfd_vma, void *), struct elf_reloc_cookie *); extern bool _bfd_elf_merge_section_sframe (bfd *, struct bfd_link_info *, asection *, bfd_byte *); +extern bfd_vma _bfd_elf_sframe_section_offset + (bfd *, struct bfd_link_info *, asection *, bfd_vma); extern bool _bfd_elf_write_section_sframe (bfd *, struct bfd_link_info *); extern bool _bfd_elf_set_section_sframe (bfd *, struct bfd_link_info *); diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c index a5958464536..9c7bf099649 100644 --- a/bfd/elf-sframe.c +++ b/bfd/elf-sframe.c @@ -213,10 +213,11 @@ _bfd_elf_parse_sframe (bfd *abfd, /* Decode the buffer and keep decoded contents for later use. Relocations are performed later, but are such that the section's size is unaffected. */ - sfd_info = bfd_alloc (abfd, sizeof (*sfd_info)); + sfd_info = bfd_zalloc (abfd, sizeof (*sfd_info)); sf_size = sec->size; sfd_info->sfd_ctx = sframe_decode ((const char*)sfbuf, sf_size, &decerr); + sfd_info->sfd_state = SFRAME_SEC_DECODED; sfd_ctx = sfd_info->sfd_ctx; if (!sfd_ctx) /* Free'ing up any memory held by decoder context is done by @@ -507,12 +508,72 @@ _bfd_elf_merge_section_sframe (bfd *abfd, } } } + sfd_info->sfd_state = SFRAME_SEC_MERGED; /* Free the SFrame decoder context. */ sframe_decoder_free (&sfd_ctx); return true; } +/* Adjust an address in the .sframe section. Given OFFSET within + SEC, this returns the new offset in the merged .sframe section, + or -1 if the address refers to an FDE which has been removed. + + PS: This function assumes that _bfd_elf_merge_section_sframe has + not been called on the input section SEC yet. Note how it uses + sframe_encoder_get_num_fidx () to figure out the offset of FDE + in the output section. */ + +bfd_vma +_bfd_elf_sframe_section_offset (bfd *output_bfd ATTRIBUTE_UNUSED, + struct bfd_link_info *info, + asection *sec, + bfd_vma offset) +{ + struct sframe_dec_info *sfd_info; + struct sframe_enc_info *sfe_info; + sframe_decoder_ctx *sfd_ctx; + sframe_encoder_ctx *sfe_ctx; + struct elf_link_hash_table *htab; + + unsigned int sec_fde_idx, out_fde_idx; + unsigned int i, sfe_num_fdes; + + if (sec->sec_info_type != SEC_INFO_TYPE_SFRAME) + return offset; + + sfd_info = (struct sframe_dec_info *) elf_section_data (sec)->sec_info; + sfd_ctx = sfd_info->sfd_ctx; + + BFD_ASSERT (sfd_info->sfd_state == SFRAME_SEC_DECODED); + + /* Identify the index of the FDE (at OFFSET) in the input section. */ + sec_fde_idx = ((offset - sframe_decoder_get_hdr_size (sfd_ctx)) + / sizeof (sframe_func_desc_entry)); + + if (sframe_decoder_func_deleted_p (sfd_info, sec_fde_idx)) + return (bfd_vma) -1; + + htab = elf_hash_table (info); + sfe_info = &(htab->sfe_info); + sfe_ctx = sfe_info->sfe_ctx; + sfe_num_fdes = sframe_encoder_get_num_fidx (sfe_ctx); + + /* The index of this FDE in the output section depends on number of deleted + functions (between index 0 and sec_fde_idx), if any. */ + out_fde_idx = 0; + for (i = 0; i < sec_fde_idx; i++) + { + if (!sframe_decoder_func_deleted_p (sfd_info, i)) + out_fde_idx++; + } + /* The actual index of the FDE in the output SFrame section. */ + out_fde_idx += sfe_num_fdes; + + return (sframe_decoder_get_hdr_size (sfd_ctx) + + out_fde_idx * sizeof (sframe_func_desc_entry)); +} + /* Write out the .sframe section. This must be called after _bfd_elf_merge_section_sframe has been called on all input .sframe sections. */ diff --git a/bfd/elf.c b/bfd/elf.c index 3f8bc838bfb..3d65486ad5b 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -13491,6 +13491,9 @@ _bfd_elf_section_offset (bfd *abfd, case SEC_INFO_TYPE_EH_FRAME: return _bfd_elf_eh_frame_section_offset (abfd, info, sec, offset); + case SEC_INFO_TYPE_SFRAME: + return _bfd_elf_sframe_section_offset (abfd, info, sec, offset); + default: if ((sec->flags & SEC_ELF_REVERSE_COPY) != 0) { diff --git a/bfd/elflink.c b/bfd/elflink.c index 13993527e3e..895fbb0206e 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -11974,7 +11974,11 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd) continue; } - irela->r_offset += o->output_offset; + /* All SFrame FDEs from input sections are clubbed together + in the beginning of the output section. RELA offsets are + already up to date. PR ld/32666. */ + if (o->sec_info_type != SEC_INFO_TYPE_SFRAME) + irela->r_offset += o->output_offset; /* Relocs in an executable have to be virtual addresses. */ if (!bfd_link_relocatable (flinfo->info)) diff --git a/ld/testsuite/ld-x86-64/sframe-reloc-1.d b/ld/testsuite/ld-x86-64/sframe-reloc-1.d new file mode 100644 index 00000000000..308f94bd76c --- /dev/null +++ b/ld/testsuite/ld-x86-64/sframe-reloc-1.d @@ -0,0 +1,34 @@ +#as: --gsframe +#source: sframe-foo.s +#source: sframe-bar.s +#objdump: --sframe=.sframe +#ld: -r --no-rosegment +#name: SFrame simple link - relocatable + +.*: +file format .* + +Contents of the SFrame section .sframe: + Header : + + Version: SFRAME_VERSION_2 + Flags: SFRAME_F_FDE_SORTED + CFA fixed RA offset: \-8 + Num FDEs: 2 + Num FREs: 8 + + Function Index : + + + func idx \[0\]: pc = 0x0, size = 53 bytes + STARTPC +CFA +FP +RA + + 0+0000 +sp\+8 +u +f + + 0+0001 +sp\+16 +c-16 +f + + 0+0004 +fp\+16 +c-16 +f + + 0+0034 +sp\+8 +c-16 +f + + + func idx \[1\]: pc = 0x35, size = 37 bytes + STARTPC +CFA +FP +RA + + 0+0035 +sp\+8 +u +f + + 0+0036 +sp\+16 +c-16 +f + + 0+0039 +fp\+16 +c-16 +f + + 0+0059 +sp\+8 +c-16 +f + diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 01d6459b5d7..eed06af80df 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -566,6 +566,7 @@ run_dump_test "pr32591-4-x32" if { ![skip_sframe_tests] } { run_dump_test "sframe-simple-1" + run_dump_test "sframe-reloc-1" run_dump_test "sframe-plt-1" run_dump_test "sframe-ibt-plt-1" run_dump_test "sframe-pltgot-1"