From patchwork Fri Apr 11 11:34:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu-Ianculescu X-Patchwork-Id: 110250 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 C2B1E3831E32 for ; Fri, 11 Apr 2025 11:37:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2B1E3831E32 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=eKYxKcpB; 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=kz7v+Pp0 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 3417B3831E34 for ; Fri, 11 Apr 2025 11:35:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3417B3831E34 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 3417B3831E34 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744371311; cv=pass; b=t2w0c7k/VsN3Xj3lTNswlXtlsxor5DzrKilrKNoCFmL1PIwtB8dWHaOhYQu2AgqVdiAjUupOm+cCuXMfF78XEP7QTSrHojEsRf42mS2RUAICyBktDoWM3rcyl9pzKbZpLIjUwgSlW/R1FX8BGw7EMg9KCSpLtrvSbKBbckqYyKc= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744371311; c=relaxed/simple; bh=p34GiQLT1UZPfzLPONuKPQLPN2+l5LyHAXpYIL17XEs=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=WFqKrApNrcFt0czzlKLRMEYYdUOh7JiZqYfpybq/7Hz89+9RKiivxuRNoJJcm8D6HxF6+S7mR3gpc4KXEjqiysp9EnbOSVJl2437rSEcBpoiMmPR4X4M4S/46eAEKHhMFlrEx1IPdul3FDywhJ2EW0xWHbV1a5EdOpf3unPIQbI= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3417B3831E34 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53BBCUCR008134; Fri, 11 Apr 2025 11:35:07 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=aG+pp8NVcv3LOHH5U6Bl6EteTqcA5d90Wgi6XaCXHlA=; b= eKYxKcpB/P6xZJFDqosmITHdkAl/6AEZpLEcEVzaGyar6JZP5y/wnLlhMKmRTMO1 jPoYEECnWp1jiIVBqq/Ll/0hmZ+0o4F2l7ZA2E32NbkjOp84sa/MLs0buRjOfK6b bqz7PvJwpB0L3A9FlnClOL30uhYOLoZ3ojmxaEvjm70rJ+vDLs+4us5OIjaPfAfZ L92/qibOHmK1slpw7r2y02yzn3CUg16M28CzMiqmSBPgej9B08zicWEXfRoRaY31 WkKnmso7g1NrBKYX+vrgvMW9zxz5nCJ7cQsHpBTO7KKes7I0qYzYavVYlquDuYql 7dsZ0KMWYKsPfLSBfuc4iQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45y20dg10c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:06 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53BB1uOQ001293; Fri, 11 Apr 2025 11:35:06 GMT Received: from cy4pr02cu008.outbound.protection.outlook.com (mail-westcentralusazlp17011027.outbound.protection.outlook.com [40.93.6.27]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 45ttydj5c5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qekWeShluZEyVUoFMcstr+xkWZaFwp6uMixhkRdV9tmOg2/Z3utsyLJX0CQx9mgz4mswXZJndfPe4zMT9HklS9SDtmdTFb1ReI4Uq8MRiNJduXWV1nzdcuMY1mJyVWDuQZWgyaIubb1ewvZ6hehG2YK4b6wfWD7j+0enkR7t+qN7G9gP1zs4RHsSKWvNmxlW+SqSq2T8FUfwScnUiBWIcYChAe1y8VGbrGi12NlhMh0rzuAQk+MEA8+bxvJTWaG3lyTwvkn6XI//k4KapWL6hvZQAz6QjbpG2CSG9Gcq8+gA+8hggMRGeEm6McrVgeztaRZOW4XAfUIKXjRAGct7HA== 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=aG+pp8NVcv3LOHH5U6Bl6EteTqcA5d90Wgi6XaCXHlA=; b=BvyHKVpmbHPzgasTx0r7YebDnX+sf8GMVg3+7S5JMuhqEf0H9OlI1fOwal9dvXtIToP6a4+HDLdqOVmiPXrxKkrWfJmSDJbf2tJ4CGkV7HqYvLSn9jvo0M7Ub9z0eFT/J7MjnwRDitqoAlLSrEY7uCz3s0E+6u8gY5uZ0+ZXyhYBc9tkeQFscPFexpk+oXDAXizR1jI427VtZrRkZxLxTqo1u54IK+Zdi61pM5Idh7MO/wKFLq5E0K2Xiwbv+nN4zhMlyOVahkeFxoUJCDla+yz16gQU8ZtKTwd7lRwSWf7LxecQBwUJqDPxrKCIeKBO5pj8/qu68l9YDiOd2+hRAg== 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=aG+pp8NVcv3LOHH5U6Bl6EteTqcA5d90Wgi6XaCXHlA=; b=kz7v+Pp0ZDjH7oKjtDx73PWF02BQyC87O3mzR7bC63/HHIzRNT2t/OegvOH51n0yziCJTZOA2Cr5zSqOU/I4I9sQYSbEo1XxU3McXa2dyCnD1w/IZvg7aBLZ9SUA2x6uqENKJUigVYjdW3icQvGfu5nAgVenlB7mirA4/+bh4Og= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CO1PR10MB4404.namprd10.prod.outlook.com (2603:10b6:303:90::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.27; Fri, 11 Apr 2025 11:35:03 +0000 Received: from CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e]) by CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e%6]) with mapi id 15.20.8632.017; Fri, 11 Apr 2025 11:35:03 +0000 From: claudiu.zissulescu-ianculescu@oracle.com To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, indu.bhagat@oracle.com, jremus@linux.ibm.com, fweimer@redhat.com, josmyers@redhat.com Subject: [PATCH v2 1/5] elf: Add SFrame support to _dl_find_object function Date: Fri, 11 Apr 2025 14:34:52 +0300 Message-ID: <20250411113456.15213-2-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250411113456.15213-1-claudiu.zissulescu-ianculescu@oracle.com> References: <20250411113456.15213-1-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: PR1PR01CA0002.eurprd01.prod.exchangelabs.com (2603:10a6:102::15) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CO1PR10MB4404:EE_ X-MS-Office365-Filtering-Correlation-Id: 59e50f1b-5703-4869-ed50-08dd78ece6d0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: 8m2R943RYWk+X0Yj3s/SF0YRnt4RD2BJFnzHMcYy4QbvkfR5B1YnMEPXOcJhvM/TvbgZQadpRht9kpo5gYVhbvcofJFiiIXbONXBes+VGB61SWcfSFx13fQW31CzXf+xw1EbG5k7UG/5ztypHDMxYibpUFzPMsgv4l9wlqm9LKLa2kOEwgTGmBz2ZTuqXGfhlirSmAO6A0K73aoeh+plv7UZY4k1W5/NSmislXb7RI2cMHEdjfy/CHkREwAnQzIMsYrr5zxKI960sqX/frBj82cSYYbitKiOC8+QPoKKMyESNNh1OGymoOh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VN2eTD5b7zxR5h4b8EnGLlXWx94Fg7ErBLLK5L/nR1Kg3wYkrEWkYgObQlAUL0/c2Q= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY5PR10MB6011.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Bupd5geIOqqm5LIcd2jkYAPfP5jNpQGucsARxzkvTtXvdx46XVwK34ks05hjqWNlUGSzbOs4sGvsJHvKvNHOfZiFjQpWGi+sE9H4/Vds/xE1nnldcnXaBWG/ObPP7hULVFx3nEAi+X5WPL6nRVnjlc2vnoc44rYd2vw28GTscg07/rTCVO6lK6I6fnz4XYmvr8wenKWWf2fBfuYZWY3GHwH3JeptEJFI4DFfpHhDd6zBmYY73UxrHkdTRB4EWPy3teAxLNHlzz9XK355qZ/spkZynmZ3g27NQykFOT5wnNeakmPz0cj8YyM7cqOCvRMKYz7gAUfMBHGutYNMkMhzrXzM4cykkLA+/MHXLeaw+Oyezj6e0tGA91Kheum2BxZgakJaYNxr8JF8+0JuO2V+9z9Kj8GISvpNy5w0xLvWy0o4iDntVABjoAOydpNuA5sEQ4Y4gc2NjdNUHmCMG6vjZeZDBPCpCKOtwZhUk3lxJfQGFNwPBPNiUEj0sRaMElR9XtoWYoj633ZaTz9aSDYGx9faXX+2V48rSoxe522p/zdcu/9om00I0nCnFrU0U8TXn6jpfugvVjGY7OqQYN7w4YjD8bq0vDyzoOQPp5Fa1ZjCDjt2pIzzZJxMTHEg5raLcuJAtsaq+JiZbpZ0wYxgAvWzgzzSQfbsW8RhdY8Y6j4EACk5DbzZ290+hHxEMtwGu8DUT6gkX5Fq0G9jgMNCnkOXifg9KEi5aLQGrod4Tn4snOZzAsBcaRM8VOQcu1LZyAiHoa0c5tXJkrkZj8if5Wxw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alo/izKPE7886UqzajG2D9VW5afdTdAaJDQIqRwaXKwzVYr96qbrNY44qWGUPgZI1fT6k/jfhyf44UP5nAivOWDA4CR38JkQKjdewVtdIKifxIJQy1qTbB+16WbVYqNS4NQpStvHnt1fN/5tBfCBlE557a09P5QDDaVH75I+dI5nBw8Y54VRElwKIfqg66ehji83plf0jdxQMu2G12b5teT1m1mW/jur0gxfsjXcrhmDx56hA9BeDvqHfRJy6NLLAuyYIikh21C3w88jI7o44r21tHKpkIdiuVUbWuhdGZNtmWZQLe7EPd1UvpS/dJszNw5vey1c3cRGfro8VyAn/erY7RkclWS4i1Zpi9hrOiJKNFWiQWGeqYT/NMpa3i8/A0vAnuc/0aRAAXpNZt8T5r0QY1+vNQq4efuhxvTaGbqaWF2DqZOgH/fuqYuSX9k2vBsM5LnO2dbMzBpFh05Zu9RGvIvMu4cPNhVm9wad+hWJJXVyvho= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59e50f1b-5703-4869-ed50-08dd78ece6d0 X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2025 11:35:03.8720 (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: KuXndU5HRtk+sgK0gS5cXaXdeCExZdLyAW3qafHiBIatDU5569YTdeCUmYJwCUgmLXAwpjnugMcVSJQ56lbkt8BezhJww6gUfmKxW0m109+rGwKdelYvK14saCocnMJbKun86jZB6zq9KxTY9Qxr1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4404 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_04,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504110073 X-Proofpoint-GUID: gh8prX4n7DVpnswvCsVgDNoIea7US7BT X-Proofpoint-ORIG-GUID: gh8prX4n7DVpnswvCsVgDNoIea7US7BT X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Claudiu Zissulescu The SFrame provides information to be able to do stack trace is now well defined and implemented in Binutils 2.41. The format simply contains enough information to be able to do stack trace given a program counter (PC) value, the stack pointer, and the frame pointer. The SFrame information is stored in a .sframe ELF section, which is loaded into its own PT_GNU_SFRAME segment. We consider for this support SFrame version 2. This patch adds the bits to _dl_find_object to recognize and store in struct dl_find_object the necessary info about SFrame section. Signed-off-by: Claudiu Zissulescu --- bits/dl_find_object.h | 3 +++ dlfcn/dlfcn.h | 7 ++++++- elf/dl-find_object.h | 44 ++++++++++++++++++++++++++++++++++--------- manual/dynlink.texi | 25 +++++++++++++++++++++++- 4 files changed, 68 insertions(+), 11 deletions(-) diff --git a/bits/dl_find_object.h b/bits/dl_find_object.h index b9f796dc2b..908feece08 100644 --- a/bits/dl_find_object.h +++ b/bits/dl_find_object.h @@ -30,3 +30,6 @@ /* The ELF segment which contains the exception handling data. */ #define DLFO_EH_SEGMENT_TYPE PT_GNU_EH_FRAME + +/* The ELF segment which contains the SFrame data. */ +#define DLFO_SFRAME_SEGMENT_TYPE PT_GNU_SFRAME diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index 5747962611..411b401c9e 100644 --- a/dlfcn/dlfcn.h +++ b/dlfcn/dlfcn.h @@ -217,7 +217,11 @@ struct dl_find_object int dlfo_eh_count; /* Number of exception handling entries. */ unsigned int __dlfo_eh_count_pad; # endif - __extension__ unsigned long long int __dflo_reserved[7]; + void *dlfo_sframe; /* SFrame stack trace data of the object. */ +#if __WORDSIZE == 32 + unsigned int __dlfo_sframe_pad; +#endif + __extension__ unsigned long long int __dflo_reserved[6]; }; /* If ADDRESS is found in an object, fill in *RESULT and return 0. @@ -226,6 +230,7 @@ int _dl_find_object (void *__address, struct dl_find_object *__result) __THROW; #endif /* __USE_GNU */ +#define DLF_SFRAME (1 << 0) /* SFrame stack trace data is valid. */ __END_DECLS diff --git a/elf/dl-find_object.h b/elf/dl-find_object.h index 0915065be0..54092f9af7 100644 --- a/elf/dl-find_object.h +++ b/elf/dl-find_object.h @@ -33,6 +33,7 @@ transactions). */ struct dl_find_object_internal { + unsigned long long int flags; uintptr_t map_start; uintptr_t map_end; /* Set to map_start by dlclose. */ struct link_map *map; /* Set to NULL by dlclose. */ @@ -43,6 +44,7 @@ struct dl_find_object_internal #if DLFO_STRUCT_HAS_EH_COUNT int eh_count; #endif + void *sframe; }; /* Create a copy of *SOURCE in *COPY using relaxed MO loads and @@ -51,6 +53,8 @@ static inline void _dl_find_object_internal_copy (const struct dl_find_object_internal *source, struct dl_find_object_internal *copy) { + atomic_store_relaxed (©->flags, + atomic_load_relaxed (&source->flags)); atomic_store_relaxed (©->map_start, atomic_load_relaxed (&source->map_start)); atomic_store_relaxed (©->map_end, @@ -67,13 +71,15 @@ _dl_find_object_internal_copy (const struct dl_find_object_internal *source, atomic_store_relaxed (©->eh_count, atomic_load_relaxed (&source->eh_count)); #endif + atomic_store_relaxed (©->sframe, + atomic_load_relaxed (&source->sframe)); } static inline void _dl_find_object_to_external (struct dl_find_object_internal *internal, struct dl_find_object *external) { - external->dlfo_flags = 0; + external->dlfo_flags = internal->flags; external->dlfo_map_start = (void *) internal->map_start; external->dlfo_map_end = (void *) internal->map_end; external->dlfo_link_map = internal->map; @@ -84,6 +90,7 @@ _dl_find_object_to_external (struct dl_find_object_internal *internal, # if DLFO_STRUCT_HAS_EH_COUNT external->dlfo_eh_count = internal->eh_count; # endif + external->dlfo_sframe = internal->sframe; } /* Extract the object location data from a link map and writes it to @@ -92,6 +99,8 @@ static void __attribute__ ((unused)) _dl_find_object_from_map (struct link_map *l, struct dl_find_object_internal *result) { + uint64_t read_seg = 0; + atomic_store_relaxed (&result->flags, 0); atomic_store_relaxed (&result->map_start, (uintptr_t) l->l_map_start); atomic_store_relaxed (&result->map_end, (uintptr_t) l->l_map_end); atomic_store_relaxed (&result->map, l); @@ -100,23 +109,40 @@ _dl_find_object_from_map (struct link_map *l, atomic_store_relaxed (&result->eh_dbase, (void *) l->l_info[DT_PLTGOT]); #endif + /* Initialize object's exception handling segment and SFrame segment + data. */ + atomic_store_relaxed (&result->sframe, NULL); + atomic_store_relaxed (&result->eh_frame, NULL); +#if DLFO_STRUCT_HAS_EH_COUNT + atomic_store_relaxed (&result->eh_count, 0); +#endif + for (const ElfW(Phdr) *ph = l->l_phdr, *ph_end = l->l_phdr + l->l_phnum; ph < ph_end; ++ph) - if (ph->p_type == DLFO_EH_SEGMENT_TYPE) + switch (ph->p_type) { + case DLFO_EH_SEGMENT_TYPE: atomic_store_relaxed (&result->eh_frame, (void *) (ph->p_vaddr + l->l_addr)); #if DLFO_STRUCT_HAS_EH_COUNT atomic_store_relaxed (&result->eh_count, ph->p_memsz / 8); #endif - return; - } + read_seg |= 1; + break; - /* Object has no exception handling segment. */ - atomic_store_relaxed (&result->eh_frame, NULL); -#if DLFO_STRUCT_HAS_EH_COUNT - atomic_store_relaxed (&result->eh_count, 0); -#endif + case DLFO_SFRAME_SEGMENT_TYPE: + atomic_store_relaxed (&result->sframe, + (void *) (ph->p_vaddr + l->l_addr)); + atomic_store_relaxed (&result->flags, + atomic_load_relaxed (&result->flags) + | DLF_SFRAME); + read_seg |= 2; + /* Fall through. */ + default: + if (read_seg == 3) + return; + break; + } } /* Called by the dynamic linker to set up the data structures for the diff --git a/manual/dynlink.texi b/manual/dynlink.texi index 1500a53de6..865a8dcdf7 100644 --- a/manual/dynlink.texi +++ b/manual/dynlink.texi @@ -442,7 +442,7 @@ result data to the caller. @table @code @item unsigned long long int dlfo_flags -Currently unused and always 0. +Bit zero signals if SFrame stack data is valid. @item void *dlfo_map_start The start address of the inspected mapping. This information comes from @@ -459,6 +459,10 @@ This member contains a pointer to the link map of the object. This member contains a pointer to the exception handling data of the object. See @code{DLFO_EH_SEGMENT_TYPE} below. +@item void *dlfo_sframe +This member contains a pointer to the SFrame stack trace data of the +object. See @code{DLFO_SFRAME_SEGMENT_TYPE} below. + @end table This structure is a GNU extension. @@ -496,6 +500,25 @@ macro expands to the program header type for the unwinding data. This macro is a GNU extension. @end deftypevr +@deftypevr Macro int DLFO_SFRAME_SEGMENT_TYPE +@standards{GNU, dlfcn.h} +On targets using SFrame stack tracer, this macro expands to +@code{PT_GNU_SFRAME}. This indicates that @code{dlfo_sframe} in +@code{struct dl_find_object} points to the @code{PT_GNU_SFRAME} +segment of the object. + +This macro is a GNU extension. +@end deftypevr + +@deftypevr Macro int DLFO_STRUCT_HAS_SFRAME +@standards{GNU, dlfcn.h} +On most targets, this macro is defined as @code{0}. If it is defined to +@code{1}, @code{struct dl_find_object} contains an additional member +@code{dlfo_sframe}. + +This macro is a GNU extension. +@end deftypevr + @deftypefun {int} _dl_find_object (void *@var{address}, struct dl_find_object *@var{result}) @standards{GNU, dlfcn.h} @safety{@mtsafe{}@assafe{}@acsafe{}} From patchwork Fri Apr 11 11:34:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu-Ianculescu X-Patchwork-Id: 110251 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 EE22A38319C6 for ; Fri, 11 Apr 2025 11:37:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE22A38319C6 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=ke7FYD8j; 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=JHzVOEoo X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 8A6163831C5F for ; Fri, 11 Apr 2025 11:35:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A6163831C5F 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 8A6163831C5F 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=1744371317; cv=pass; b=rw6neRHQ1J8mHCQ8az4Sv7q+LssARWxFax7YqQmICiFyK+bkJH3iI+UvQj6lPmeNgKaPAnLfawmUGwC5im5IiuUNOFC2f4Ls7wx21TJsQPgb1eEoZkQsHflRuNgVcE2lcaXjiaFK4nLVhHq55pjuSvj18Z0u7RvxSG1X4MI16YM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744371317; c=relaxed/simple; bh=TmfL3x5sMd7KKp06GOSy1VXBZ+SIbttcyQ9mF93/IF0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=ReY52BcQ430MVnQFlJ3z3ewcRPUZkKF4XU0W+jEWZH5CitrjX7crccbfMUG0tZ75RMmjFmGx8+4ip43MlsH/naZufpyVnxsJoVML65qUljA3/MvRur6y49z/A4Q/cP52ody2vYMr+dQzfCNLxJm3O2Tb88n4kY775fU5gZkyGk8= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A6163831C5F Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53BBMJ4k001383; Fri, 11 Apr 2025 11:35:12 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=zytrMs6UBB+/W/FZMbz9RtguVygVucn9w+OmHOtxdQg=; b= ke7FYD8jIOgdXb4+zBNJ3KNzKZ/86fUHwCjqsfcRQk/3Yf63AUPJtJqSzTeomHON NaXQgQM0Fjm/jt3avDZXQA3inuYCv3mcs32iYofS78WcT/0+JqF1oI5uHovontmW kN1dA+e+VK6yloTceo+Hr6TBTteiLU12CJPvbwBzcIooL7wNHHGx1OEpu4qoZw7n Bl8NED/ORpgPCqitRT0dCr11cVDUi9hc8mwH3pP/G24hGjWTAtocCuc8vEqYFIGw /ck6IR3WFLlFpZe8ffnJt6Iy2u6AlJ2CIVYJk7qAkJGDZKxCnXQzqqE5Zfsotez6 miFtHc6PUWFCcMJhr2k6Bg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45y25080re-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:12 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53BAufDA023776; Fri, 11 Apr 2025 11:35:11 GMT Received: from cy3pr05cu001.outbound.protection.outlook.com (mail-westcentralusazlp17013077.outbound.protection.outlook.com [40.93.6.77]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45ttykx7ba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aVjH3NbBcSJmuX7sg2jIbSyWRsdx1+yacv7Y91coN9oJrQ/bYNiJUGgD2/LQcCs7Dbbi61W1OMaORwn8rxzAkZOIORNk6yxw+qysS83N51k4eJtRuelpNZ5rVogNA/nBGBBJ0DNJyl4bWe7PsjMHdOrys9Y/DlAV0eQO+tqwrqFzgyYSFhVBRwOQfbgIIJMAryvAPAVducNcZkhLfesAvU+H92u3nB3IytBVMBni68T6F2nyFxBPx19vFl3sOGCA+AaAJp97pTudh7x+zYKMGzWGoZaBJzFoOfk8ZyLphkcYwiUREHhUNXvmzvOmLyadhyf2aoDovkb4Ny9tF7T3lw== 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=zytrMs6UBB+/W/FZMbz9RtguVygVucn9w+OmHOtxdQg=; b=pRI9abjB74tKBaYTboMaeGTksEamP/aImNj93F+rN89KBj4PTXaIobMBWz0fk+Ovg4BhU+eI+fxFCApq9yb+cWlIS/4w1wUIz219w09tzRORu8eo6qazEXjgHtQANhj1te8Nd9FbqZ8Oe7SWBTloMVChSECau0pwY8/+ADgHmyb332xDa04n9mdyZJjX1IIRZkoJLXQHJHyEYq9TGVq3TxN4tBZKlzdxtiOk5dUCIJDkJtBw5X6Zb2spP56jnAXydORcGU7aMtboOE0BsjjleTI6KOZlnZKI6TJ+z7+v/kaSqOttmWnpgOT4LXZeNhz8TeacNe41L2x95ycCLo5y/Q== 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=zytrMs6UBB+/W/FZMbz9RtguVygVucn9w+OmHOtxdQg=; b=JHzVOEoo0UezmkKmTgg1UDx6SyOTyVipQ7HAklgLJ0ATgKzGLXM5sMADGJq04wJGP9BjxudZ1ACm+KyWBf5WB5fT0G9IQpLu5aF/AoSHX0bp4U8wBSXIQnRIa3Nq2pIX6ZUJxrz+vaJAs/AdF/c777wxibYj5OTVp0s3IeBPzpE= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CO1PR10MB4404.namprd10.prod.outlook.com (2603:10b6:303:90::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.27; Fri, 11 Apr 2025 11:35:09 +0000 Received: from CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e]) by CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e%6]) with mapi id 15.20.8632.017; Fri, 11 Apr 2025 11:35:09 +0000 From: claudiu.zissulescu-ianculescu@oracle.com To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, indu.bhagat@oracle.com, jremus@linux.ibm.com, fweimer@redhat.com, josmyers@redhat.com Subject: [PATCH v2 2/5] elf: Add SFrame stack tracing Date: Fri, 11 Apr 2025 14:34:53 +0300 Message-ID: <20250411113456.15213-3-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250411113456.15213-2-claudiu.zissulescu-ianculescu@oracle.com> References: <20250411113456.15213-1-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-2-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: PR1PR01CA0009.eurprd01.prod.exchangelabs.com (2603:10a6:102::22) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CO1PR10MB4404:EE_ X-MS-Office365-Filtering-Correlation-Id: e37401a2-2ac8-4981-3023-08dd78ece9ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|1800799024|13003099007; X-Microsoft-Antispam-Message-Info: yh3lURN0UNQdKgpbj0CSH0DyACzQu0k6VtOluM+SlkE0HNN8fYi3gWQ7IhfrzFZ9ITnca4+yDg2UFHuW3SBZvKwdGIQ1nRmn/G55z96C7EazqXqmouNYd8Y5AxzkJuck22NK3A2HiNMyE7HICzUQSPd8D7GraOl4u9sF9I9pq54Xe+iuUGagPs5rBNwJHN1//sUA/AnVX0ihrZFePX4q4FaWvN1l6ZbOpQzzxIypbTW/VX2ADKX96z625YE7sOieuXc8JMaPHn1ahNR/DY6Xmnj5mtIpCc3WKtcs2Mdhv6bTW0IT9zsuue/nur83siE0YG4K7uCwDXK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255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY5PR10MB6011.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(13003099007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +AqPFrtJBZ16sytWtA/ei4fuGaZ0IpHoh95LVOF3NvBN8SpdHfWcxhc/8JQ044uE1dfBu4qGWFkcYs6JdmgM5fDTeyhQUY97TcozxUxTD8Lx2Ej2aPKHs5HGwo2QEDVvBu9hBKWNIufmszvVuH2S3+M1EEGwrsJAoLgSIgPerNGepae0FxxSaiMtFLn0Xj88dYVX5sbiOslBf9f/Qr8laYUpNJ5faSeAiyx3DZpAs6JslAImd4GzRfQK0MTwVxbP2YEe+BYx8XaiZIFqusace702CF34nOfI6TCdQHQh9ijD28hK6QEjvejZMYQ86hM1k0wMFyWvkW0IbBMBZmoEqVzIpvhQhv65JinRR++TeRTWyG1yhyFAuk/EndLAFM7GEwNCfhJY67Fgig7i6Zu4idAtdhWxmulByxIeXH50GARloZY4MWUC/RHpLbypxypTrRlih10cnRvh3AavEJtpSDp7hiQEsdS0djlxa9rahl9TlQclEop6tT2ZfKbaSkUpJDOd0FBmiKyzJeS4yKoyzK9c5C2cU6Q9+nflfkItUGBOaFj/gp+7wyw9FV4k8JuqaRYkaYTBak0nLqZe7SL33Re0RdUUq5Nw9Yz0/HD3bn1XFUnukoGSpETslEPc+Dl0xlZ0ZxJQ9BdezhvA0YOHjyX1kMWF5EYJumyIlnpr5FvMiH2MFOoEteA/cVnAM80ktb8b5pBiWe84AuqcrpHnHxUsE7ENwueeh9K691pB5lz8YRAHkYAdEOKhIsolNXVuzQvBDtJIrihaTpkwWxNp803Q35BT5O05TL9GvonIi6t9Z1BVYIQGTzQZy16vprBzYoxkzdJWuJQXXCYn3vl35cBum8n1eE39u9oqDFbODaHbYs8GA9FkwbATDhZVa20tvln2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CNNoJK5xLtzmTjM7a7U9WLSqLDRXv/fEVyr6N+M0yLEGuIpW3BBsN23ykJf6GyWxpEMRlxH2EEUlphCkDxDEJcgjDtz+AGETieaDHTwKJpV0DCf1WazK4g0s/od7x7WAOx73tmkaAPi9h2dMAR2XjtjFUV6wQK0IUkTBPydHCqB6pDrZE4WAbF4NTMvq1fcEq4naLAPatLWP0FBhOvhdPPB0CR4MYK/2IOesZO+HvF0TYjEbpt2Hl7gJeLWelIHF6FydCxBYYEaDhONuwyZbZyCB0EXBBxgrK0Zp5yf30IJddAWSKZ/wgJSvc9x/tLY5JcY/iro+tmCN+JIKEmQCMznqPSD0leghovtOEQBNEiqZC67AyUrBA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e37401a2-2ac8-4981-3023-08dd78ece9ee X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2025 11:35:09.2026 (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: mrO+zLPSNcE3gOnVAlYs5ZF7ydRDuosUNnXzIB88WtJF1dQia6uu5GJ5H3p1qslxIaXY7U8DCGUSDKqIKmEYS8U2Tna/576bYmMv8It6O6/E1g5AcRrfFc+lk5eDuk7SBO80MTeNcW37gvtDNZNuUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4404 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_04,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504110073 X-Proofpoint-ORIG-GUID: UZRC35ktCPjhBGeWJtdVo--K4MFZ5zaW X-Proofpoint-GUID: UZRC35ktCPjhBGeWJtdVo--K4MFZ5zaW X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Claudiu Zissulescu This patch adds the necessary bits to enable stack tracing using SFrame. In the case the new SFrame stack tracing procedure doesn't find SFrame related info, the stack tracing falls back on default Dwarf implementation. The new SFrame stack tracing procedure is added to bebug/backtrace.c file, the support functions are added in sysdeps folder, namely sframe.h, read-sframe.c and read-sfame.h. Signed-off-by: Claudiu Zissulescu --- debug/backtrace.c | 32 +- sysdeps/generic/Makefile | 1 + sysdeps/generic/sframe-read.c | 577 ++++++++++++++++++++++++++++++++++ sysdeps/generic/sframe-read.h | 101 ++++++ sysdeps/generic/sframe.c | 157 +++++++++ sysdeps/generic/sframe.h | 367 +++++++++++++++++++++ sysdeps/generic/uw-sigframe.h | 17 + 7 files changed, 1250 insertions(+), 2 deletions(-) create mode 100644 sysdeps/generic/sframe-read.c create mode 100644 sysdeps/generic/sframe-read.h create mode 100644 sysdeps/generic/sframe.c create mode 100644 sysdeps/generic/sframe.h create mode 100644 sysdeps/generic/uw-sigframe.h diff --git a/debug/backtrace.c b/debug/backtrace.c index 969d699bd1..b41bc9513f 100644 --- a/debug/backtrace.c +++ b/debug/backtrace.c @@ -1,5 +1,5 @@ /* Return backtrace of current program state. - Copyright (C) 2003-2024 Free Software Foundation, Inc. + Copyright (C) 2003-2025 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 @@ -20,6 +20,7 @@ #include #include #include +#include struct trace_arg { @@ -30,6 +31,26 @@ struct trace_arg int size; }; +/* Initialize the SFrame backtrace routine, and try to backtrace the + current stack using SFrame info. The return value of SFrame stack + tracer must be larger than one to consider the SFrame backtrace + valid. Otherwise, there may be the case that glibc is compiled + using SFrame but the application not. */ + +#define DO_SFRAME_BACKTRACE(ARRAY, SIZE) \ + do \ + { \ + int cnt; \ + frame frame; \ + frame.pc = getPC(); \ + frame.sp = getSP(); \ + frame.fp = (_Unwind_Ptr) __builtin_frame_address (0); \ + cnt = stacktrace_sframe (ARRAY, SIZE, &frame); \ + if (cnt > 1) \ + return cnt; \ + } \ + while(0) + static _Unwind_Reason_Code backtrace_helper (struct _Unwind_Context *ctx, void *a) { @@ -72,7 +93,14 @@ __backtrace (void **array, int size) .cnt = -1 }; - if (size <= 0 || arg.unwind_link == NULL) + if (size <= 0) + return 0; + + /* Try first the SFrame backtracer. */ + DO_SFRAME_BACKTRACE (array, size); + + /* Try the dwarf unwinder. */ + if (arg.unwind_link == NULL) return 0; UNWIND_LINK_PTR (arg.unwind_link, _Unwind_Backtrace) diff --git a/sysdeps/generic/Makefile b/sysdeps/generic/Makefile index 72522d1f0e..c551eb5ab1 100644 --- a/sysdeps/generic/Makefile +++ b/sysdeps/generic/Makefile @@ -21,6 +21,7 @@ CFLAGS-wordcopy.c += -Wno-uninitialized endif ifeq ($(subdir),elf) +sysdep_routines += sframe-read sframe ifeq (yes:yes,$(build-shared):$(unwind-find-fde)) # This is needed to support g++ v2 and v3. sysdep_routines += framestate unwind-pe diff --git a/sysdeps/generic/sframe-read.c b/sysdeps/generic/sframe-read.c new file mode 100644 index 0000000000..e988ad3299 --- /dev/null +++ b/sysdeps/generic/sframe-read.c @@ -0,0 +1,577 @@ +/* Copyright (C) 2025 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 General Public License + along with this program. If not, see . */ + +#include +#include +#include +#include +#include +#include + +#define sframe_assert(expr) (assert (expr)) + +/* Get the SFrame header size. */ + +static inline uint32_t +sframe_get_hdr_size (sframe_header *sfh) +{ + return SFRAME_V1_HDR_SIZE (*sfh); +} + +/* Access functions for frame row entry data. */ + +static inline uint8_t +sframe_fre_get_offset_count (uint8_t fre_info) +{ + return SFRAME_V1_FRE_OFFSET_COUNT (fre_info); +} + +static inline uint8_t +sframe_fre_get_offset_size (uint8_t fre_info) +{ + return SFRAME_V1_FRE_OFFSET_SIZE (fre_info); +} + +static inline bool +sframe_get_fre_ra_mangled_p (uint8_t fre_info) +{ + return SFRAME_V1_FRE_MANGLED_RA_P (fre_info); +} + +/* Access functions for info from function descriptor entry. */ + +static uint32_t +sframe_get_fre_type (sframe_func_desc_entry *fdep) +{ + uint32_t fre_type = 0; + if (fdep) + fre_type = SFRAME_V1_FUNC_FRE_TYPE (fdep->sfde_func_info); + return fre_type; +} + +static uint32_t +sframe_get_fde_type (sframe_func_desc_entry *fdep) +{ + uint32_t fde_type = 0; + if (fdep) + fde_type = SFRAME_V1_FUNC_FDE_TYPE (fdep->sfde_func_info); + return fde_type; +} + +/* Check if SFrame header has valid data. Only consider SFrame type + 2. */ + +static bool +sframe_header_sanity_check_p (sframe_header *hp) +{ + unsigned char all_flags = SFRAME_F_FDE_SORTED | SFRAME_F_FRAME_POINTER; + /* Check preamble is valid. */ + if ((hp->sfh_preamble.sfp_magic != SFRAME_MAGIC) + || (hp->sfh_preamble.sfp_version != SFRAME_VERSION_2) + || ((hp->sfh_preamble.sfp_flags | all_flags) != all_flags)) + return false; + + /* Check offsets are valid. */ + if (hp->sfh_fdeoff > hp->sfh_freoff) + return false; + + return true; +} + +/* Get the FRE start address size. */ + +static size_t +sframe_fre_start_addr_size (uint32_t fre_type) +{ + size_t addr_size = 0; + switch (fre_type) + { + case SFRAME_FRE_TYPE_ADDR1: + addr_size = 1; + break; + case SFRAME_FRE_TYPE_ADDR2: + addr_size = 2; + break; + case SFRAME_FRE_TYPE_ADDR4: + addr_size = 4; + break; + default: + /* No other value is expected. */ + sframe_assert (0); + break; + } + return addr_size; +} + +/* Check if the FREP has valid data. */ + +static bool +sframe_fre_sanity_check_p (sframe_frame_row_entry *frep) +{ + uint8_t offset_size, offset_cnt; + uint8_t fre_info; + + if (frep == NULL) + return false; + + fre_info = frep->fre_info; + offset_size = sframe_fre_get_offset_size (fre_info); + + if (offset_size != SFRAME_FRE_OFFSET_1B + && offset_size != SFRAME_FRE_OFFSET_2B + && offset_size != SFRAME_FRE_OFFSET_4B) + return false; + + offset_cnt = sframe_fre_get_offset_count (fre_info); + if (offset_cnt > MAX_NUM_STACK_OFFSETS) + return false; + + return true; +} + +/* Get FRE_INFO's offset size in bytes. */ + +static size_t +sframe_fre_offset_bytes_size (uint8_t fre_info) +{ + uint8_t offset_size, offset_cnt; + + offset_size = sframe_fre_get_offset_size (fre_info); + + offset_cnt = sframe_fre_get_offset_count (fre_info); + + if (offset_size == SFRAME_FRE_OFFSET_2B + || offset_size == SFRAME_FRE_OFFSET_4B) /* 2 or 4 bytes. */ + return (offset_cnt * (offset_size * 2)); + + return (offset_cnt); +} + +/* Get total size in bytes to represent FREP in the binary format. This + includes the starting address, FRE info, and all the offsets. */ + +static size_t +sframe_fre_entry_size (sframe_frame_row_entry *frep, uint32_t fre_type) +{ + if (frep == NULL) + return 0; + + uint8_t fre_info = frep->fre_info; + size_t addr_size = sframe_fre_start_addr_size (fre_type); + + return (addr_size + sizeof (frep->fre_info) + + sframe_fre_offset_bytes_size (fre_info)); +} + +/* Check whether for the given FDEP, the SFrame Frame Row Entry identified via + the START_IP_OFFSET and the END_IP_OFFSET, provides the stack trace + information for the PC. */ + +static bool +sframe_fre_check_range_p (sframe_func_desc_entry *fdep, + int32_t start_ip_offset, int32_t end_ip_offset, + int32_t pc) +{ + int32_t start_ip, end_ip; + int32_t func_start_addr; + uint8_t rep_block_size; + uint32_t fde_type; + int32_t masked_pc; + bool mask_p; + bool ret; + + ret = false; + + if (!fdep) + return ret; + + func_start_addr = fdep->sfde_func_start_address; + fde_type = sframe_get_fde_type (fdep); + mask_p = (fde_type == SFRAME_FDE_TYPE_PCMASK); + rep_block_size = fdep->sfde_func_rep_size; + + if (!mask_p) + { + start_ip = start_ip_offset + func_start_addr; + end_ip = end_ip_offset + func_start_addr; + ret = ((start_ip <= pc) && (end_ip >= pc)); + } + else + { + /* For FDEs for repetitive pattern of insns, we need to return the FRE + where pc % rep_block_size is between start_ip_offset and + end_ip_offset. */ + masked_pc = pc % rep_block_size; + ret = ((start_ip_offset <= masked_pc) && (end_ip_offset >= masked_pc)); + } + + return ret; +} + +/* The SFrame Decoder. */ + +/* Get SFrame header from the given decoder context DCTX. */ + +static inline sframe_header * +sframe_decoder_get_header (sframe_decoder_ctx *dctx) +{ + sframe_header *hp = NULL; + if (dctx != NULL) + hp = &dctx->sfd_header; + return hp; +} + +/* Get IDX'th offset from FRE. Set ERRP as applicable. */ + +static int32_t +sframe_get_fre_offset (sframe_frame_row_entry *fre, + int idx, + _Unwind_Reason_Code *errp) +{ + uint8_t offset_cnt, offset_size; + + if (!sframe_fre_sanity_check_p (fre)) + { + *errp = _URC_END_OF_STACK; + return 0; + } + + offset_cnt = sframe_fre_get_offset_count (fre->fre_info); + offset_size = sframe_fre_get_offset_size (fre->fre_info); + + if (offset_cnt < (idx + 1)) + { + *errp = _URC_END_OF_STACK; + return 0; + } + *errp = _URC_NO_REASON; + + if (offset_size == SFRAME_FRE_OFFSET_1B) + { + int8_t *sp = (int8_t *)fre->fre_offsets; + return sp[idx]; + } + else if (offset_size == SFRAME_FRE_OFFSET_2B) + { + int16_t *sp = (int16_t *)fre->fre_offsets; + return sp[idx]; + } + else + { + int32_t *ip = (int32_t *)fre->fre_offsets; + return ip[idx]; + } +} + +/* Decode the SFrame FRE start address offset value from FRE_BUF in on-disk + binary format, given the FRE_TYPE. Updates the FRE_START_ADDR. */ + +static void +sframe_decode_fre_start_address (const char *fre_buf, + uint32_t *fre_start_addr, + uint32_t fre_type) +{ + uint32_t saddr = 0; + + if (fre_type == SFRAME_FRE_TYPE_ADDR1) + { + uint8_t *uc = (uint8_t *)fre_buf; + saddr = (uint32_t)*uc; + } + else if (fre_type == SFRAME_FRE_TYPE_ADDR2) + { + uint16_t *ust = (uint16_t *)fre_buf; + saddr = (uint32_t)*ust; + } + else if (fre_type == SFRAME_FRE_TYPE_ADDR4) + { + uint32_t *uit = (uint32_t *)fre_buf; + saddr = (uint32_t)*uit; + } + else + return; + + *fre_start_addr = saddr; +} + +/* Find the function descriptor entry starting which contains the specified + address ADDR. */ + +static sframe_func_desc_entry * +sframe_get_funcdesc_with_addr_internal (sframe_decoder_ctx *ctx, int32_t addr, + int *errp) +{ + sframe_header *dhp; + sframe_func_desc_entry *fdp; + int low, high, cnt; + + if (ctx == NULL) + return NULL; + + dhp = sframe_decoder_get_header (ctx); + + if (dhp == NULL || dhp->sfh_num_fdes == 0 || ctx->sfd_funcdesc == NULL) + return NULL; + /* If the FDE sub-section is not sorted on PCs, skip the lookup because + binary search cannot be used. */ + if ((dhp->sfh_preamble.sfp_flags & SFRAME_F_FDE_SORTED) == 0) + return NULL; + + /* Do the binary search. */ + fdp = (sframe_func_desc_entry *) ctx->sfd_funcdesc; + low = 0; + high = dhp->sfh_num_fdes; + cnt = high; + while (low <= high) + { + int mid = low + (high - low) / 2; + + if (fdp[mid].sfde_func_start_address == addr) + return fdp + mid; + + if (fdp[mid].sfde_func_start_address < addr) + { + if (mid == (cnt - 1)) /* Check if it's the last one. */ + return fdp + (cnt - 1); + else if (fdp[mid+1].sfde_func_start_address > addr) + return fdp + mid; + low = mid + 1; + } + else + high = mid - 1; + } + + return NULL; +} + +/* Get the end IP offset for the FRE at index i in the FDEP. The buffer FRES + is the starting location for the FRE. */ + +static uint32_t +sframe_fre_get_end_ip_offset (sframe_func_desc_entry *fdep, unsigned int i, + const char *fres) +{ + uint32_t end_ip_offset = 0; + uint32_t fre_type; + + fre_type = sframe_get_fre_type (fdep); + + /* Get the start address of the next FRE in sequence. */ + if (i < fdep->sfde_func_num_fres - 1) + { + sframe_decode_fre_start_address (fres, &end_ip_offset, fre_type); + end_ip_offset -= 1; + } + else + /* The end IP offset for the FRE needs to be deduced from the function + size. */ + end_ip_offset = fdep->sfde_func_size - 1; + + return end_ip_offset; +} + +/* Get the SFrame's fixed FP offset given the decoder context CTX. */ + +static int8_t +sframe_decoder_get_fixed_fp_offset (sframe_decoder_ctx *ctx) +{ + sframe_header *dhp; + dhp = sframe_decoder_get_header (ctx); + return dhp->sfh_cfa_fixed_fp_offset; +} + +/* Get the SFrame's fixed RA offset given the decoder context CTX. */ + +static int8_t +sframe_decoder_get_fixed_ra_offset (sframe_decoder_ctx *ctx) +{ + sframe_header *dhp; + dhp = sframe_decoder_get_header (ctx); + return dhp->sfh_cfa_fixed_ra_offset; +} + +/* Get the base reg id from the FRE info. Set errp if failure. */ + +uint8_t +sframe_fre_get_base_reg_id (sframe_frame_row_entry *fre) +{ + uint8_t fre_info = fre->fre_info; + return SFRAME_V1_FRE_CFA_BASE_REG_ID (fre_info); +} + +/* Get the CFA offset from the FRE. If the offset is invalid, sets errp. */ + +int32_t +sframe_fre_get_cfa_offset (sframe_decoder_ctx *dctx __attribute__ ((__unused__)), + sframe_frame_row_entry *fre) +{ + _Unwind_Reason_Code err; + return sframe_get_fre_offset (fre, SFRAME_FRE_CFA_OFFSET_IDX, &err); +} + +/* Get the FP offset from the FRE. If the offset is invalid, sets errp. */ + +int32_t +sframe_fre_get_fp_offset (sframe_decoder_ctx *dctx, + sframe_frame_row_entry *fre, + _Unwind_Reason_Code *errp) +{ + uint32_t fp_offset_idx = 0; + int8_t fp_offset = sframe_decoder_get_fixed_fp_offset (dctx); + + *errp = _URC_NO_REASON; + /* If the FP offset is not being tracked, return the fixed FP offset + from the SFrame header. */ + if (fp_offset != SFRAME_CFA_FIXED_FP_INVALID) + return fp_offset; + + /* In some ABIs, the stack offset to recover RA (using the CFA) from is + fixed (like AMD64). In such cases, the stack offset to recover FP will + appear at the second index. */ + fp_offset_idx = ((sframe_decoder_get_fixed_ra_offset (dctx) + != SFRAME_CFA_FIXED_RA_INVALID) + ? SFRAME_FRE_RA_OFFSET_IDX + : SFRAME_FRE_FP_OFFSET_IDX); + return sframe_get_fre_offset (fre, fp_offset_idx, errp); +} + +/* Get the RA offset from the FRE. If the offset is invalid, sets errp. */ + +int32_t +sframe_fre_get_ra_offset (sframe_decoder_ctx *dctx, + sframe_frame_row_entry *fre) +{ + _Unwind_Reason_Code err; + int8_t ra_offset = sframe_decoder_get_fixed_ra_offset (dctx); + /* If the RA offset was not being tracked, return the fixed RA offset + from the SFrame header. */ + if (ra_offset != SFRAME_CFA_FIXED_RA_INVALID) + return ra_offset; + + /* Otherwise, get the RA offset from the FRE. */ + return sframe_get_fre_offset (fre, SFRAME_FRE_RA_OFFSET_IDX, &err); +} + +/* Decode the specified SFrame buffer SF_BUF and return the new SFrame + decoder context. */ + +_Unwind_Reason_Code +sframe_decode (sframe_decoder_ctx *dctx, const char *sf_buf) +{ + const sframe_preamble *sfp; + size_t hdrsz; + sframe_header *sfheaderp; + char *frame_buf; + + int fidx_size; + uint32_t fre_bytes; + + if (sf_buf == NULL) + return _URC_END_OF_STACK; + + sfp = (const sframe_preamble *) sf_buf; + + /* Check for foreign endianness. */ + if (sfp->sfp_magic != SFRAME_MAGIC) + return _URC_END_OF_STACK; + + frame_buf = (char *)sf_buf; + + /* Handle the SFrame header. */ + dctx->sfd_header = *(sframe_header *) frame_buf; + + /* Validate the contents of SFrame header. */ + sfheaderp = &dctx->sfd_header; + if (!sframe_header_sanity_check_p (sfheaderp)) + return _URC_END_OF_STACK; + + hdrsz = sframe_get_hdr_size (sfheaderp); + frame_buf += hdrsz; + + /* Handle the SFrame Function Descriptor Entry section. */ + fidx_size + = sfheaderp->sfh_num_fdes * sizeof (sframe_func_desc_entry); + dctx->sfd_funcdesc = (sframe_func_desc_entry *)frame_buf; + frame_buf += (fidx_size); + + dctx->sfd_fres = frame_buf; + fre_bytes = sfheaderp->sfh_fre_len; + dctx->sfd_fre_nbytes = fre_bytes; + + return _URC_NO_REASON; +} + +/* Find the SFrame Row Entry which contains the PC. Returns + _URC_END_OF_STACK if failure. */ + +_Unwind_Reason_Code +sframe_find_fre (sframe_decoder_ctx *ctx, int32_t pc, + sframe_frame_row_entry *frep) +{ + sframe_func_desc_entry *fdep; + uint32_t fre_type, fde_type, i; + int32_t start_ip_offset; + int32_t func_start_addr; + int32_t end_ip_offset; + const char *fres; + size_t size = 0; + int err = 0; + bool mask_p; + + if ((ctx == NULL) || (frep == NULL)) + return _URC_END_OF_STACK; + + /* Find the FDE which contains the PC, then scan its fre entries. */ + fdep = sframe_get_funcdesc_with_addr_internal (ctx, pc, &err); + if (fdep == NULL || ctx->sfd_fres == NULL) + return _URC_END_OF_STACK; + + fre_type = sframe_get_fre_type (fdep); + fde_type = sframe_get_fde_type (fdep); + mask_p = (fde_type == SFRAME_FDE_TYPE_PCMASK); + + fres = ctx->sfd_fres + fdep->sfde_func_start_fre_off; + func_start_addr = fdep->sfde_func_start_address; + + for (i = 0; i < fdep->sfde_func_num_fres; i++) + { + size_t addr_size; + + /* Partially decode the FRE. */ + sframe_decode_fre_start_address (fres, &frep->fre_start_addr, fre_type); + addr_size = sframe_fre_start_addr_size (fre_type); + frep->fre_info = *(uint8_t *)(fres + addr_size); + size = sframe_fre_entry_size (frep, fre_type); + + start_ip_offset = frep->fre_start_addr; + end_ip_offset = sframe_fre_get_end_ip_offset (fdep, i, fres + size); + + /* First FRE's start_ip must be more than pc for regular SFrame FDEs. */ + if (i == 0 && !mask_p && (start_ip_offset + func_start_addr) > pc) + return _URC_END_OF_STACK; + + if (sframe_fre_check_range_p (fdep, start_ip_offset, end_ip_offset, pc)) + { + /* Decode last FRE bits: offsets size. */ + frep->fre_offsets = fres + addr_size + sizeof (frep->fre_info); + + return _URC_NO_REASON; + } + + fres += size; + } + return _URC_END_OF_STACK; +} diff --git a/sysdeps/generic/sframe-read.h b/sysdeps/generic/sframe-read.h new file mode 100644 index 0000000000..6d4e72a17f --- /dev/null +++ b/sysdeps/generic/sframe-read.h @@ -0,0 +1,101 @@ +/* Copyright (C) 2025 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 General Public License + along with this program. If not, see . */ + +#ifndef _SFRAME_API_H +#define _SFRAME_API_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct sframe_decoder_ctx +{ + + sframe_header sfd_header; + + sframe_func_desc_entry *sfd_funcdesc; + /* SFrame FRE table. */ + char *sfd_fres; + /* Number of bytes needed for SFrame FREs. */ + int sfd_fre_nbytes; +} sframe_decoder_ctx; + +#define MAX_NUM_STACK_OFFSETS 3 + +/* User interfacing SFrame Row Entry. + An abstraction provided by libsframe so the consumer is decoupled from + the binary format representation of the same. + + The members are best ordered such that they are aligned at their natural + boundaries. This helps avoid usage of undesirable misaligned memory + accesses. See PR libsframe/29856. */ + +typedef struct sframe_frame_row_entry +{ + uint32_t fre_start_addr; + const char *fre_offsets; + unsigned char fre_info; +} sframe_frame_row_entry; + +/* The SFrame Decoder. */ + +/* Decode the specified SFrame buffer CF_BUF and return the new SFrame + decoder context. */ + +extern _Unwind_Reason_Code +sframe_decode (sframe_decoder_ctx *dctx, const char *cf_buf); + +/* Find the SFrame Frame Row Entry which contains the PC. Returns + _URC_END_OF_STACK if failure. */ + +extern _Unwind_Reason_Code +sframe_find_fre (sframe_decoder_ctx *ctx, int32_t pc, + sframe_frame_row_entry *frep); + +/* Get the base reg id from the FRE info. */ + +extern uint8_t +sframe_fre_get_base_reg_id (sframe_frame_row_entry *fre); + +/* Get the CFA offset from the FRE. */ + +extern int32_t +sframe_fre_get_cfa_offset (sframe_decoder_ctx *dtcx, + sframe_frame_row_entry *fre); + +/* Get the FP offset from the FRE. If the offset is invalid, sets errp. */ + +extern int32_t +sframe_fre_get_fp_offset (sframe_decoder_ctx *dctx, + sframe_frame_row_entry *fre, + _Unwind_Reason_Code *errp); + +/* Get the RA offset from the FRE. */ + +extern int32_t +sframe_fre_get_ra_offset (sframe_decoder_ctx *dctx, + sframe_frame_row_entry *fre); + +#ifdef __cplusplus +} +#endif + +#endif /* _SFRAME_API_H */ diff --git a/sysdeps/generic/sframe.c b/sysdeps/generic/sframe.c new file mode 100644 index 0000000000..b0a5c2e6f8 --- /dev/null +++ b/sysdeps/generic/sframe.c @@ -0,0 +1,157 @@ +/* Copyright (C) 2025 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 General Public License + along with this program. If not, see . */ + +#include +#include +#include +#include +#include + + +/* Some arches like s390x needs an offset to correct the value where + SP is located in relation to CFA. */ +#ifndef SFRAME_SP_VAL_OFFSET +#define SFRAME_SP_VAL_OFFSET 0 +#endif + +static inline uint64_t +read_stack_value (uint64_t loc) +{ + uint64_t value = *((uint64_t *) loc); + return value; +} + +/* Backtrace the stack and collect the stacktrace given SFrame info. + If successful, store the return addresses in RA_LST. The SIZE + argument specifies the maximum number of return addresses that can + be stored in RA_LST and contains the number of the addresses + collected. */ + +int +stacktrace_sframe (void **ra_lst, int count, frame *frame) +{ + _Unwind_Ptr sframe_vma, cfa, return_addr, ra_stack_loc, fp_stack_loc, pc; + int cfa_offset, fp_offset, ra_offset, i; + sframe_frame_row_entry fred, *frep = &fred; + + if (!ra_lst || !count) + return 0; + + for (i = 0; i < count; i++) + { + _Unwind_Reason_Code err; + struct dl_find_object data; + sframe_decoder_ctx decoder_context, *dctx = &decoder_context; + + /* Clean decoder context. */ + memset (dctx, 0, sizeof (sframe_decoder_ctx)); + + /* Load and set up the SFrame stack trace info for pc. */ + if (_dl_find_object ((void *) frame->pc, &data) < 0) + return i; + + sframe_vma = (_Unwind_Ptr) data.dlfo_sframe; + if (!sframe_vma) + { +#ifdef MD_DECODE_SIGNAL_FRAME + /* I cannot find a valid SFrame section. Check if it is a + signal frame. */ + if (MD_DECODE_SIGNAL_FRAME (frame) == _URC_NO_REASON) + { + ra_lst[i] = (void *) frame->pc; + continue; + } +#endif + return i; + } + + /* Decode the specified SFrame buffer populate sframe's decoder + context. */ + if (sframe_decode (dctx, (char *) data.dlfo_sframe) == _URC_END_OF_STACK) + return i; + + pc = frame->pc - sframe_vma; + /* Find the SFrame Row Entry which contains the PC. */ + if (sframe_find_fre (dctx, pc, frep) == _URC_END_OF_STACK) + { +#ifdef MD_DECODE_SIGNAL_FRAME + /* I cannot find any FREs, try to see if it is a signal + frame, and if so decode it. */ + if (MD_DECODE_SIGNAL_FRAME (frame) == _URC_NO_REASON) + { + ra_lst[i] = (void *) frame->pc; + continue; + } +#endif + return i; + } + + /* Get the CFA offset from the FRE. */ + cfa_offset = sframe_fre_get_cfa_offset (dctx, frep); + + /* Get CFA using base reg id from the FRE info. */ + cfa = ((sframe_fre_get_base_reg_id (frep) + == SFRAME_BASE_REG_SP) ? frame->sp : frame->fp) + cfa_offset; + + /* Get the RA offset from the FRE. */ + ra_offset = sframe_fre_get_ra_offset (dctx, frep); + + ra_stack_loc = cfa + ra_offset; + return_addr = read_stack_value (ra_stack_loc); + + ra_lst[i] = (void *)return_addr; + + /* Set up for the next frame. */ + /* Get the FP offset from the FRE. If the offset is invalid, + sets errp. */ + fp_offset = sframe_fre_get_fp_offset (dctx, frep, &err); + if (err == _URC_NO_REASON) + { + /* Frame is valid, get the value stored in the stack + location. */ + fp_stack_loc = cfa + fp_offset; + frame->fp = read_stack_value (fp_stack_loc); + } + + frame->sp = cfa + SFRAME_SP_VAL_OFFSET; + frame->pc = return_addr; + } + return i; +} + +libc_hidden_def (stacktrace_sframe); + +/* A noinline helper used to obtain the caller's current PC. */ + +_Unwind_Ptr __attribute__ ((noinline)) +getPC (void) +{ + return (_Unwind_Ptr) + __builtin_extract_return_addr (__builtin_return_address (0)); +} + +libc_hidden_def (getPC); + +/* A noinline helper used to obtain the caller's current SP. It + mimics gcc14's __builtin_stack_address() functionality. */ + +_Unwind_Ptr __attribute__ ((noinline)) +getSP (void) +{ + return (_Unwind_Ptr) __builtin_dwarf_cfa() + SFRAME_SP_VAL_OFFSET; +} + +libc_hidden_def (getSP); diff --git a/sysdeps/generic/sframe.h b/sysdeps/generic/sframe.h new file mode 100644 index 0000000000..ce8f6cdf7f --- /dev/null +++ b/sysdeps/generic/sframe.h @@ -0,0 +1,367 @@ +/* SFrame format description. + Copyright (C) 2022-2025 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 General Public License + along with this program; see the file COPYING. If not see + . */ + +#ifndef _SFRAME_H +#define _SFRAME_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* SFrame format. + + SFrame format is a simple format to represent the information needed + for generating vanilla backtraces. SFrame format keeps track of the + minimal necessary information needed for stack tracing: + - Canonical Frame Address (CFA) + - Frame Pointer (FP) + - Return Address (RA) + + The SFrame section itself has the following structure: + + +--------+------------+---------+ + | file | function | frame | + | header | descriptor | row | + | | entries | entries | + +--------+------------+---------+ + + The file header stores a magic number and version information, flags, and + the byte offset of each of the sections relative to the end of the header + itself. The file header also specifies the total number of Function + Descriptor Entries, Frame Row Entries and length of the FRE sub-section. + + Following the header is a list of Function Descriptor Entries (FDEs). + This list may be sorted if the flags in the file header indicate it to be + so. The sort order, if applicable, is the order of functions in the + .text.* sections in the resulting binary artifact. Each Function + Descriptor Entry specifies the start PC of a function, the size in bytes + of the function and an offset to its first Frame Row Entry (FRE). Each FDE + additionally also specifies the type of FRE it uses to encode the stack + trace information. + + Next, the SFrame Frame Row Entry sub-section is a list of variable size + records. Each entry represents stack trace information for a set of PCs + of the function. A singular Frame Row Entry is a self-sufficient record + which contains information on how to generate stack trace from the + applicable set of PCs. + + */ + + +/* SFrame format versions. */ +#define SFRAME_VERSION_1 1 +#define SFRAME_VERSION_2 2 +/* SFrame magic number. */ +#define SFRAME_MAGIC 0xdee2 +/* Current version of SFrame format. */ +#define SFRAME_VERSION SFRAME_VERSION_2 + +/* Various flags for SFrame. */ + +/* Function Descriptor Entries are sorted on PC. */ +#define SFRAME_F_FDE_SORTED 0x1 +/* Functions preserve frame pointer. */ +#define SFRAME_F_FRAME_POINTER 0x2 + +#define SFRAME_CFA_FIXED_FP_INVALID 0 +#define SFRAME_CFA_FIXED_RA_INVALID 0 + +/* Supported ABIs/Arch. */ +#define SFRAME_ABI_AARCH64_ENDIAN_BIG 1 /* AARCH64 big endian. */ +#define SFRAME_ABI_AARCH64_ENDIAN_LITTLE 2 /* AARCH64 little endian. */ +#define SFRAME_ABI_AMD64_ENDIAN_LITTLE 3 /* AMD64 little endian. */ + +/* SFrame FRE types. */ +#define SFRAME_FRE_TYPE_ADDR1 0 +#define SFRAME_FRE_TYPE_ADDR2 1 +#define SFRAME_FRE_TYPE_ADDR4 2 + +/* SFrame Function Descriptor Entry types. + + The SFrame format has two possible representations for functions. The + choice of which type to use is made according to the instruction patterns + in the relevant program stub. + + An SFrame FDE of type SFRAME_FDE_TYPE_PCINC is an indication + that the PCs in the FREs should be treated as increments in bytes. This is + used for a bulk of the executable code of a program, which contains + instructions with no specific pattern. + + An SFrame FDE of type SFRAME_FDE_TYPE_PCMASK is an indication + that the PCs in the FREs should be treated as masks. This type is useful + for the cases when a small pattern of instructions in a program stub is + repeatedly to cover a specific functionality. Typical usescases are pltN + entries, trampolines etc. */ + +/* Unwinders perform a (PC >= FRE_START_ADDR) to look up a matching FRE. */ +#define SFRAME_FDE_TYPE_PCINC 0 +/* Unwinders perform a (PC % REP_BLOCK_SIZE >= FRE_START_ADDR) to look up a + matching FRE. */ +#define SFRAME_FDE_TYPE_PCMASK 1 + +typedef struct sframe_preamble +{ + uint16_t sfp_magic; /* Magic number (SFRAME_MAGIC). */ + uint8_t sfp_version; /* Data format version number (SFRAME_VERSION). */ + uint8_t sfp_flags; /* Flags. */ +} __attribute__ ((packed)) sframe_preamble; + +typedef struct sframe_header +{ + sframe_preamble sfh_preamble; + /* Information about the arch (endianness) and ABI. */ + uint8_t sfh_abi_arch; + /* Offset for the Frame Pointer (FP) from CFA may be fixed for some + ABIs (e.g, in AMD64 when -fno-omit-frame-pointer is used). When fixed, + this field specifies the fixed stack frame offset and the individual + FREs do not need to track it. When not fixed, it is set to + SFRAME_CFA_FIXED_FP_INVALID, and the individual FREs may provide + the applicable stack frame offset, if any. */ + int8_t sfh_cfa_fixed_fp_offset; + /* Offset for the Return Address from CFA is fixed for some ABIs + (e.g., AMD64 has it as CFA-8). When fixed, the header specifies the + fixed stack frame offset and the individual FREs do not track it. When + not fixed, it is set to SFRAME_CFA_FIXED_RA_INVALID, and individual + FREs provide the applicable stack frame offset, if any. */ + int8_t sfh_cfa_fixed_ra_offset; + /* Number of bytes making up the auxiliary header, if any. + Some ABI/arch, in the future, may use this space for extending the + information in SFrame header. Auxiliary header is contained in + bytes sequentially following the sframe_header. */ + uint8_t sfh_auxhdr_len; + /* Number of SFrame FDEs in this SFrame section. */ + uint32_t sfh_num_fdes; + /* Number of SFrame Frame Row Entries. */ + uint32_t sfh_num_fres; + /* Number of bytes in the SFrame Frame Row Entry section. */ + uint32_t sfh_fre_len; + /* Offset of SFrame Function Descriptor Entry section. */ + uint32_t sfh_fdeoff; + /* Offset of SFrame Frame Row Entry section. */ + uint32_t sfh_freoff; +} __attribute__ ((packed)) sframe_header; + +#define SFRAME_V1_HDR_SIZE(sframe_hdr) \ + ((sizeof (sframe_header) + (sframe_hdr).sfh_auxhdr_len)) + +/* Two possible keys for executable (instruction) pointers signing. */ +#define SFRAME_AARCH64_PAUTH_KEY_A 0 /* Key A. */ +#define SFRAME_AARCH64_PAUTH_KEY_B 1 /* Key B. */ + +typedef struct sframe_func_desc_entry +{ + /* Function start address. Encoded as a signed offset, relative to the + beginning of the current FDE. */ + int32_t sfde_func_start_address; + /* Size of the function in bytes. */ + uint32_t sfde_func_size; + /* Offset of the first SFrame Frame Row Entry of the function, relative to the + beginning of the SFrame Frame Row Entry sub-section. */ + uint32_t sfde_func_start_fre_off; + /* Number of frame row entries for the function. */ + uint32_t sfde_func_num_fres; + /* Additional information for stack tracing from the function: + - 4-bits: Identify the FRE type used for the function. + - 1-bit: Identify the FDE type of the function - mask or inc. + - 1-bit: PAC authorization A/B key (aarch64). + - 2-bits: Unused. + ------------------------------------------------------------------------ + | Unused | PAC auth A/B key (aarch64) | FDE type | FRE type | + | | Unused (amd64) | | | + ------------------------------------------------------------------------ + 8 6 5 4 0 */ + uint8_t sfde_func_info; + /* Size of the block of repeating insns. Used for SFrame FDEs of type + SFRAME_FDE_TYPE_PCMASK. */ + uint8_t sfde_func_rep_size; + uint16_t sfde_func_padding2; +} __attribute__ ((packed)) sframe_func_desc_entry; + +/* Macros to compose and decompose function info in FDE. */ + +/* Note: Set PAC auth key to SFRAME_AARCH64_PAUTH_KEY_A by default. */ +#define SFRAME_V1_FUNC_INFO(fde_type, fre_enc_type) \ + (((SFRAME_AARCH64_PAUTH_KEY_A & 0x1) << 5) | \ + (((fde_type) & 0x1) << 4) | ((fre_enc_type) & 0xf)) + +#define SFRAME_V1_FUNC_FRE_TYPE(data) ((data) & 0xf) +#define SFRAME_V1_FUNC_FDE_TYPE(data) (((data) >> 4) & 0x1) +#define SFRAME_V1_FUNC_PAUTH_KEY(data) (((data) >> 5) & 0x1) + +/* Set the pauth key as indicated. */ +#define SFRAME_V1_FUNC_INFO_UPDATE_PAUTH_KEY(pauth_key, fde_info) \ + ((((pauth_key) & 0x1) << 5) | ((fde_info) & 0xdf)) + +/* Size of stack frame offsets in an SFrame Frame Row Entry. A single + SFrame FRE has all offsets of the same size. Offset size may vary + across frame row entries. */ +#define SFRAME_FRE_OFFSET_1B 0 +#define SFRAME_FRE_OFFSET_2B 1 +#define SFRAME_FRE_OFFSET_4B 2 + +/* An SFrame Frame Row Entry can be SP or FP based. */ +#define SFRAME_BASE_REG_FP 0 +#define SFRAME_BASE_REG_SP 1 + +/* The index at which a specific offset is presented in the variable length + bytes of an FRE. */ +#define SFRAME_FRE_CFA_OFFSET_IDX 0 +/* The RA stack offset, if present, will always be at index 1 in the variable + length bytes of the FRE. */ +#define SFRAME_FRE_RA_OFFSET_IDX 1 +/* The FP stack offset may appear at offset 1 or 2, depending on the ABI as RA + may or may not be tracked. */ +#define SFRAME_FRE_FP_OFFSET_IDX 2 + +typedef struct sframe_fre_info +{ + /* Information about + - 1 bit: base reg for CFA + - 4 bits: Number of offsets (N). A value of upto 3 is allowed to track + all three of CFA, FP and RA (fixed implicit order). + - 2 bits: information about size of the offsets (S) in bytes. + Valid values are SFRAME_FRE_OFFSET_1B, SFRAME_FRE_OFFSET_2B, + SFRAME_FRE_OFFSET_4B + - 1 bit: Mangled RA state bit (aarch64 only). + ---------------------------------------------------------------------------------- + | Mangled-RA (aarch64) | Size of offsets | Number of offsets | base_reg | + | Unused (amd64) | | | | + ---------------------------------------------------------------------------------- + 8 7 5 1 0 + + */ + uint8_t fre_info; +} sframe_fre_info; + +/* Macros to compose and decompose FRE info. */ + +/* Note: Set mangled_ra_p to zero by default. */ +#define SFRAME_V1_FRE_INFO(base_reg_id, offset_num, offset_size) \ + (((0 & 0x1) << 7) | (((offset_size) & 0x3) << 5) | \ + (((offset_num) & 0xf) << 1) | ((base_reg_id) & 0x1)) + +/* Set the mangled_ra_p bit as indicated. */ +#define SFRAME_V1_FRE_INFO_UPDATE_MANGLED_RA_P(mangled_ra_p, fre_info) \ + ((((mangled_ra_p) & 0x1) << 7) | ((fre_info) & 0x7f)) + +#define SFRAME_V1_FRE_CFA_BASE_REG_ID(data) ((data) & 0x1) +#define SFRAME_V1_FRE_OFFSET_COUNT(data) (((data) >> 1) & 0xf) +#define SFRAME_V1_FRE_OFFSET_SIZE(data) (((data) >> 5) & 0x3) +#define SFRAME_V1_FRE_MANGLED_RA_P(data) (((data) >> 7) & 0x1) + +/* SFrame Frame Row Entry definitions. + + Used for both AMD64 and AARCH64. + + An SFrame Frame Row Entry is a self-sufficient record which contains + information on how to generate the stack trace for the specified range of + PCs. Each SFrame Frame Row Entry is followed by S*N bytes, where: + S is the size of the stack frame offset for the FRE, and + N is the number of stack frame offsets in the FRE + + The interpretation of FRE stack offsets is ABI-specific: + + AMD64: + offset1 (interpreted as CFA = BASE_REG + offset1) + if FP is being tracked + offset2 (intrepreted as FP = CFA + offset2) + fi + + AARCH64: + offset1 (interpreted as CFA = BASE_REG + offset1) + if FP is being tracked (in other words, if frame record created) + offset2 (interpreted as RA = CFA + offset2) + offset3 (intrepreted as FP = CFA + offset3) + fi + Note that in AAPCS64, a frame record, if created, will save both FP and + LR on stack. +*/ + +/* Used when SFRAME_FRE_TYPE_ADDR1 is specified as FRE type. */ +typedef struct sframe_frame_row_entry_addr1 +{ + /* Start address of the frame row entry. Encoded as an 1-byte unsigned + offset, relative to the start address of the function. */ + uint8_t sfre_start_address; + sframe_fre_info sfre_info; +} __attribute__ ((packed)) sframe_frame_row_entry_addr1; + +/* Upper limit of start address in sframe_frame_row_entry_addr1 + is 0x100 (not inclusive). */ +#define SFRAME_FRE_TYPE_ADDR1_LIMIT \ + (1ULL << ((SFRAME_FRE_TYPE_ADDR1 + 1) * 8)) + +/* Used when SFRAME_FRE_TYPE_ADDR2 is specified as FRE type. */ +typedef struct sframe_frame_row_entry_addr2 +{ + /* Start address of the frame row entry. Encoded as an 2-byte unsigned + offset, relative to the start address of the function. */ + uint16_t sfre_start_address; + sframe_fre_info sfre_info; +} __attribute__ ((packed)) sframe_frame_row_entry_addr2; + +/* Upper limit of start address in sframe_frame_row_entry_addr2 + is 0x10000 (not inclusive). */ +#define SFRAME_FRE_TYPE_ADDR2_LIMIT \ + (1ULL << ((SFRAME_FRE_TYPE_ADDR2 * 2) * 8)) + +/* Used when SFRAME_FRE_TYPE_ADDR4 is specified as FRE type. */ +typedef struct sframe_frame_row_entry_addr4 +{ + /* Start address of the frame row entry. Encoded as a 4-byte unsigned + offset, relative to the start address of the function. */ + uint32_t sfre_start_address; + sframe_fre_info sfre_info; +} __attribute__ ((packed)) sframe_frame_row_entry_addr4; + +/* Upper limit of start address in sframe_frame_row_entry_addr2 + is 0x100000000 (not inclusive). */ +#define SFRAME_FRE_TYPE_ADDR4_LIMIT \ + (1ULL << ((SFRAME_FRE_TYPE_ADDR4 * 2) * 8)) + +/* Used to pass frame information to stack trace routine. */ +typedef struct cframe +{ + _Unwind_Ptr pc; + _Unwind_Ptr sp; + _Unwind_Ptr fp; +} frame; + +/* SFrame stack tracing support */ +int stacktrace_sframe (void **, int, frame *); +libc_hidden_proto (stacktrace_sframe); + +/* Helper used by SFrame tracing algorithm. */ +_Unwind_Ptr getPC (void); +libc_hidden_proto (getPC); + +/* Helper used by SFrame tracing algorithm. */ +_Unwind_Ptr getSP (void); +libc_hidden_proto (getSP); + +#ifdef __cplusplus +} +#endif + +#endif /* _SFRAME_H */ diff --git a/sysdeps/generic/uw-sigframe.h b/sysdeps/generic/uw-sigframe.h new file mode 100644 index 0000000000..77dbff78b6 --- /dev/null +++ b/sysdeps/generic/uw-sigframe.h @@ -0,0 +1,17 @@ +/* Internal header file for handling signal frames. Generic version. + Copyright (C) 2025 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 + . */ From patchwork Fri Apr 11 11:34:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu-Ianculescu X-Patchwork-Id: 110252 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 E2EB138319C6 for ; Fri, 11 Apr 2025 11:37:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2EB138319C6 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=WmsAbHmi; 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=fjgbNsPJ X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 3A0EE3831E2A for ; Fri, 11 Apr 2025 11:35:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A0EE3831E2A 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 3A0EE3831E2A 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=1744371322; cv=pass; b=BCx8rR72w0ak+f2COnIzJRzMKS4JVHH5jBhClMNIPvdK4qxeRyHIBqPWjWerbjdna2/i07GWeY62dcpExYUiWEzvTfmoQ4RJ4cA6NGqebABCHMOmrkEXuG7blpXWUV2WuCKYneiGCqxhhlyB3I93n0Idgpno2B67YCT/JPOiByc= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744371322; c=relaxed/simple; bh=SSwWTd+g2JL8GDlXqGZPRl1XBDLcSyQZEAe0ZnOUvS4=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=XMz476x9HrmVTs7EDMWP82lGpdFu/GU9eTPPI9nzHGMpsZSslHr15ExagonFqyV+f5TSApfxpDtIvoPhtwyuHAGOex+CBc4A5Ocrow5iYW69j+ff0KWDebq0LJO9whRW72rQnMxfV1GpwP0UKXSCIEY6xZKVXklpHfghkfAuUpk= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A0EE3831E2A Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53BBMvp6001661; Fri, 11 Apr 2025 11:35:16 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=YQt65HykDrosLGZhA4gQsGrkY+3O0/NZBEXMbDQMglE=; b= WmsAbHmi7jonsnDyo1oZSkKiTqWnMxkRDYcQwhYm57c0gEPaNHUwadPVuCgSa/aO +h8sQL+FPmR+Q2ZDZTfucGHAnwtdx/0jZNfP1PaQspqAam8FuM/XhcvUnheHIeZl pOWo4D5+3wIs+btn3dmZDm24m0+ffRLPYT4+esS0jWD69uBSWc5IpEr/RI8z3wW5 k+IMBPex3v0mW6hup2Kd+SDsgE/fIPyXrJdkKhKU7I+8HN6i4pEYgHbmsm3u+baw KzvLtwbiseDC1gtMhk/wkCAYWLL7WIgyjtu76tQu1agE8BLtQxy5unU2WJfxGtaq n5KpmDpysZj6e2+17T+Dpw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45y25080rk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:15 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53BB2H0E023792; Fri, 11 Apr 2025 11:35:15 GMT Received: from cy3pr05cu001.outbound.protection.outlook.com (mail-westcentralusazlp17013074.outbound.protection.outlook.com [40.93.6.74]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45ttykx7cu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kL1dGiPIFbaR5rHh4bw0Jhh48pB2EZBOF3WXeZ8jZtxvbNoe/gCwPDKdE5FEZiOIY47PAQSEKnug0F2suD2M2ve55qd3M94alsJKZHbhqzY83v7nfFPt9ETAodtQuejst7pJnJZ/NcHINZCjKcmQQABp6c64Nv8OqJBNeEW9mIP8pj0e5ZpqterPohZ0Dp+ejXE1RjKq8TvpLeMRZbKjUPzRwMWeCoJBooGXZl2LHuXqH8n4HRmEaznehM+k7h0EpLFsmTXv9IEeOPsOlMdrHrWKSXp/HOYLjjLpGmYAABsrDUniqjkRPXzhu0qLBj+Y2Yher0Lq2si79GgJu7dYCQ== 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=YQt65HykDrosLGZhA4gQsGrkY+3O0/NZBEXMbDQMglE=; b=Bs6MfEtHT6pewB1Yvb6W6SDrYkSjuU797altWKjrK+8Gc8oHfBTSjEkggue4LE/oSGuEyYVYSKsvr9W/hrSHgwT8usEYbTDiYw8Ew5spmWa2T9HtDRHFLKNxWNkYeDheE6Jb55+LiY1Wn1yLAFKUizVrQfUjlUJTipIDbvspKeI4+aRs7NK0UH2PGHkWbUBWL2MWDdfC8uitIo7zWltR3eA7mVgbxCj2U/nawyBp/jQ4qXysmBuMdxmUvDVCD2PeUkQ8YIKwIFJDFk8ejPIN3CW5vL+BtLTwCqAgLQ2Ta4VZSg1lRxFSUAPrR5IuhjBskxeLgbYDx3wRKCM+1kjR8g== 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=YQt65HykDrosLGZhA4gQsGrkY+3O0/NZBEXMbDQMglE=; b=fjgbNsPJNLGvYdzJUpxpy8dUnTROTlAQF7K6Yj+ZJEo/tzpxEUFb5MEagghbqAgUbJ6MGAhQF1Hi4xt4gQ/e9rbLxH3JHGsFTw1/fDaOhFNqgJQSDg8F/Yzxypn3ON9+NBoxQdYRzVSVlFI6dIMARr9CsebzFo35EsqOMdKT4go= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CO1PR10MB4404.namprd10.prod.outlook.com (2603:10b6:303:90::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.27; Fri, 11 Apr 2025 11:35:13 +0000 Received: from CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e]) by CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e%6]) with mapi id 15.20.8632.017; Fri, 11 Apr 2025 11:35:13 +0000 From: claudiu.zissulescu-ianculescu@oracle.com To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, indu.bhagat@oracle.com, jremus@linux.ibm.com, fweimer@redhat.com, josmyers@redhat.com Subject: [PATCH v2 3/5] configure: Add --enable-sframe option Date: Fri, 11 Apr 2025 14:34:54 +0300 Message-ID: <20250411113456.15213-4-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250411113456.15213-3-claudiu.zissulescu-ianculescu@oracle.com> References: <20250411113456.15213-1-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-2-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-3-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1PR06CA0123.eurprd06.prod.outlook.com (2603:10a6:803:a0::16) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CO1PR10MB4404:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d469f0c-94ef-4cf1-c93b-08dd78ecec3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: 0l/+Uh9Y8VU+EcjfSl8gZUYWBlT4wpU+kZQTfMsaCJ03khba846DJk6uoR10OWuLYSBkSS73qiGcazxv4yrxSS9SbSn9imZNEm+7mWth5SKw6l/q7QjOrpNGkDbp6+UU6GFfiABnIMH3sK1dbMWLz9CU3lAJ8uwRBZCcT7MDyasFkXJZ1Bu+GoDU7WLf/4Gd3X4I9w/3rwd22dJb2K3ZBisrrojrBkR/7dglo5a/4fVRlx7+5fmL40yflwMwsm/GtSjWKpdCndEK5ju2WDg9o4k2PNpkGC5tMg2kNG0UiUM2y8QwjZ77X3tZdRupUmeqLrmJG/EMNsEv4cW/Fn7g0I5EaB/h5Z1r4FSApI5u+EHXiwic7vgqbpf8nhMkaae7eF3cPGENtz6mrsn6g+C4o8D7q69iGrPZFLF2ouMwOJISjxrWbIse0bYW2mQTPqJDm4sWCGv6Gao1dek+7RikrE2r7id8x5K0LA8fJbacQZHXx9nuQBsusgNEDEYVg9XPUBtHER/p7WRhJgRn1wdtgG5lDHg4TJshEeGeOMR7dRCOKMgIYYiAnumUGdQdgU1Q4eGQwaQZ1VSvHpxSKI7mJp2Vd/a7IWCtD7CalinjFzvYMH4SPUdHoxSen0o+NmQQLILxFTVDvYib3rtIYVp5XUVhLAg5D9k4Mz1DFBym5kI8CLTTw8a741pzJARZ2VpJfDs5hOWLwar13Yi14a+rWtJN1iFlfB0JVUEVt0zSjd+EYj2doHjmy8ZLeFEr93Bqytmyl+12fvyXJf7dm9jSk8L3eKHgMGzApBsBvJRxkdJ41gII6vFLNZvrFD3HALf+evHR1RjeRR4fvYHmdZB5mIh7k5Jpy/jS7J7sF/K/ITIq/wEg06b0V9jqi72Af9Oc/BSqqjPRy3mOVtU+Twiv9fH+KiMYcwbAVUAoPi1UZlNSCTzp0G785BWY1Vn9FjTevDI/gMNOX552WAtNOfIJmn7NQA+2xLBsu2J9YOq/0oskqAKCUltJuEYBPJXKm5EBNCCXEHy3Ep+1oUazKt34YsiqA3StM9XCMo0Oca9HeKh0ypTm+F5fw4E4ybkKD+w5g7dWWiygKuMxI2BrFh42C8i1KnRt3JaKncGKn/4jtmi/7Zh9f17IM/Cx14RVFjwYv8G4e2t8rV4R3iRDxAsJEtW4M9LtT56OekyfSG7jrbpgLzDJ9XjtzfiFD2jYwCCVy3ijzy0fXLlejdWwVRBZXKNJ29LUliIOjCUcRromlQF+/2G0F8y0sC+wSWuXf2PwuYK83wR9cN6O6bgvMGSvEPvKUWE7HHan2Y29zJdu8mV88i2Zg9yh8hHk9Hx0G1exwDPUGktTPb0rq5r07wIkPLoJHJPvHl39pYgo0mswMUiVHaT3gTLYH6ACfx7b6/ze2ap4TvF84pcUIb3q1VyKowFnC1YelwisX1INOCy7o3U= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY5PR10MB6011.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7SNLYSMT3tc51LgvXkPVsw99IIGoSkLNZHpFqcAGSyhvKdq4F42QZwC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jx0jAHI/ZcQRlazLrAEncAdmeYV/9ZgdaesDoL/XL54SnvGpTCFgawyuDPDB11t8YeWElELmY7S+DP9vE1AV7ju5DTDYZGVAOHD++u/fDsVUUZgenC8LS5/iUCuiXuWh0JwG13ru2p04= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d469f0c-94ef-4cf1-c93b-08dd78ecec3f X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2025 11:35:13.0297 (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: UZjrNHsTpZYQH8OiEOlm0rFhJnuzbecnkEtG6g8xZofFk00E3DBZYmR/IRBufo3gV3HFYENxtocDAFz7kCFfrlidbDiqclQQYnlkuc75C7L40JOy8l//7apweZTEwR7JBVvqeXMdxzb4z/+rxTB0RQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4404 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_04,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504110073 X-Proofpoint-ORIG-GUID: zRrtDgXXEGhSN0JirlvuQzndQ_kD5FCP X-Proofpoint-GUID: zRrtDgXXEGhSN0JirlvuQzndQ_kD5FCP X-Spam-Status: No, score=-13.4 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_H5, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Claudiu Zissulescu Enable SFrame stack track information. The --enable-sframe option allows the glibc build to compile with SFrame stack track information. Thus, enabling glibc's backtrace to work within glibc. Signed-off-by: Claudiu Zissulescu --- INSTALL | 5 ++ Makeconfig | 8 ++- NEWS | 2 + config.make.in | 1 + configure | 128 ++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 43 +++++++++++++++ manual/install.texi | 5 ++ 7 files changed, 191 insertions(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index 24e3c8d25b..25abdb3969 100644 --- a/INSTALL +++ b/INSTALL @@ -284,6 +284,11 @@ if 'CFLAGS' is specified it must enable optimization. For example: Library. If not provided, 'LEVEL' defaults to highest possible value supported by the build compiler. +'--disable-sframe' + By default, the GNU C Library is build with '-Wa,--gsframe' if the + current GNU 'binutils' supports it. You may want to use this + option if you don't plan to use SFrame stack unwinder. + Default is to disable fortification. To build the library and related programs, type 'make'. This will diff --git a/Makeconfig b/Makeconfig index a87ff7b1d3..7d360f7daf 100644 --- a/Makeconfig +++ b/Makeconfig @@ -1011,6 +1011,12 @@ else +cflags += $(no-fortify-source) endif +# Enable SFrame while compiling for stack backtracing. +ifeq ($(enable-gsframe),yes) +as-sframe = -Wa,--gsframe +endif ++cflags += $(as-sframe) + # Each sysdeps directory can contain header files that both will be # used to compile and will be installed. Each can also contain an # include/ subdirectory, whose header files will be used to compile @@ -1158,7 +1164,7 @@ endif ifndef ASFLAGS ASFLAGS := $(filter -g% -fdebug-prefix-map=%,$(CFLAGS)) endif -override ASFLAGS += -Werror=undef $(ASFLAGS-config) $(asflags-cpu) +override ASFLAGS += -Werror=undef $(ASFLAGS-config) $(asflags-cpu) $(as-sframe) ifndef BUILD_CC BUILD_CC = $(CC) diff --git a/NEWS b/NEWS index b1ae1c31ca..22e0e0fa85 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,8 @@ Major new features: * The iconv program now supports converting files in place. The program automatically uses a temporary file if required. +* New stack tracer using SFrame. + Deprecated and removed features, and other changes affecting compatibility: * The big-endian ARC port (arceb-linux-gnu) has been removed. diff --git a/config.make.in b/config.make.in index 36096881b7..db2367f007 100644 --- a/config.make.in +++ b/config.make.in @@ -51,6 +51,7 @@ c++-cstdlib-header = @CXX_CSTDLIB_HEADER@ c++-cmath-header = @CXX_CMATH_HEADER@ c++-bits-std_abs-h = @CXX_BITS_STD_ABS_H@ enable-werror = @enable_werror@ +enable-gsframe = @enable_gsframe@ have-z-execstack = @libc_cv_z_execstack@ have-protected-data = @libc_cv_protected_data@ diff --git a/configure b/configure index ec0b62db36..7908121794 100755 --- a/configure +++ b/configure @@ -620,6 +620,8 @@ DEFINES static_nss profile libc_cv_multidir +enable_gsframe +READELF_SFRAME shared static ldd_rewrite_script @@ -808,6 +810,7 @@ enable_mathvec enable_cet enable_scv enable_fortify_source +enable_sframe with_cpu ' ac_precious_vars='build_alias @@ -1491,6 +1494,8 @@ Optional Features: Use -D_FORTIFY_SOURCE=[1|2|3] to control code hardening, defaults to highest possible value supported by the build compiler. + --enable-sframe Enable SFrame stack trace information [default + depends on toolchain] Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -4855,6 +4860,16 @@ case "$enable_fortify_source" in *) as_fn_error $? "Not a valid argument for --enable-fortify-source: \"$enable_fortify_source\"" "$LINENO" 5;; esac +# Check whether --enable-sframe was given. +if test ${enable_sframe+y} +then : + enableval=$enable_sframe; use_sframe=$enableval +else case e in #( + e) use_sframe=notset ;; +esac +fi + + # We keep the original values in `$config_*' and never modify them, so we # can write them unchanged into config.make. Everything else uses # $machine, $vendor, and $os, and changes them whenever convenient. @@ -8110,6 +8125,119 @@ fi config_vars="$config_vars enable-static-pie = $libc_cv_static_pie" +# Glibc stacktracer supports SFrame v2 or newer +libc_cv_readelf_version_ok=yes +for ac_prog in $READELF +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_READELF_SFRAME+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) if test -n "$READELF_SFRAME"; then + ac_cv_prog_READELF_SFRAME="$READELF_SFRAME" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_READELF_SFRAME="$ac_prog" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi ;; +esac +fi +READELF_SFRAME=$ac_cv_prog_READELF_SFRAME +if test -n "$READELF_SFRAME"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $READELF_SFRAME" >&5 +printf "%s\n" "$READELF_SFRAME" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + + test -n "$READELF_SFRAME" && break +done + +if test -z "$READELF_SFRAME"; then + ac_verc_fail=yes +else + # Found it, now check the version. + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking version of $READELF_SFRAME" >&5 +printf %s "checking version of $READELF_SFRAME... " >&6; } + ac_prog_version=`$READELF_SFRAME --version 2>&1 | sed -n 's/^.*GNU readelf.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'` + case $ac_prog_version in + '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; + 2.4[1-9]*|2.[5-9][0-9]*|[3-9].*|[1-9][0-9]*) + ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; + *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; + + esac + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5 +printf "%s\n" "$ac_prog_version" >&6; } +fi +if test $ac_verc_fail = yes; then + libc_cv_readelf_version_ok=no +fi + + +# Check the current toolchain for SFrame support +if test $libc_cv_readelf_version_ok = yes; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for SFrame support" >&5 +printf %s "checking for SFrame support... " >&6; } +if test ${libc_cv_default_sframe+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) cat > conftest.c </dev/null 2>&1 && \ + # Check if .sframe section is present and if version > 1 + $READELF --sframe conftest.o | grep "SFRAME_VER" | grep -qv "VERSION_1"; then + libc_cv_default_sframe=yes + fi + rm -f conftest.c conftest.o + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_default_sframe" >&5 +printf "%s\n" "$libc_cv_default_sframe" >&6; } +fi + +# Prevent enabling sframe on non-supporting toolchains +enable_gsframe=no +if test $use_sframe$libc_cv_default_sframe = yesyes || \ + test $use_sframe$libc_cv_default_sframe = notsetyes; then + enable_gsframe=yes +elif test $use_sframe = yes; then + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} +as_fn_error $? "toolchain doesn't support SFrame V2 or higher +See 'config.log' for more details" "$LINENO" 5; } +fi + + # Set the `multidir' variable by grabbing the variable from the compiler. # We do it once and save the result in a generated makefile. libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory` diff --git a/configure.ac b/configure.ac index 7c9b57789e..2d8c1be411 100644 --- a/configure.ac +++ b/configure.ac @@ -426,6 +426,12 @@ case "$enable_fortify_source" in *) AC_MSG_ERROR([Not a valid argument for --enable-fortify-source: "$enable_fortify_source"]);; esac +AC_ARG_ENABLE([sframe], + [AS_HELP_STRING([--enable-sframe], + [Enable SFrame stack trace information @<:@default depends on toolchain@:>@])], + [use_sframe=$enableval], + [use_sframe=notset]) + # We keep the original values in `$config_*' and never modify them, so we # can write them unchanged into config.make. Everything else uses # $machine, $vendor, and $os, and changes them whenever convenient. @@ -1776,6 +1782,43 @@ if test "$libc_cv_static_pie" = "yes"; then fi LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie]) +# Glibc stacktracer supports SFrame v2 or newer +libc_cv_readelf_version_ok=yes +AC_CHECK_PROG_VER(READELF_SFRAME, $READELF, --version, + [GNU readelf.* \([0-9][0-9]*\.[0-9.]*\)], + [2.4[1-9]*|2.[5-9][0-9]*|[3-9].*|[1-9][0-9]*], + libc_cv_readelf_version_ok=no) + +# Check the current toolchain for SFrame support +if test $libc_cv_readelf_version_ok = yes; then + AC_CACHE_CHECK([for SFrame support], libc_cv_default_sframe, + [dnl +cat > conftest.c </dev/null 2>&1 && \ + # Check if .sframe section is present and if version > 1 + $READELF --sframe conftest.o | grep "SFRAME_VER" | grep -qv "VERSION_1"; then + libc_cv_default_sframe=yes + fi + rm -f conftest.c conftest.o + ]) +fi + +# Prevent enabling sframe on non-supporting toolchains +enable_gsframe=no +if test $use_sframe$libc_cv_default_sframe = yesyes || \ + test $use_sframe$libc_cv_default_sframe = notsetyes; then + enable_gsframe=yes +elif test $use_sframe = yes; then + AC_MSG_FAILURE([toolchain doesn't support SFrame V2 or higher]) +fi +AC_SUBST(enable_gsframe) + # Set the `multidir' variable by grabbing the variable from the compiler. # We do it once and save the result in a generated makefile. libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory` diff --git a/manual/install.texi b/manual/install.texi index 3e68a3d823..f3086da576 100644 --- a/manual/install.texi +++ b/manual/install.texi @@ -311,6 +311,11 @@ Use -D_FORTIFY_SOURCE=@option{LEVEL} to control hardening in the GNU C Library. If not provided, @option{LEVEL} defaults to highest possible value supported by the build compiler. +@item --disable-sframe +By default, the GNU C Library is build with @option{-Wa,--gsframe} if +the current GNU @code{binutils} supports it. You may want to use this +option if you don't plan to use SFrame stack unwinder. + Default is to disable fortification. @end table From patchwork Fri Apr 11 11:34:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu-Ianculescu X-Patchwork-Id: 110254 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 26EC738319D4 for ; Fri, 11 Apr 2025 11:41:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26EC738319D4 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=RMm2VEXB; 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=g7vcDx3K X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 4B08938319C6 for ; Fri, 11 Apr 2025 11:35:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B08938319C6 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 4B08938319C6 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=1744371324; cv=pass; b=PXmYNY9GVw8DT2z/WNDfJmq/YHTktRmzPQ/QsD0BB06A+ybtyU8TtOxc/5E/J4KueyQyhmuhfoz9Di6Ze94M7havZY76/PgOKZVl6+9niWsbvPIixnPgEgUULrzf3UhUatQec0heNR9uF7XL3XK8eV79TLQT0YKZNiZrxjsLzPQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744371324; c=relaxed/simple; bh=cZObS6s9QxS8KOwUiKP741uz4f4aroTd5ugcdLvdDHI=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=qeJ1FLaV2wKN/zf39YY+2MYzDdBepFVo7aLzZV8M7ypvxsM5BhUIp5y5OQfgBi/3lmkaKPTDRWk/ZO/Q3AnqB6xtqOt4IYel5/QKFVp7bdINJybXetOuTOrvWOaC0gB9l+YHUkFW7r40WeFgub+OEJkQHH3dUT98WjTesfSkOrk= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B08938319C6 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53BBM44o000906; Fri, 11 Apr 2025 11:35:21 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=iSn+Sg0XG8To2pGot6sBRtDw7HOpeMOZtYPzXTWd8T0=; b= RMm2VEXBEkgkBnoR6wu32N0F067vyF2sjrxGC2gC1rE6H4dcL127zolHpYZc8Gxu PIp6eB/fLS4ubxGeotCxVhlFFsQnkj5JlodBWnyxk/tDdlQcaC/nY2hLvkZLYqaY kEFZCA9ulHbydb5z8KaLFh6dX2dxbedr1yEkhfW6rnW8+PTt5z1fthFrXq5sDrkk m90AZgpeiiRcltqzgvnq2oWgvhFHm5VxevPqYK54byFwZ2PrBCXHMc5CNTyif5vZ 4eRt1XudhPYn1eL67f+mKLVFePVhCSsaW9TMd21q2UEYiDjlHZlWHTZX+E4HIsdz 8BTBGGxxNfAOiBDLv2vj5Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45y25080rt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:20 +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 53B9sIcr022183; Fri, 11 Apr 2025 11:35:20 GMT Received: from cy3pr05cu001.outbound.protection.outlook.com (mail-westcentralusazlp17013076.outbound.protection.outlook.com [40.93.6.76]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 45ttye9rqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Yn/6TGc8leuW0PgrVI4trHemskqArTRiDf6Nhu/gTJm/j2m4dce8r+U71cYtsj3ZxtGqG7HZG6+h0bAA+DsKgzT/hFnlaSVJEbYHtbfioBGXMUbTI7Fwcs8HjDsJRr97RhNHtrFmW8EBBmLbVT2S9bFUDvRNc0K3j8B8uOCNPAs7lBi7CJ9ZoMergZKispgYQnhXRB13pfWOVGWHkGv7P+DGMj1+3o71DWpld2NWsRmAiuHDIbLH/oFm3mhbw5xM2poFYGbHHH9DeFJGZO2ddbx3BRwHIIEtPuMSKNMZs70rIFTjvKw7AUO/iq9KvCfXzsbMjI+H4KiLBTKTWMycsw== 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=iSn+Sg0XG8To2pGot6sBRtDw7HOpeMOZtYPzXTWd8T0=; b=kaZs7TLRqYvR59cf8Osvh1KSHW+Y3R0hHsBdjTlyi6BO/WmBHsq4hSsZiIVYVS+4kE86l65zc3NUxmAi0ayKR85+aGDNq4tTY7PVsPVg06qLjAsRci1uKbXJCtc+wmjbg2tvPU+pWpDA2gZLBIxLwxfsBLKUzuH3Hz/aSecHajvI+LxorJp3b/ymCwIgpxFu2CJYa9zRsJMmlSk0Q0p58QfFsD1Mmlfes2yBlRyzKpLHREkeB2ERPMPSpSvpvXY89i1JbxvnZb0K5mkM+BXgtN/pe0UdXaLioQoAX941v+FmqzywEl5NpsjzhkeoiWi9UrbTPKRg4eEYuxkWq3fq1A== 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=iSn+Sg0XG8To2pGot6sBRtDw7HOpeMOZtYPzXTWd8T0=; b=g7vcDx3KKvIRliQ8HpeQwxj34WxiofSJmQPc/dagOMwFpQq2WGLDEKVJIj58R5Wmt1QpuVN/qpnxGXn+paK7saUxnH/j+1Wzuz5jJ6v8SWXk5XSLS3Ho5l0SlH+gVBCyTg7LvsU9ru2vnYfVh3tMW8wEoj3vCENFkpPHG/vWjVM= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CO1PR10MB4404.namprd10.prod.outlook.com (2603:10b6:303:90::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.27; Fri, 11 Apr 2025 11:35:17 +0000 Received: from CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e]) by CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e%6]) with mapi id 15.20.8632.017; Fri, 11 Apr 2025 11:35:17 +0000 From: claudiu.zissulescu-ianculescu@oracle.com To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, indu.bhagat@oracle.com, jremus@linux.ibm.com, fweimer@redhat.com, josmyers@redhat.com Subject: [PATCH v2 4/5] x86: Add SFrame support for x86 architecture Date: Fri, 11 Apr 2025 14:34:55 +0300 Message-ID: <20250411113456.15213-5-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250411113456.15213-4-claudiu.zissulescu-ianculescu@oracle.com> References: <20250411113456.15213-1-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-2-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-3-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-4-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1P195CA0047.EURP195.PROD.OUTLOOK.COM (2603:10a6:802:5a::36) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CO1PR10MB4404:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ddefbe9-ad72-45fe-12f7-08dd78ecef12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: hqOCo9VfzkYhqj8CInYx706gOp6J2vq0A42mtrOaQ2ah/OWgQtHgvDBun31QTQRvWykNZ3kf/mUKAutD2xVdKcETsvOy9NlXdwNfg0kb+nwgVEjJKctBsQQ2uohjKampW2wmBJQzPuOXqpReAa4XvUaMmyO5lnavruttnR1ZrGgdyqGaEQ4e/kxu6BWFCT65B4YyPmKRdHnA4+dO4FoRz3euHQmsQ4kMwqQlxTOHfHCLAB/xqdQTajRkFefR2iKRvlSR+WHHJT525kqy/9K3CoSM51Pck7jRF9Xq6o1Uuv+IcA3jwI9g4M8Pocua6UJ88+OC8aHeUa7vjG4R9O3IoZ35LcxkjNNkI2l98S/6BaLxs2+JvEGRs8lxgBSRrKr16+dviSsfOWtP+SseAq0/lgEUFWQHVtWCSzjA5TQTvuL6mWIEYEPWBARa/z82Jvh/hO3CB3RehpLkg3YLcneK+H9dNYOOPaGyrjbkl4aNoDW6uUbFbO306cvZcrStVZZkYptbsT8R1bYqWNmYgjJqw9MJddYS3nqzfX39CDCp2zpzeLRWjBPOiQuXPcS2t5ZiEm11UojCqiVx/rUM2cMicio/hAhm09u6bxp7A56rohJvN0yVUl8c2DVMZJW7csgswkq/x7o3T3ITcJg6kAMRnoemGujXEJ4DQwx9qmj2ugNHwaB1YE4iTUA0W1BpRw1XvFIFLbOz4na6fwXskBoFAHoZFTqc5nw6sL0LFRfSthLamaDYKHljs1PPUFVgVlYWriD1V1eH0vo0ADH8Od+DuLaSns+Sb33FjmBHAO7Wdaf6VWh/0kJdiSd6C4ToPt6oXAOPwiJMbXr8HhBY6p+jM4w7uLTRzAPaQGj6sDg9EaAgIhbLMX//onSYryUjt7OMzq/EUzQIj1ZfUdmOPgMQlKHy0TkmLYcxC6RpMDWCD4UY+vZIBRB1sjqAXpdque4RB2eiKqVVZQkX4nT6fOpVaPvp7lnuDnRhv9372dHF4478/8jIItY0lV1KWQKtGc8GVV/p1lLsDE2EW/wtKCCkKbY2aC4mbe2BSXe6erIPmmyipfY8vkVWGE86RKz8/leQhMCmxvYHqazwAzimlnt5cS66iMn4YqxvPq1l8H2ggDFsv9/Agq7hwqBRIB0y/0E3Q3kOPk6o7n1tHQit45YTwDhga44ZfrsgwHkEe0KR/lViDyb1fObNHaM3JLqPU+WyqnreAC7X9NXk9+skMj0jyQ2w1xmCjsKB5d34WDb5g2h2NJbNHcuu1/Lg4SFjNsCC6sBtJzGaIIo0n3IpPenCwy6beO98ehGkfAP4l3CkXTtnkKW1EWB2hCpd/6m5lEWeJumZeSXfeb0nZdL8E4+eYARDdxKoAEvsqJBl99W+JWw= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY5PR10MB6011.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: E/xfPTEw/Hg0WwNrXk3ZfgeDt92S9EQSQKR78wYDoFrjwAKTHIXS5G48EX95chYVWnQCZ5DK4G5CtdqV5QHa0RpEXAVSZLRljsgOQ0pDfmd7NvXeLwpiOj3G1F8TFrpsty9zevgGCzTqUMJHLPa6z/xM0h8dRYbX46FMbbXz8L1bdFitM6aMS3IHDs/M4RgPGUCqu6MVIgzBdTCSU89pjA6GVIaKfX7uMGtX3pb425/MJmqUH6SstmLf2liz1B0Sg+d/xyfiyC86wnktkZtMuQR3R0P8NiU17fmZ118OOYPEoccKo61pHTf2W3YGS9s0kToWO78A6bww1UO3WiZzOtXIg0MjI2KSKXeFWnpWSfdxzjA2cdRLowbCrzjIJGvHTW2s1EljAQvHVbuKg9/bFQV5K5hIXAmkT6zFClxqUxdIDlS6Jk7MLTSEVcC+3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iUrueVu1SMruJaD1XC2KosrjIOAr36KYWmYX0EmdXBdnRIJWq9PIKLgdUYL9wDrxafsQT94wPx8pP5s0EsgLBU8BOGYsbDpjEFRCFnnHcRbuBhiVF/TDUfomOiDwxBpeRM3NcbzGGWsfhGaHcOWEY76U4PqmyC4/ X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 1WCS4wVPnkyETdQABy6d8ogQWTh4fJZNDoSatVIkHVrTaZRN/2phXqEnmf1J13lW39Oed5qQTEfYqgi95aQb6NbXor/tJg0dQWoysOxZUNIdc63HkizD/wLVP2aRfnfJLgTm3b77662D6O2AkZ4yTdfd7+y6eqY1KWYCNp0UPjLCG4wMa4vMfhHH6JcNoSg3kgPc0deKW10Nz0rCbzNEzpDSE+2TVNbSY/HcMCZW8+YFeeTiuWUSeTRmeaKjzHgk8FQYFNYECe8dyYE8S5GGEfuOCuTVsZDdPlPejtUWVOaXuKagdASzbTqtgnCjyRmpO+J4CtuXJejaoNlxzvn10sVm0iX2obmHgv7TXnES3Rxfq1riZxU/Z8MtLyjZ5/G8T5eCjFDAkPgKDOK0HFZvgJTgbk2IFclvtKPAUUtCEo4jbx60yVrt3Vxf3Hl4NoiYLFwMKfhluAAx198GbXu9NLKTQTZavp4Kbp0QgsdDCFwyW4d8OEtG2NhyEul+QLe1jkexwdPU0663tJC4Y9eoNcCaSQjdlPKlMsvhl80YnuRioK2t4Az/nzM0A8BEQ3FT9pAXcp1jWHYlc5bxs5l1pLSNWQA3xVQvl77o2yzOJIE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ddefbe9-ad72-45fe-12f7-08dd78ecef12 X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2025 11:35:17.7410 (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: CjlOiUli44m6ADXN59Bzei/1gUj18i/+oWDu/GMQ5WgPdHzbJ+H6eKhdd6yxLUZmDts/ozNhFeVIO+uxCIFZ9Y2nnex7CqOfGgDh2DxhTBbd+Q0P6UFC0pGr3w6glk73im1BgLK5J/nrBZRlCoEIsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4404 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_04,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504110073 X-Proofpoint-ORIG-GUID: 8Zh6BSiX5svu6dAWbxInjFHUSbmZpO1j X-Proofpoint-GUID: 8Zh6BSiX5svu6dAWbxInjFHUSbmZpO1j X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Claudiu Zissulescu The SFrame is well supported by x86 architecture since binutils 2.41. Enable it to be used as default frame tracer. Signed-off-by: Claudiu Zissulescu --- sysdeps/unix/sysv/linux/x86/uw-sigframe.h | 99 +++++++++++++++++++++++ sysdeps/x86/bits/dl_find_object.h | 1 + 2 files changed, 100 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/x86/uw-sigframe.h diff --git a/sysdeps/unix/sysv/linux/x86/uw-sigframe.h b/sysdeps/unix/sysv/linux/x86/uw-sigframe.h new file mode 100644 index 0000000000..cad53255cd --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/uw-sigframe.h @@ -0,0 +1,99 @@ +/* Signal frame backtracing support for SFrame on AMD, x86-64 and x86. + Copyright (C) 2025 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 + . */ + +/* This code is inspired from libgcc's MD_FALLBACK_FRAME_STATE_FOR + implementation. See libgcc/config/i386/gnu-unwind.h */ + +#include +#include + +#ifdef __x86_64__ + +#define MD_DECODE_SIGNAL_FRAME x86_64_decode_signal_frame + +static _Unwind_Reason_Code +x86_64_decode_signal_frame (frame *frame) +{ + unsigned char *pc = (unsigned char *) frame->pc; + struct sigcontext *sc; + + /* movq $__NR_rt_sigreturn, %rax ; syscall. */ +#ifdef __LP64__ +#define RT_SIGRETURN_SYSCALL 0x050f0000000fc0c7ULL +#else +#define RT_SIGRETURN_SYSCALL 0x050f40000201c0c7ULL +#endif + if (*(unsigned char *)(pc+0) == 0x48 + && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL) + { + ucontext_t *uc_ = (ucontext_t *)frame->sp; + /* The void * cast is necessary to avoid an aliasing warning. + The aliasing warning is correct, but should not be a problem + because it does not alias anything. */ + sc = (struct sigcontext *) (void *) &uc_->uc_mcontext; + } + else + return _URC_END_OF_STACK; + + frame->pc = (_Unwind_Ptr) sc->rip; + frame->sp = (_Unwind_Ptr) sc->rsp; + frame->fp = (_Unwind_Ptr) sc->rbp; + return _URC_NO_REASON; +} +#else /* !__x86_64__ */ + +#define MD_DECODE_SIGNAL_FRAME x86_decode_signal_frame + +static _Unwind_Reason_Code +x86_decode_signal_frame (frame *frame) +{ + unsigned char *pc = (unsigned char *) frame->pc; + struct sigcontext *sc; + + /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80 */ + if (*(unsigned short *)(pc+0) == 0xb858 + && *(unsigned int *)(pc+2) == 119 + && *(unsigned short *)(pc+6) == 0x80cd) + sc = context->cfa + 4; + /* movl $__NR_rt_sigreturn,%eax ; int $0x80 */ + else if (*(unsigned char *)(pc+0) == 0xb8 + && *(unsigned int *)(pc+1) == 173 + && *(unsigned short *)(pc+5) == 0x80cd) + { + struct rt_sigframe { + int sig; + siginfo_t *pinfo; + void *puc; + siginfo_t info; + ucontext_t uc; + } *rt_ = context->cfa; + /* The void * cast is necessary to avoid an aliasing warning. + The aliasing warning is correct, but should not be a problem + because it does not alias anything. */ + sc = (struct sigcontext *) (void *) &rt_->uc.uc_mcontext; + } + else + return _URC_END_OF_STACK; + + frame->pc = (_Unwind_Ptr) sc->eip; + frame->sp = (_Unwind_Ptr) sc->esp; + frame->fp = (_Unwind_Ptr) sc->ebp; + return _URC_NO_REASON; +} +#endif /* ifdef __x86_64__ */ diff --git a/sysdeps/x86/bits/dl_find_object.h b/sysdeps/x86/bits/dl_find_object.h index 00860f4fbe..0428305600 100644 --- a/sysdeps/x86/bits/dl_find_object.h +++ b/sysdeps/x86/bits/dl_find_object.h @@ -27,3 +27,4 @@ #endif #define DLFO_STRUCT_HAS_EH_COUNT 0 #define DLFO_EH_SEGMENT_TYPE PT_GNU_EH_FRAME +#define DLFO_SFRAME_SEGMENT_TYPE PT_GNU_SFRAME From patchwork Fri Apr 11 11:34:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Zissulescu-Ianculescu X-Patchwork-Id: 110253 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 3137538319DB for ; Fri, 11 Apr 2025 11:40:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3137538319DB 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=nn7gd5fv; 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=aW2LTjly X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 4C69B383581C for ; Fri, 11 Apr 2025 11:35:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C69B383581C 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 4C69B383581C 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=1744371328; cv=pass; b=w+Hg9J6fzUx43moqER70WMJA378ph+soW+M0Z5jVBi7X0RdljC/m8s4lkhHNaUBmkDYACMt92L7io0ktQUE4b2cPxr9aJg/vnhQz+4vy+PYx91G2gcaeMctSa+tPucvC7NoHRnDqIuY54Ah/+W3ReDmjxiD8UPC0G2YUm6ZJUUg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1744371328; c=relaxed/simple; bh=kIB4cteQN99mj1gbR4lPKfKAQwaWS4MKj4f6OsCmImU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=wqzBw76IsOVWnOYj8umPtz/BHfksV2ugR4RcS9TJjCBMwevKtEFE8ux4kgfKYkZemxACoWjrwxhwGn14gVgCJWRBIyonLp2aOD0jVKmAiqv+GaAkvCOAvmr/ukOX1m1ZZX7n1vuy7kEz4t4ZTLOIobCrPn1QsXKO3nvtD2+4boQ= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C69B383581C Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53BAMn5V021992; Fri, 11 Apr 2025 11:35:26 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=K8sBtbF6/yvdpI70PWYYbVuZ0mS3SuEtNAh2rjCN4xo=; b= nn7gd5fvLv/a99QrBQtyHJlQVqX19/U+dPsCNjYcKqRCmiT/YRvnzjVtVOXQ2haj K3seJJ8ioLwjBHXt/W17eYQEobRSDvfVUSPte909O37J0HqAnD/W5tdkl8sxyrYQ xvr6wfHbS+pmhgCRiF02Yi1AtlHpY8aPPCA/y2CnaqO3d1kKNlLCHi6pjUIw65Yb 7lnZOSj6DZkVxrESGCfXPu+TszYf9VrebB4awF0IcdwXzDUjR9iF2pNrXu5phCNN 6XpvpFkFvh039C/55HSPFcTTl8FfOPxdK2BYGXlRAe6R+0mQFpdt2Q/Y347Woh2R RYNw4M+Cje3tdH1KSAwYRA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45y18ur3nk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:25 +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 53BBDvF2022370; Fri, 11 Apr 2025 11:35:24 GMT Received: from ch1pr05cu001.outbound.protection.outlook.com (mail-northcentralusazlp17010004.outbound.protection.outlook.com [40.93.20.4]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 45ttye9rrv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Apr 2025 11:35:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xibxdYmehuPIPenxM/SyjbJGiAczPwOd9XhV7igDhoL0Lkx5X4FkCV9gnuziQKQyR5E3lPF0ueOCg9MvKnw2PL5g8zBPMYUzHXFLkXq0MbD38Tp+lPziit1pLW0XCLfztwXw6V4G08NOtxff54l8D9r2RqnIpEMUIJwTNDWmBEvu+kux5WpUlARBRySBzqbj3WY8BJ/DAJhqiXwu9PnQ6NhpTwwbuITHz6yA00wRtlnDmecV4zxuK09kfSCSsHCKuRd/9KZguOFMAsE8ig5pgs1Y46XbUyisdf6FggWll90K/S0j8EAtsMojTG6gfU0QM5rahtBx7iLOgygrS8pdLg== 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=K8sBtbF6/yvdpI70PWYYbVuZ0mS3SuEtNAh2rjCN4xo=; b=q37+blQZHw2L2RIaLr4aIgb0SvilJkgtLV0CSdbhByljO5mEcTlViEsxtxX7tGEOaf3FCqYyV23x9mAVu4bii5gHIj3c56Cii9ulWPw4/9F1lkH+nXCymPNfjuDKJbQ8wt+PMzEyxJ/F/Tmc/+OeKJkPi4FRZQuWwohykwWQXzht2YgZxwVYaopZDFoAy2lrvnuLvC2SFxqxz6LkNTm6x5VGTPypHDK5NwD9vZ4RxtFS2HibRT1IwX/MGWINviwNSf6Lie8hWnhuh843QDIzmr84V3Togcfr3bDinCDogit4vmpqe+veO2Xy4h6j2eJHTcfXSkcaZ7eQVXLpaZLkng== 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=K8sBtbF6/yvdpI70PWYYbVuZ0mS3SuEtNAh2rjCN4xo=; b=aW2LTjlyDw7a+Z53jTiwgKoU61MvVzVEv19grV/zPPIFqpdG0BeUYn0RljItzEAYwRbha9pFiv/no+VUXky0jx8YMSCZh5fJcV5klE/WDYSGzXq+/QPV412s0RlJv4Q2HNc/LdBPofOxwdy7LQXQeKJcD2XYFmOde9cFMihnIRA= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CO1PR10MB4404.namprd10.prod.outlook.com (2603:10b6:303:90::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.27; Fri, 11 Apr 2025 11:35:22 +0000 Received: from CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e]) by CY5PR10MB6011.namprd10.prod.outlook.com ([fe80::3aca:a3f6:e92f:782e%6]) with mapi id 15.20.8632.017; Fri, 11 Apr 2025 11:35:22 +0000 From: claudiu.zissulescu-ianculescu@oracle.com To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, indu.bhagat@oracle.com, jremus@linux.ibm.com, fweimer@redhat.com, josmyers@redhat.com Subject: [PATCH v2 5/5] aarch64: Add SFrame support for aarch64 architecture Date: Fri, 11 Apr 2025 14:34:56 +0300 Message-ID: <20250411113456.15213-6-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250411113456.15213-5-claudiu.zissulescu-ianculescu@oracle.com> References: <20250411113456.15213-1-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-2-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-3-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-4-claudiu.zissulescu-ianculescu@oracle.com> <20250411113456.15213-5-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1PR07CA0301.eurprd07.prod.outlook.com (2603:10a6:800:130::29) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CO1PR10MB4404:EE_ X-MS-Office365-Filtering-Correlation-Id: 04327232-e7b3-4eed-235a-08dd78ecf1be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: uxDDEgMYSJifrT+knSW7h0/2adrm/P6RlNfOP9d+K6Jw2IBUKti8bxMSjIkWPJrk7DzvdysF7hGYKKxX5G5stB1tuOFRksbn7Hdoe8jRk3ju1+8F7lEMLgM5PVn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75XFvI4nLbfGGpNAp4KQMyDmxjt4UX1q+4S7M5wrcSnPNgCzcDqJGdG7T6Job/P60InHTHLB0KRPZYA/D5M5dwlD730HG2gKhGh4Q4InhfjQ/re2C2bD1J9HtM7EbdpYElNM4zwuGKAP6sd2PGwE7bJyUrJTnudodyNQEASGfj4o2c629uMiqUoGVh9YJpd9vQQsk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CY5PR10MB6011.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3PmeraAQfgD7t4N0wQyrfgQBNiFrJxheYzTnBFYMb06v9mdVlnttrk60yTLlxCwwXyFaPigBjMgNn0zOvQslwd6iCRG4JdnYa9Y4DpHnhd35JXovMKElwaAXnkoZYAG9kBKT4oQ3V+G2fRd26soyP/4wTWwEvTu4Du5X6EgYRW6LAv3g3+JUJLia7stBciAnwgznaB8UHRRinyHK4yKBF/dGK3SagwMV1TI9vH/U2R1IExDTEmiAyuQ6X+Vp0gGiaURKE6MY7Hs3ceQAbwDtIRrVoAo6uo5M33snaQ6AX/kb22PaLkUjJTPfX3aM7rUl0Jrm51QmBrt9Y7TF6Sc092SB3qXPwRPR6gMR64AsYCbekngeBV5oz6dHNIaSjKX8EU2J2OtD/S6jhgFkGdpT3NS5mUEBDWTccUJ5VpFybho+H7Fhq5MG0TUyZzrecNd9nSRCghnSx4w5BkPop9/YNrb+qcSBWwNPT3lXd1zmQ9NzgOrr+rJnMqh81LmyKBqJgxwzp4v26z7hovzmRK/iybUr5qbHDFezOQGQuEzysw7QtG+2b/Fyf9AqSiUDV+lOVu28s7QoNW3tPuXfhG2oLHbx+768JqrXNvRe79oO9pKciV3X0q5+y0k5p3S4DRGfHal21lebQ1mInDBskThn/h0LLBqj2/AAqO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F7bX+kNA/G3uvCBwvLxPN3RbSlF94/TQ7rWcNN60VMNeYu18bfMWUf/3Tfeb9l73ZHF+11c7I0ayvHvZhQjnuaTG+YLX5XIKbf6qNNlLt3TJF0WxTfdW/x2p38K5CaOnVJ9LMCPaYvjr5VIuOe5aLjXhp52yJxGuBAJQDvUyVg8ZYKsmyGgngrJwNLHytp1gs+ZfStQOkqtA/RIk2qxTmONW5WGJZ3gqhZlT67gMSOcwVjl0dIS//3geoB6BrR6OyCGg3JHp1FYw0JzAq+OYj34VNhHTZ9J2iQYrDyjcHzrLcL7zvkRTr9fngtSA7v2AzP7YLkxL24S6+CZO/VUdnpZW84e5UuJD+gKvvFBo0Eb2IG4qSgRoDGlMHzP0IH3S3DsEe1UW/rMfqzjsDbLIkUeD5ag+kM3/13MvhSkd6l/UYM1fGESyP5TED24hw5RmS313bMEGoDh1oqMxjntv9N0ZJ4xI5ZIta/QyMMlWux3LsypkBvZ9+vfeVSV0o9a6rGpjsJNyLPRmkiS9zNzC7Baax/Ogoh4bIpBHjAF9AveGqGsp51097YwSSBs9Joj4AGM9cOBXAtU2K+F/1vRb5eUBo5FMPHY7/SPyovIit0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04327232-e7b3-4eed-235a-08dd78ecf1be X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2025 11:35:22.2482 (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: o46h+rdwAkw3Il4rd1tf9WwPN4ME80LbaX+nn/ZdgogIPHzMalxzudQt6YVuynO0Ffb5V9RGR6B33+3OyQFVzwEtlkOWROqYnqJXFyIPEHuPR1uc/gpOUUYX/N63zAZ/tE6Tf1ZKZQZOF75wUNN3YQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4404 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-04-11_04,2025-04-10_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2504110073 X-Proofpoint-GUID: mu_l7naaB20CEsi42NuIPt4nE-3EfOUb X-Proofpoint-ORIG-GUID: mu_l7naaB20CEsi42NuIPt4nE-3EfOUb X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Claudiu Zissulescu The SFrame is supported for AArch64 architecture. Enable SFrame stack tracer for AArch64 too. Signed-off-by: Claudiu Zissulescu --- sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h diff --git a/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h new file mode 100644 index 0000000000..e13277ec5e --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h @@ -0,0 +1,63 @@ +/* Signal frame backtracing support for SFrame on AARCH64. + Copyright (C) 2025 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 + . */ + +/* This code is inspired from libgcc's MD_FALLBACK_FRAME_STATE_FOR + implementation. See libgcc/config/aarch64/gnu-unwind.h */ + +#include +#include +#include + +#if __AARCH64EL__ +#define MOVZ_X8_8B 0xd2801168 +#define SVC_0 0xd4000001 +#else +#error SFrame is not supported on big endian systems +#endif + +#define MD_DECODE_SIGNAL_FRAME aarch64_decode_signal_frame + +static _Unwind_Reason_Code +aarch64_decode_signal_frame (frame *frame) +{ + unsigned int *pc = (unsigned int *) frame->pc; + struct sigcontext *sc; + struct kernel_rt_sigframe *rt_; + + /* A signal frame will have a return address pointing to + __default_sa_restorer. This code is hardwired as: + + 0xd2801168 movz x8, #0x8b + 0xd4000001 svc 0x0 + */ + if (pc[0] != MOVZ_X8_8B || pc[1] != SVC_0) + return _URC_END_OF_STACK; + + rt_ = (struct kernel_rt_sigframe *) frame->sp; + sc = (struct sigcontext *) &rt_->uc.uc_mcontext; + +#define SP_REGNUM 31 +#define LR_REGNUM 29 +#define FP_REGNUM 30 + + frame->pc = (_Unwind_Ptr) sc->pc; + frame->sp = (_Unwind_Ptr) sc->sp; + frame->fp = (_Unwind_Ptr) sc->regs[FP_REGNUM]; + return _URC_NO_REASON; +}