From patchwork Tue Mar 18 13:03:29 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: 108302 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 5398D3858019 for ; Tue, 18 Mar 2025 13:05:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5398D3858019 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=E+suhTs+; 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=WkJfKBqC 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 F2A553858031 for ; Tue, 18 Mar 2025 13:03:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F2A553858031 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 F2A553858031 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=1742303027; cv=pass; b=Qs9FW5lxR1hNvHq/MXheIZkJVDhZMSXvNLsRuZLplJH18e6lbP20urvFiCgfkAcr63ue0WSVXS8+8f0G2+byzM/S/N7fPWN6JQg/TvOIPR5b6j6Nu65hiimy08uM4X0ZMawo9ilu2M+wzjIyO7kBZ+3G74CShlda6I+eHof8APY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1742303027; c=relaxed/simple; bh=vOvWkjyEs74BOaRcIMR0cU1wc/DYLh2DvFsOlivSSmc=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=C/gBuFGUlc2sLFd0KE4/HajNgBC3zkqhHBP6HtcTG+PC4HHgGb853bOhiqad1rLnKYgknfJWNJCKwSq/4NXZ0qmKFNe2SC0yQL9L2LdPOfABYRNs0fv4+SYgM8JtwatHzmBr8QA7kzQQAB3hW+OvS9vFYIPVFb0zSTSeW7aWbhA= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2A553858031 Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52ICftp8026043 for ; Tue, 18 Mar 2025 13:03:46 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=TAZWjrf7AuPZGJ0ovB03H6xFkCp4LzSPF5C4mS6THMk=; b= E+suhTs+pAwpGUlAobDbwQNUt1Bh4ADSLxoZYZDTtYHKO6i3u3pbq5s+ibjtTcAp E9Fnn3UPOIQREZrNsBEfqOf+EuTlw7kh8sieNxDmNz7OC3flVtj1DGRyPlR4qSPc q410VRFFnk9wXB6AlkCzIphke+jdm04Vvku9npDa6oHv2XWJuKhmJJPWUFmWpO7l A//34j7hQCKCtNSM7HHucccVtO3oVc1mLyeKaXIQ0QkfkCCtX62TUnqJcbpCnZEo xO23YCl1VvD7Tr4dpe+j/DR+aeN5q4dx33vW8NlBgjLzbNkfvK3AqDCJtcLlkx5F SFDXi4o3sJhvw8UrL+Zqag== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45d1s8n514-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:45 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 52IBKqiI023291 for ; Tue, 18 Mar 2025 13:03:45 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2041.outbound.protection.outlook.com [104.47.55.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 45dxefa9ba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RGtoexz/qtY8sW9JUPy3MP02/+ooA26MuWC3zReaxq1JwUJxQ1WuHy8k6ihT82lzLlKJMWJaaZzLrQTSiiMSexohHLzWXiIJfMWFgghPn26uQhFmXCkBUU1PYVdTdP6KtLLh/KVMOXpuI6VcGFDh0mfAdeHQ5sZIlXwQmRgmXBjES5KsUn4do8ieU/HkxTn3ieM0GY+8w9xHw2fR8HfGOFeluGA/cxtrnrcsGWERNXqZ/DACpTsYriqKyzEtlra6stILKcW8iUlPKMSYE5MisGTX/n9gxNNZ3yjreFpSj+6eyEIFb/zplMeplg5/zQk91NlvE7d9dgEJZ6jeD96RFg== 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=TAZWjrf7AuPZGJ0ovB03H6xFkCp4LzSPF5C4mS6THMk=; b=I/CvX7ilr0U5PYMS0zMnFCHwDR9fKOLnUAjhMnO7wT0qvInIZ1GmG7H9J6CRy0SxcEeG/EnRfniUXFmNJZo/F3uKM4PDS6D91TixqJZbhjKwlFWhqjd3uwsG7F07QJ3GcLppH8MaO1QExHW3I5/83vDUT7uUIukkWOJ26AmfS1Tk3xXKsM2iUiA0xU/y/xBmbG4uabX4IAIwapyWzEwpgXWPnL8rAQ4ojltBXYpxD2zs7O+hlhg8th4XMMlZqXsiVMG5+lWO/NQYJLkwAEUYdepMh9htibaXRAoZSg+sppROZrjgWY2fY/TtJ5zhNVzKwC8sa7S31uHoRJJOVqbQJQ== 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=TAZWjrf7AuPZGJ0ovB03H6xFkCp4LzSPF5C4mS6THMk=; b=WkJfKBqCCDxkMYfjMh4GOyYe06w8DfVcuQ2RzwmMDQDKse4x8cR1Ok7Eh5fQ0Hp/i6IbDv1gYJD0WaM59rhDV+G2SqeQmrEyP6y9Gn6zJTMfro1+Lvs6dbGzpuNDx1/HhR1OF93aksmHZ3xJsu4+nHz6pRXCpTZGbFK+/UO9WDo= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CY8PR10MB6684.namprd10.prod.outlook.com (2603:10b6:930:93::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.33; Tue, 18 Mar 2025 13:03:42 +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.8534.031; Tue, 18 Mar 2025 13:03:42 +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 Subject: [RFC 1/5] elf: Add SFrame support to _dl_find_object function Date: Tue, 18 Mar 2025 15:03:29 +0200 Message-ID: <20250318130333.18829-2-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318130333.18829-1-claudiu.zissulescu-ianculescu@oracle.com> References: <20250318130333.18829-1-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1PR09CA0121.eurprd09.prod.outlook.com (2603:10a6:803:78::44) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CY8PR10MB6684:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b65e843-d27a-40a4-610c-08dd661d4ecc 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: rsXrEUOk635PN4f+tU0dPWePIq7VqtYhpo09XEM/KNwprgwTQs8xfsLYI52ndjyFVTVG1zd+krD7iaKz0AG7iUFC7OvvJExkt7xDVRG8qv8HILXjiDomZnNS0MPf/cMD7GuBEepIAT9lb4aSxm0GYE7pxcMJH/4Z9+xTsJU/kQzXEjsb0Lel3gb+PZCyW66ErbOiAtTfA43oTWHNji5zBxCfo/EeDfmOEIld+0Pa9wkJErGTL8trGmre9aGrm8FHvLSTUuH0bWk+f/uIdBw2AokuaiKXiBMuEB6f7B51v4yc9GcdI6/WfRfijNqkckiBUXImQlEln39vuqIRcgomTy71ZQ0VpEu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P: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: gpzT9oRJ6Z7oeWXHY130tMm5OMtj4vx1sXXUygtC4BVCj4SpsiBCbS5ONYpbFW/ipdutmydSJhH3cxti8ajU79OjWy8XDMQBfnUjZssfiiiKU58UsN7AHt1uRGrX4vI0VtY7k+OdjYw89+HXXsHAykDFdOYCEzbfMzmioCT1DzDKgXj1vhflvyKl4UvTjdQxF0gMGuKAwURA5+X3SDapC5dCp0ZIKda5NinOQsdWfEMcpIeIHW10jrABICCp+P8FSfkaZxDwMVRAwST/S+hgGwm+Ch2+/urOPziF7fNLVov2QHIbTnG+c8NgtzACTACilEVn2IiugcpNoRUFA0UU/6FrdPZnNVq/HxxrktwVcVstBBeXcZh/8ZZOO+tzp/eoKjurNcz3l7HK+tZn/al+ke/lDn9L1/KxFgGzrrEJPdAm8kiQrg7TW8j5gkAngsozwFK6XbPF2gqycYqPJ9ZamrOKsiBTFPgW/iO4nc1xWWEzP7Nv6wmBXI4MHyXUMqRAvkdzvA33yjGT97f2XPex9uSeWhp5Yy7sAZ7bNpWe9eLo9g4g4fDpmF0UPej7+5G3+GS5OUmaCZYYodjJQVbC5GF1mQKM2JMRj4pa88FE4hYy8EhqgKxmOxiDxH3F59P4E4vt01mdYgEXtmHYOUVaJC3MLLwCS6Dx/HfB/axTOvd2MC+ngysrrrc6pEx3bP7GCKE0/mLUx+veAJ4TrFPiwzvZcD3C5r3k+7Ap6sI4h8GkAuV/39dVx+Bo/KK4MFkBSXsbADN9jjvSb5nb0fnPLKHiK3DHtOvfrd4MXL9qHJr1iLhJg1ZKSHV9VgKwqBB83tkcg49Elkov1U2qKpo78npgCipnZ8wKsaLqsmobi8JRyza3b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0WcP7ImCZfE3H4BpGE1ohfpERCDRd/ZLVBfkZQUGzjQ5zXWTWdVaKuftIKnyxp161MgN1GxToMyq+RwL3X2gNADFUOadnsmKHbfydViHUwokLbdRmnCEPq9n8Ro5+khEst3h74BW5yNZFPj6gEhH3gvvcaGdzadGeHNSX0zJ//xPP/Gkedt0sk3ssFJDbZDux+XDzy133qrwNIb+f11N8zMYHCAg/q2elTxyC+mLIwtGkWudx3B4yoZR1gYpM63o7eovi7SZpXNpqP4vGh5uyzxTh8ulL89B49HgbuaOg1KljiG1w8qYZITqv2Fe5XGsnOI3sncfrOe3dq/n/Kp2UkmyfXw097GdwHX9IXA9yTo4x4aXtoOj0NOvi5pOZDrbOWAVVzXoZfZtY44xmtebwoQjte0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b65e843-d27a-40a4-610c-08dd661d4ecc X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2025 13:03:42.1014 (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: tB5Orl8N7tk7amFuvWHDEC+Lkfu/vs3jO6OHC+geGuJ+4fKfnz0ZhwuJHG+oeAfVVjtPP14Q4hI0KhRXumOYl2pRvSv1NoNLnd+WfkKr/UdYdDw4tNkwqtiWzztG1YgH62AX2Kx2g5LDBhzQucjsmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6684 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_06,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxscore=0 adultscore=0 mlxlogscore=958 spamscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2503180097 X-Proofpoint-ORIG-GUID: uH6bFhylsWfglB_0zkYaSHNU5ja7JSyl X-Proofpoint-GUID: uH6bFhylsWfglB_0zkYaSHNU5ja7JSyl X-Spam-Status: No, score=-13.2 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_H2, 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 | 6 +++++ dlfcn/dlfcn.h | 3 +++ elf/dl-find_object.h | 51 +++++++++++++++++++++++++++++++++++++------ manual/dynlink.texi | 24 ++++++++++++++++++++ 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/bits/dl_find_object.h b/bits/dl_find_object.h index b9f796dc2b..162ef00615 100644 --- a/bits/dl_find_object.h +++ b/bits/dl_find_object.h @@ -30,3 +30,9 @@ /* 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 + +/* This implementation does not have SFrame data. */ +#define DLFO_STRUCT_HAS_SFRAME 0 diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index 5747962611..dd4113a757 100644 --- a/dlfcn/dlfcn.h +++ b/dlfcn/dlfcn.h @@ -216,6 +216,9 @@ struct dl_find_object # if DLFO_STRUCT_HAS_EH_COUNT int dlfo_eh_count; /* Number of exception handling entries. */ unsigned int __dlfo_eh_count_pad; +# endif +# if DLFO_STRUCT_HAS_SFRAME + void *dlfo_sframe; /* SFrame stack trace data of the object. */ # endif __extension__ unsigned long long int __dflo_reserved[7]; }; diff --git a/elf/dl-find_object.h b/elf/dl-find_object.h index 0915065be0..e43c3212c2 100644 --- a/elf/dl-find_object.h +++ b/elf/dl-find_object.h @@ -43,6 +43,9 @@ struct dl_find_object_internal #if DLFO_STRUCT_HAS_EH_COUNT int eh_count; #endif +#if DLFO_STRUCT_HAS_SFRAME + void *sframe; +#endif }; /* Create a copy of *SOURCE in *COPY using relaxed MO loads and @@ -67,6 +70,10 @@ _dl_find_object_internal_copy (const struct dl_find_object_internal *source, atomic_store_relaxed (©->eh_count, atomic_load_relaxed (&source->eh_count)); #endif +#if DLFO_STRUCT_HAS_SFRAME + atomic_store_relaxed (©->sframe, + atomic_load_relaxed (&source->sframe)); +#endif } static inline void @@ -84,6 +91,9 @@ _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 +# if DLFO_STRUCT_HAS_SFRAME + external->dlfo_sframe = internal->sframe; +# endif } /* Extract the object location data from a link map and writes it to @@ -92,6 +102,9 @@ static void __attribute__ ((unused)) _dl_find_object_from_map (struct link_map *l, struct dl_find_object_internal *result) { +#if DLFO_STRUCT_HAS_SFRAME + uint64_t read_seg = 0; +#endif 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 +113,47 @@ _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. */ +#if DLFO_STRUCT_HAS_SFRAME + atomic_store_relaxed (&result->sframe, NULL); +#endif + 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; - } - /* 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); +#if DLFO_STRUCT_HAS_SFRAME + read_seg |= 1; + break; + + case DLFO_SFRAME_SEGMENT_TYPE: + atomic_store_relaxed (&result->sframe, + (void *) (ph->p_vaddr + l->l_addr)); + read_seg |= 2; + /* Fall through. */ + default: + if (read_seg == 3) + return; + break; +#else + return; + + default: + break; #endif + } } /* 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..86922d9d19 100644 --- a/manual/dynlink.texi +++ b/manual/dynlink.texi @@ -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,26 @@ 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. The @code{dlfo_sframe} member is valid only and +only if @code{DLFO_STRUCT_HAS_SFRAME} is defined as @code{1}. + +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 Tue Mar 18 13:03:30 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: 108303 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 B4DFE3858031 for ; Tue, 18 Mar 2025 13:06:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4DFE3858031 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=GvfEQqPD; 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=iQXhJ6dc 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 E46D9385743A for ; Tue, 18 Mar 2025 13:03:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E46D9385743A 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 E46D9385743A 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=1742303032; cv=pass; b=xzbCqrad2psco29k3oJUmKed+uA8wPeGcw2lABz+nlHls9ghzGU/zkthH789kssk2cBkfNNX2DuZvgG5JJdxFDbMbU/E0mP8fZlc+Wf3pHUXlorl3qfnKAikD41iAMzDpDqUsZ9gFKrOYKC0LzFTG511TuBA1OnHcPpOnfmK148= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1742303032; c=relaxed/simple; bh=Qjf5FP5zsnVdMmSyY0woLrox0rWUfRe+1jb3OmndFXs=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=RF0TcegiT5d7FrtARqgq6yHv/Qwx6M9i82C4TqBxr1kXhOZgG2YdkAYQDxA4cMQ6HV0FXyz1tDAMO5OQoG/u6pTHJIk71l1F0UYmsJawG9urtDqkzvQcq41gug5WCc05whcpP94q6aQPcL6mPtMOghYYuILrt3Z4C3mZPsOx0ys= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E46D9385743A Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52ICfqgR025970 for ; Tue, 18 Mar 2025 13:03:51 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=BJnha4GoyvQt0zAlx/yEryM7hW8aQpCF+tZyumbiu3M=; b= GvfEQqPD97K3XrD+psmVjan8TH7YEZANjiDrAPXpwEwAI/RkD5FVa0RFtVq81PtI dULwHQVvQgS0qpmxAUzLfn6ikzpPa9xohjh1OsUpqUVuGPMCzvBluvIyEAdanpeC RCax7cX4Vw2d0F1JjNzkVZuX9KpBgq6L34YTLdAg8qyyTBffj9qoIyAtOJ+duMVO WYH+it5Lzkttd1tgbIh9gWZgwE+esudSkNndbH374cjiWZ41USQQLt2F2FlDl24E kaxVLReFyfyvg2467qenznkU8zY8U05bedfnKUxVLr66ps3MZOJ2gVApAPOMoQpv 54TGNvJeI0KSvarqQO0Akw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45d1s8n519-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:50 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 52ICKGbp022429 for ; Tue, 18 Mar 2025 13:03:50 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2048.outbound.protection.outlook.com [104.47.70.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 45dxefa9e3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ug6ng0bq8zJIGVE1HaJaqp+z4+WzkX8nxhEoH7B4P6aYlXkIDyzlTq7u+yMvM4cyXsY9+8Hrx7bU6yMt9Q7s6lDDC1lhENm1vhWrETMKOh+uWZO+I/4QkjcQFU0YXefezTkoztAH6ZG6ODooVQAgUl56DrsR5CuRYhk9ElJUOWz6uZ8F+CRjedriGZow1ia7xRroU4Si6KRfsl+7HDb/H0jTJKcHlSlfjRhyHSgQgCTCgYukuxJOz/C+JQaCNWx7ZIkQEBea2Gv7nASUf5EJO/CbPusHedLqkAVG7IidcGdnPN+bpWKettPVvd2cCiABCYRKHrtPYsaaKZawK3Mocw== 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=BJnha4GoyvQt0zAlx/yEryM7hW8aQpCF+tZyumbiu3M=; b=tHBxcA04K1DpkJ2hEeVWrQ4M4BOuhfZU0wRy9Qm9cE/7/aZGYP3Yvx4X5iFW4ilyC6TxdMmLNGeh2Wy+iiO03rT3W/fUzVi/TBT9GbvM9IbldUX6j8zF6ETtorWVcYlDtuM4ANuksbTbhmkMUCig7GsKuqbD0SuotnUPzw7xnGrQ65bU2oa/T3RmbXPC7Xd7mSJjK9nUTxCzYulOf7wAEnniNLlR+Sl3Q2Lb3IBl7oYlwrS7jfidjtbCTEYRVHv6Gh8r8lVQNBWjkx85ugc2h9VPZp9FHiDJQp6cEKj0bfb4daeA5rpfaVweFjKEVFkYY2bnky/GtdIWrJYsFhZFtQ== 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=BJnha4GoyvQt0zAlx/yEryM7hW8aQpCF+tZyumbiu3M=; b=iQXhJ6dcrUkj69EujzgsucZbpQhKJsnDDmWHFZhJ/BwIor5bdCKZOKdb24Q9uZdagM3C0FjoNmTrbAk72DbM2dx+MD7qosZQUabIhNQH/9baVrdiGoZHWkmWqP6P41Fv4LPRcVFSAubzRd/aPNLvwFNnh+9Bz40WDtCG//lJCVk= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CY8PR10MB6684.namprd10.prod.outlook.com (2603:10b6:930:93::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.33; Tue, 18 Mar 2025 13:03:47 +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.8534.031; Tue, 18 Mar 2025 13:03:46 +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 Subject: [RFC 2/5] elf: Add SFrame stack tracing Date: Tue, 18 Mar 2025 15:03:30 +0200 Message-ID: <20250318130333.18829-3-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318130333.18829-2-claudiu.zissulescu-ianculescu@oracle.com> References: <20250318130333.18829-1-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-2-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1PR07CA0261.eurprd07.prod.outlook.com (2603:10a6:803:b4::28) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CY8PR10MB6684:EE_ X-MS-Office365-Filtering-Correlation-Id: b1c27f2c-b751-4b09-6655-08dd661d5169 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: 6EuCTFpK4LqQwA8ULBd1JgknXqJdbqE7sdkpbc164+IINOy89IY1ik/eJIpRHnqInKkG6kcyMgZac9KKwvtsu4QoaQ1Qb13Fx+xcd8nrOV93Q8izcKtJwbzf+k69w+7PzekNP/40Dk5kltLuHax2Eo+aMcqHtgzr5JzxnBt4Puq2i6IUTJww/5X5ZxN5sk94Zoa42Zrw0dQZ8KugfVjaAUrV+5aMhIqHHc8lBo6px54wpl58u6uNrtB4cel8jWd/7ZKtvWhSIt3bWwxHWERkvZLlXeDhZJ1vjJlZWwiZn3Y/1dWlT9gYI7UpLOhtcFK+4uEcVDiOghmsH0PisVgR3d+EPFME5dARmhmhLdZPNKwIJ+yQEpk+ba6qnbLX+ixODEEO2WMeS9NGmzu+/Bk+gDDNxXrfjx5SUNK7GtuGm5b3VTStkpKXApoJKBZtve8q4/SBs+XoBcFOEXCWddRAJKEgVjULeAB6o5D6Z7WM3mHwLUhI8QrEcckqXAsFdkxHgAbG0W95jlWoLNTAKzfIfC4b4WNRXYZMITsAmPnK3F47WzyClc99wTXLANyxGkTbsrisQGrScxawerclqRS6zFcnhxPuktAgHahEuD3WxJzXEarFrn/VcK1H/TpU8w1/OIVDh6pci6H0XOWmRieZwLE15i8i6KrRFkjZ+xbpTNSxFAv+b1zzqT2dNhqVe39r7rG/0ATPznHuCn272CkMunif0ZlwdzssjNj6s/xSc2NCtYRViJASpznv1fLdDf93rgj0lvbxEwTtGGs98srGo0qfNdf4M0CUxkxTj/JzPzLpRTpL0OhyU7ifiT0tk/GV4mc/tsUvGa3wO2H6e84mZT7BU/XPLiFfSR9ydibO5mAZHvYHMqNTVUH8EK+CJdtZIBmjlkfkEEvghtCScXt4J7aRY4gqmI/r2WkzNLVn43pIlo8tu39G7lxj5z2xr/H+0B2GPkNrUl0DFHkrd7C8ho55jhWmVIXqXarnomiptqN1gH4EEP14s3FtjLZeTyi3nz+CxbXH4qzJrfwiNICeS+gzURa3mg9+ciJwAhfZ2Mc/RK1RvRyU1MiRt2W3IJE/pMls/ARRONa9fjr7bAyYdk2fuqbsgggQpU/QBmhTV85Ae5/AxV8klAKqGn2/Yi/Xykfl9JRl5O9VSlX6TiH5j9ZDB0smvp6UI1Kz5TF1ywX6ruSmNmfrUVHO2nrNym0A12u7Gvb3x8ZoGX7sFMLR8I0k46iDfhf0+pXThr3Q52oB3BOCAkKqibUPpqowlrU4slwWAA+/JNSeXALEFr82T89Kkrd9K9Pq6kNug7X5AdtZe/Rtnx5myyW2Nj2a0OLg5X9LEc8PuTm3vDjRzESzAQ== 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)(13003099007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +yOtk0OOBFnxnYbBXcw9uJtFeo3sduXeaSG+4mWp9z/vnpuipVuNuY4Sc8mA5pCI8uCgmHGVqmNrsm7RB2/Tw6YMnEG+pmBmR6SnjXwp2E1n+2HyeIzbi8UkueyEcFti+WBak4zmPWQmm17oetJP6g5DjuSyCvI+ZpnZtbDIKP0hGiWOAPbkOalLl+Zoz5AiYpmJLl06sK5NHOr3gUmltkEHhGI+ZmfuY4aGOLEwh0x5qFs6HXv9IZD29sIE6HKU/cgjeicZ/nlNNJmURodv06VcY/6x/i+ioHVRUYmrGcnsmka0NCBMCrNiC1vyR5DqsdorwHZXu8dygThIWI8U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cU8AYxKYJvNIhl5LQaRLPeqpV2/218AFawNCnpxL2GwZ6j4wTOzlhPmEH4TkEKDKZXO2c+Yf9938GPEsaOaaY2l37yBiEBcYXgFoDuvqqDoGOPe9wlz9MPzZUgCqqKjI9aYkKeqGfiOBv9UkUzf1P6EPRbuvr0h05hP91/kx6Qf59XoOObaTi1eFbviHeQrooCwYfPun09n8/mMhhsocyQKNoF0m4vxYktd7SRMexCH+yrLSjRIhYCSrPnRTjJuSVQFv6pi X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: oID/R+m3K9vdyP2zPMbDru8BCi5cbVt01rJu1oFg+UtEvqw/BDq9Yn/35yCikzWG1F0S7AGOYOkUaOiLuO2tN7BtBwfKAfsQc7Ie72hSdto3nIFRSqxTliCd6gU6HVA8m3p5Puk3efa2+mXkWbhZPAnszgXlZ8Q/wLRA8t01DsUenzyosVC46kqA7VqQbih6J48uV9Mb7RnL5yNo2gaS/h9IIUcqZx9cLiusOi3HQ9/vCBUY2s8ZX3IDjnXug9A+U37Fi+Z61gEHI/QD7bzUnUOY2DsxI9OdW3plgY1K0x7rbwJdDqo4zuirhnLxL6J1Fz+cCERJ0JFngGN3CH4B4FnQBWzm4KrfSdvU7+DcQ5b1N8LV6TrzedMP6TkahRzzHGQ6Plt0E/sb2Whiv8MReUMPV8kGv7PtpIPU6Zh26MxUA0tnQfYzywj1wubLu+ADiIP+HzZGrkJ4/UX4pWDCdY3XS8jF5fJBbRbwNwX9WOPUXMyIqVXgtiERP8ZlJRYkd8eZQJ2E4A99mBxG77GMrI1QKba7hR40IO3yzKID90xUHAkMb9aC8TbMeI8gNAZgpHhkaRu00r0q7BnjnY6XNx2gFUkFvBPhPdUYbhYrStI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1c27f2c-b751-4b09-6655-08dd661d5169 X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2025 13:03:46.5509 (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: vicSz6/ESBgMVt+rUzxUQ3XCnotEzZNlbnxKh8k+pSETRSvJa7raObSCAaZfbey689oA0qbs0M4rd3JFQ4EkUz0feGQD+/3+8OGWSRnRZLSub7P0B/WTEtqj6y1wqeh8KJ7LRM5d11LdZ4IoY14rng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6684 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_06,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2503180097 X-Proofpoint-ORIG-GUID: VOVvL1xkYdsRcwtpjrotUSBzHdMJrr-4 X-Proofpoint-GUID: VOVvL1xkYdsRcwtpjrotUSBzHdMJrr-4 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 | 43 ++- sysdeps/generic/Makefile | 1 + sysdeps/generic/sframe-read.c | 577 ++++++++++++++++++++++++++++++++++ sysdeps/generic/sframe-read.h | 101 ++++++ sysdeps/generic/sframe.c | 140 +++++++++ sysdeps/generic/sframe.h | 359 +++++++++++++++++++++ sysdeps/generic/uw-sigframe.h | 17 + 7 files changed, 1236 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..32490b35bb 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,38 @@ 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_Ptr __attribute__ ((noinline)) +getPC (void) +{ + return (_Unwind_Ptr) __builtin_return_address (0); +} + +static _Unwind_Ptr __attribute__ ((noinline)) +getSP (void) +{ + return (_Unwind_Ptr) __builtin_dwarf_cfa(); +} + static _Unwind_Reason_Code backtrace_helper (struct _Unwind_Context *ctx, void *a) { @@ -72,7 +105,13 @@ __backtrace (void **array, int size) .cnt = -1 }; - if (size <= 0 || arg.unwind_link == NULL) + if (size <= 0) + return 0; + + 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..5f5dbe4f93 --- /dev/null +++ b/sysdeps/generic/sframe.c @@ -0,0 +1,140 @@ +/* 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 + +#if DLFO_STRUCT_HAS_SFRAME + +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, rfp_stack_loc, pc; + int cfa_offset, rfp_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 the 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. */ + rfp_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. */ + rfp_stack_loc = cfa + rfp_offset; + frame->fp = read_stack_value (rfp_stack_loc); + } + + frame->sp = cfa; + frame->pc = return_addr; + } + return i; +} +#else +/* Dummy function called when SFrame is not available for a target. */ +int +stacktrace_sframe (void **ra_lst __attribute__ ((__unused__)), + int count __attribute__ ((__unused__)), + frame *frame __attribute__ ((__unused__))) +{ + return 0; +} +#endif /* DLFO_STRUCT_HAS_SFRAME */ + +libc_hidden_def (stacktrace_sframe) diff --git a/sysdeps/generic/sframe.h b/sysdeps/generic/sframe.h new file mode 100644 index 0000000000..81f1a5ac8b --- /dev/null +++ b/sysdeps/generic/sframe.h @@ -0,0 +1,359 @@ +/* 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 traching support */ +int stacktrace_sframe (void **, int, frame *); +libc_hidden_proto (stacktrace_sframe) + +#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 Tue Mar 18 13:03:31 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: 108306 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 09556385780D for ; Tue, 18 Mar 2025 13:09:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09556385780D 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=AXdz8BpL; 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=ThwCty12 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 A629E3857723 for ; Tue, 18 Mar 2025 13:03:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A629E3857723 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 A629E3857723 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=1742303034; cv=pass; b=Mk1V6qSXces4ppDgPuBB/hKDqjnBLm7utiovUOws8s9GAzRHggz0iajfU4qkdAov60MYUZy4Fs57CC35VDfwoVyZgZWnH8y6LbeFr9TcOZr1QNhWlXIGAqzoPQz2502XIEOPgW0ZTiKHU+Cot1oq11blsAUY0lNtIVgzlKBiyWQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1742303034; c=relaxed/simple; bh=HtMTWULOUnSdymV7aBwCQttViW9QZyEAoPy0X5qX2TM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=jnWjdCCsRxj7YlqNglb3UvdJzjnwAC7++GftnzOYV5HL/lWIW4TU5TQQ9XeetBDeigKoNqXWmeKG5w5DVSzC158eWfHvT0j8KxfaD3uGMz0RnY9zb7l0y6OrUsYFu7Zv8IQ+76FPDzdTkahCm9g4k4o3bUR9EPKubOUkRSm2WIM= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A629E3857723 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52ICfrSW007470 for ; Tue, 18 Mar 2025 13:03:53 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=SC373roimK+FvKAtxLrLcazoluK/+wpX1rHJEiRCMkQ=; b= AXdz8BpLAT3QhquGtjxhn+SNBmt7dnswp6E8ccH4EP/5zzKSOvvR+VrT0KNEtrzW NPw5HxZYvj2I0cOKKXeBJyNTOGAMoJkrM/zdNZpNkOgp4x9pEquARKBtKsIWEG6+ dZqH0shcVVzl7DZ5KRUMUDyAkwKbnEy15MlxdH7hg27lFUi6FXCdRuOZBzBKSAzM jJ7ZJ/RKfEbvAa6gu1Z8zi7vv/hwd0JIQQdUsOeo4TTz4RpIFw1Ya56hXXL5hf6w GDnn8+5o0kcGEQRC0G570HP5ZepUxK0GTCIaZOkn5XU45NSOnMQ51nLrKRjaj5uz 9HvEnOMjV5Tv9cKYktJV/w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45d1k9w3yn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:53 +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 52ICIF47022323 for ; Tue, 18 Mar 2025 13:03:52 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2042.outbound.protection.outlook.com [104.47.55.42]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 45dxc5j0s9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aPzYMuuFeZT0xg82TEZnKPjNFEbVamYhjII+EnYa47RqLfSA9Unkjen3hXNGHPo0Qmt89o1K6lIi+AYFXYVLBb00giONbAtB8/b9H6fZEFSGfj6tOcVA3I0Kogv5/IXFd8jm3bh+Lk0E9sBgvzC5uCbRXUvord3htStdRUgTYvSt2bg1Wgfhz6hDIcgzyX9G4aVm2qReSSLSmQAgfqZY7at9DwyQIJuesQIMTPUheJuUucMPrEtrbwtZABzeS+8SH1+BuTQP+Lk7oo0hFTmu6zu6NWri4P1nsJWBxIBdZf7HK0pubeXPhMNw6+Tc+lKBV4d4eZRJxfLWJeQ14xkQMQ== 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=SC373roimK+FvKAtxLrLcazoluK/+wpX1rHJEiRCMkQ=; b=UU4kApgz3yiDT38ttQkaunNdRc/q0Xfw1lD02Hlb3xfpdYMvIGRInh/oZ8fKVe/wlkkZ8+mwjBG9+3a3Ia/zO2S/FX3VrWc2lf7qsINk44r53n3h04KHKU7+uKh8Upub+hhF9+CfyH+va0uK9dGAA2gR3cLJq4AhDW8JQEOpEtWmesuim338rGrrK9AoO80GBRpaGCMeYU5wKe6B9cdM6Kaxyj/0mcLpFCzD80c86grJUhY5abVpkeBXwxDopNX9vvqbbHA5lpiz4jqO3Jk0HKJx7iJcr/N766CstA83VqgMhQG3dLwWL5qolFkzcu4z/rczNlNyeCtKme2CevB2pQ== 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=SC373roimK+FvKAtxLrLcazoluK/+wpX1rHJEiRCMkQ=; b=ThwCty12GQNn8x4KLt7OZdwC/T3mXKYss/DhQbXmqLvxF8geN/nNhChu8fV2CCK4NofE9U6rwPObKCjHHsvjLFYcOMDU4qmJuy1At/IXD6E1Z9A1futdqgbcIPTz/zjNhZdDlhU0c1Dt4LmbWz7xEoCoMyaNOdPFDKFwmG7OU1w= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CY8PR10MB6684.namprd10.prod.outlook.com (2603:10b6:930:93::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.33; Tue, 18 Mar 2025 13:03:50 +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.8534.031; Tue, 18 Mar 2025 13:03:50 +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 Subject: [RFC 3/5] configure: Add --enable-sframe option Date: Tue, 18 Mar 2025 15:03:31 +0200 Message-ID: <20250318130333.18829-4-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318130333.18829-3-claudiu.zissulescu-ianculescu@oracle.com> References: <20250318130333.18829-1-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-2-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-3-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1PR07CA0250.eurprd07.prod.outlook.com (2603:10a6:803:b4::17) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CY8PR10MB6684:EE_ X-MS-Office365-Filtering-Correlation-Id: 64818e3a-ce6e-48eb-d9e5-08dd661d53fc 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: bm16CZYrXqZD13C/+XRSjoNKfIJt1mDgds5F6JpqvbaTV9rr8VWMKn5ahp65+B2VGSHyz3pOvfZAlKqGKZVBr9d4olFE122KPrBrzcKaIkZB+DsFqbg53pre5/JFgu8AsHmFF7Ys2Wj/JyWFPbN42p7C1yPo5k9y4yWEw9HUqvM7XC3qfF7nBrOcgPGjTbMJ/PSgqBetdYT2PRHEfloU7WgbnLjT9LSTDmU7hQH29nyZmi4pBy9uGzdvgLQxTCp7wb4Fn87ar11uCUxvDq+CI/g0zsa1RzlEsKfGw/hGl2sc6A+048GMgXl4ZQxaahS3DwGfWVRrbAyrTKrNU3KsihPC8AIaU1HTBwy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: 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: R8rqMPnHjTMvGkiLwlzuGpmw5pvX5PFsaOlJHfXRBOhLsKSHYRD/gWE7YV1D8faNBLcqRLh42vaaCh4xgR3PdY+UFj6WjDUacFSn8Pz0vWQu7oBl9dgEul80hkaz+eGlImSOau4kFIloovsZ01rxF4MnJ6d2LxJWmAJ9CkydESSPnpmsPsEs7YiaZaPeyg/UUTVrYpsXxChca981EysF5ERlJl9OxN3neBX3NwfHJBQc1KESZwlzo1WWHy3SnaEohhIEkS+gGt9iYkQXFCiWWcfPgKxoXhG8C6zIxOT0svhTLP1QTlXlmAeEwzslJv4uzAhAUkwqDO5vcAgZyMs23EsrazO2cEedv1x0/f6HixJLUldosqnP8j7Hs0OJXgvq1Z9XglNcsprTBQ6WR2iEdAZVxsI8g8+h2aFsRLNlyLwkS9vVxUeIrlBQsUNy9rIB2Jn7Z1lTPNfLV1NTmSyljnopf/q5iWmxZCiaQqdf/smrFzXoK60FTXUAh0IpIE3aKTX/4RPl61eGsoytYHG+FC3Okf1glVPl4BRnRt10Z3wpsg+bkliifUTqDXkbPE6KmXTI0EDQJ7Ox1BLyJJC3Ic7ZDjeIZ/8P7VG2a6M1hchdfewUHtk7lBX+3o7nqzXJgL1fU6F10Mtc615IKzYXj+GrrEiO7TF6YqL6bkoMVtV85uJ/D2fJU0Mc8vp2lmG07qo9EQExRCowtOXqh9HEh9wNAE4HIcDN3Hmya6QdaWjRwEtQ4YPemqw3CZw0utQXLFB18khbCt0rLcZNPsXhbP7yJ48EnaOgHeCW86CJeJjyHSafXqELKD0//BWixkBNK54kUU/V59m2/h65dq0nRhzzDbn4WroEBaPW6MMmixhI3i5iY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FcjzHYxfNZn/E6r5I2zfhbvxQZnFFYvcpDgbGhLZ9Mm5ld308bitmB0iFzvHirFcBmm22i32/8SYDEyUDpBTo3C3RVtM4LegTd7Zwp3NtM5l/FJo+Dw59y259mW9k0VzHZLRjopxw8IqQVYV0Tt8UJUNMiyy/sOhnK0Rkk8cxAm/j9hDvhYqtWTPISDv0S8sQizetoX7ypU6GoWbtzsJvQBQv8Ts8MbFw6OacdB5nHlcJuqczBfjRJDUcfmgXCtRda+J5VTN/LOOLjsbcc1wOZSXcpbJO3qr0SybjdBqPYNuV7L6gm8DbEMiE3lNBKEvycRtbTH9tqgitsd5Whzw244HUL3g739fMj6tOnatPv+j5cTR9q7NkPM1o0kty5hHsxdVxrJVgquVGef2as4tvg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64818e3a-ce6e-48eb-d9e5-08dd661d53fc X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2025 13:03:50.7131 (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: iy8qKKKhQQzYLCvjqe+igXe1toBQS7izzTAupKS40zm2kDr3o61i/1c3bukjNta3MIzPm65HW6yI9gQ9GXQeHaqAvoShbnwHnZWI52KPsMeS6daEJqRq5WYTYp4JIrGi5MIRWGh4LtWO4vTK98QeyQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6684 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_06,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2503180097 X-Proofpoint-GUID: qXSwQ4b4VLvrrNa4bBs4H_bn2DxJkiUF X-Proofpoint-ORIG-GUID: qXSwQ4b4VLvrrNa4bBs4H_bn2DxJkiUF X-Spam-Status: No, score=-13.3 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_H2, 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 --- Makeconfig | 8 +++- config.make.in | 1 + configure | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 43 +++++++++++++++++ 4 files changed, 179 insertions(+), 1 deletion(-) 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/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` From patchwork Tue Mar 18 13:03:32 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: 108305 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 9448B3857710 for ; Tue, 18 Mar 2025 13:08:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9448B3857710 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=ZOAcdvPj; 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=XGexRa1n 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 1AD7E3857B8F for ; Tue, 18 Mar 2025 13:03:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AD7E3857B8F 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 1AD7E3857B8F 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=1742303039; cv=pass; b=FZAgS41TaXm5OCTYqox9oj0cDAhOvqRPaf57TXmK5gcdC6V93fdi8d8O8SwUCPtGUL9FtVqBEYP5L5Lq46mfMc0E6H0V7bHSydB1CyPnj+0n0sd6rCcbXqqSRaRbOj2pBi6EjnrElOSXmnME6JoLXetZuHQv8U0b+08cvZm4YA8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1742303039; c=relaxed/simple; bh=CBPpPpDOasEL+c8j0rOSkhnuHem91ksTVMnYXoNgHSA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=cOhfOSbDCxghJ8hWorm5CcHn7EjneAskbpIMeGSWHlnbkdb5W/tQL4CZbq36lYZDQggrnlPdt0mDWtueK78DWxw5BXH9P1GPolS61P9qiRg7x/Xew+J/Oa50Dd6jhJZtmvyMsYFjKQVt+0vXcScX0agiyrgaIjUDY/JfUTmIG6s= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1AD7E3857B8F 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 52ICftUE020765 for ; Tue, 18 Mar 2025 13:03:58 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=tDr049DDj3YQ3+OxS2Asg03/4rjgVEbxnlrSYk0/JZ8=; b= ZOAcdvPjxOuRZqzQ7mDVHK3wIvV3lDvy/hCmsRzFHWbV6SxOMbwoWM0Cj2MWOvLc JjcvAVBO5PXf0nttafQWU6ioZLjEjb4h10rmTbWIMxqllSAjvmYNNh7XeBpKw+mq qlEqJIJraooohKR36n88ByhZkBr6BsmOIJmhlXGh7lBg0vmN1H7yI3ZwqFtqM6qr y2CwHWVfJuDFCIe2/tw/q8+wPFUC59o/igrB5D4YSrQzh1MfiRpnbt1OcXhXFkOf +e1tWPLa0Onv3nUZh0KJvpIaoD+Dy9NZCMBLp4Q1VX8mDV33/al4/NhK8y/r5zzo uetAr4vrNfeNgS2SViDoOg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45d23rw35x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:57 +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 52ICsLuP018542 for ; Tue, 18 Mar 2025 13:03:56 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2043.outbound.protection.outlook.com [104.47.55.43]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 45dxdk226c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:03:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RV+EXx42SwScyJqxrCps1FefirysIshinYNbVUeH6t38qr7Ggq2Wk5WX8N33axyZif7AdrRh+A+j6HSDW4lpL8p6Scf9UsaNrjP8xNbRS6D7FrT8XcyGVv+8iXKK4UbUJNnBbgXJRQ28AfQ0JFP9v15U8vlBq3Xm9yvzQqdsGOp1OAu9L14A34qGE+IyMMfituKjjTgP0V7ss5fkAooHDqAM7cMTyi8xMbeZDK8gGW88sSfpHmxQkDKW1GvHyn50c2cTxDwi8FcNIbGj1ZTxY04mnFIsGdlbdAO3I2+32qkwP89PkZAnlEjwQg5rrECmWKutvdMrxl41c5H9o6x/iA== 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=tDr049DDj3YQ3+OxS2Asg03/4rjgVEbxnlrSYk0/JZ8=; b=xL6d3MAx9UxGTNgkhsSwi2/JYDTD9df8YE78M6nbtgJkwY8BDI82Qa3/v3CyekwrGEUiSnktBpd6xM18oUV1mH2/JkvMx6/68GyZjQ/lStcffERTXK8kOd/+xP4q/kM4g29RuJQB5w8xcD8qtK6tgfzPG6dyf6jX/6CrrB0FzlIgTwf1aXEY0qrH3mQML+M8kK0KlQA3RDrOyH5fZm6nS1oNCZmPYcXLhAgTDlTPWLj6kaChxO5nsRJkORBc137w7pkBeQ8SX8g+rPTefnRmVZ4rTelXUsK+6ARP7o+AJWdNDR8lg/e3YCfJBt0qA2ZwvkLtDgix9sId2MIwKpN+/A== 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=tDr049DDj3YQ3+OxS2Asg03/4rjgVEbxnlrSYk0/JZ8=; b=XGexRa1nIx/T7Cfexxn9wPBVKgRuh/1ZvzV/Mo8scalcrQAEHL0dS76c9reSBN1oDqWK67dxyAeqLwIYX543AnfOX8TMx64rJygyNF4kEponyED4ucg40IesgjLParsGDlSc6voGMOXfOqVVfUbNJGgB4+zzSHJkCxShSSSQx9g= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CY8PR10MB6684.namprd10.prod.outlook.com (2603:10b6:930:93::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.33; Tue, 18 Mar 2025 13:03:55 +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.8534.031; Tue, 18 Mar 2025 13:03:55 +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 Subject: [RFC 4/5] x86: Add SFrame support for x86 architecture Date: Tue, 18 Mar 2025 15:03:32 +0200 Message-ID: <20250318130333.18829-5-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318130333.18829-4-claudiu.zissulescu-ianculescu@oracle.com> References: <20250318130333.18829-1-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-2-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-3-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-4-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1PR0102CA0017.eurprd01.prod.exchangelabs.com (2603:10a6:802::30) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CY8PR10MB6684:EE_ X-MS-Office365-Filtering-Correlation-Id: acb09bd6-82d3-4081-f8a2-08dd661d5691 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: 5WrBKRhGqNTPcgTEb2Y9Uvxt34T14ef6dRsx31yeYiV6YyXGaDIdhMMRAx3i4fJf5ebo3IcIhS69JacxnY5EbCsfArq5dBp8CM16oo3H/CMszmKyiJyyl2OS0A4kb6ziPbGusO5iwtqQPsyp5Q8NTpJDX1WcreZ6pqQPPW3LgtbP6DRajiIfaSYWTDPpFfoNviwA55IM0UBMAZjC9rsqFsDhi5hrM3ym1lF/U5T7sSQI+oNdo0wpv7I6nd5tZegka11X9/YyDCZnZJWe97qwjAxrOAcg0Z+WRJ1BFxHDfE7CNm40k7gfofnq5zArWhTc9Fz9DtvcF9iA4U9zzC+UjE77bn4X0pknO12ZVYsDtvb4nE/3zHH6MRcg/0vs36UOhwliU0ZgU066xYjfPAvbbY7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uJAyBX3oJu9owHjArNv4GeoLLsg1GrelOSFs6I6bCQOnDDB+5A35foIuekOPnW8zma6O4DxGa4Bs6/a15e5qwzwW+jxJGno+AHvP+4pxISAErkn3sIzeQ9Ogbnr1ZfEkUdglupHDH63BkqOgO46Zy+F+d7RwmH5X1j6DpniO5fTDeokJIEBm9deNYHf/EUhQ6lfH+uj0uDV2XRb5Ex9OYO+jwgxghCs+pW1xPTbNOo/HJ2J9zugULaTLtVIRBztj8O+RdVEcfwcDp1eIdsHey1EuotCfrBwIB2o4OtT0vJ1HQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: acb09bd6-82d3-4081-f8a2-08dd661d5691 X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2025 13:03:55.0067 (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: 4ZZPXwfUF6a2/e/z/RZS/1/GToKm94tCa4xRm6o5ct/SrOLBpGJ99bLYd25dJvZaYS9RqwfZFN44qoLLDXp3naqMHvtVfHkJEGlCQiWVnR4cjwKULy/feyUeVUiqMkWbhz3sF3zSK1l/1MV/LL0J6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6684 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_06,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2503180097 X-Proofpoint-GUID: -XHagjezfDhiNiJNLItwftPkri2cGTwe X-Proofpoint-ORIG-GUID: -XHagjezfDhiNiJNLItwftPkri2cGTwe 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, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 | 2 + 2 files changed, 101 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..daf2200c31 --- /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 /* ifdef __x86_64__ */ + +#define MD_DECODE_SIGNAL_FRAME x86_decode_signal_frame + +static _Unwind_Reason_Code +x86_fallback_frame_state (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..56f7b0cbda 100644 --- a/sysdeps/x86/bits/dl_find_object.h +++ b/sysdeps/x86/bits/dl_find_object.h @@ -27,3 +27,5 @@ #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 +#define DLFO_STRUCT_HAS_SFRAME 1 From patchwork Tue Mar 18 13:03:33 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: 108304 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 946103858D29 for ; Tue, 18 Mar 2025 13:08:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 946103858D29 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=leK+KPQk; 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=eZQpgYiw 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 3F3913857C67 for ; Tue, 18 Mar 2025 13:04:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F3913857C67 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 3F3913857C67 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=1742303043; cv=pass; b=lRPpbxRUtbEoEvFI/v5wYCxd7Asjx0UzFyNDBTCrN4hmljGy5DQC/xYiXAi3XPurKdvhoM9buw3+dkS4cqk0T/3IOZHvHyNmBfNhPtOo93f6NTzp1XHXhUJr18bTXIugUpZrmMN0v2ZkR6jrYupvzCPIT+Qu8ndlU0cmcmFfya0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1742303043; c=relaxed/simple; bh=ayCqYDxVzeWE4UldLIeJGagf5tsHQ61c4cJmgEIhEas=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=gk7rdZxhQcdTqVyOqlshfpnr0cgsQpFgb1LfqjcUjr0Z6I3weJ+2IuWT72KjaZ1zG1yr9uezdLDLWDt0Tu/dkQXSUsrpm5FlfAu4PuBeKA9RDy71dHFA5gHKtoetsqIz7e4Z61bZVKmRFUpEWkoDAix4CuWV9t44FlFldH+6tSk= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F3913857C67 Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52ICfqRn025964 for ; Tue, 18 Mar 2025 13:04:02 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=1ZuNDd8Aq3cESifGsBZ5zZdXu1DtRPnGFcF4ZNCvu44=; b= leK+KPQk/Txm9KuNwrnRrNi9+Vn4f96PSqtkeBLO9DlFk02dkQYqQAAS+FUO/12e 5jG4rsbQXnZe0/WnDKwYk0CRNZlV2mMzKAgLJNzazGIhQl4OelGwO3mbBj5Vmj1t kBYNXsluYHQ5bx6wRoBnI37hy4KYgrD5xOl1sVAropYveWcMTlqTUtXAtYIOIFcD hgCkMR174ok7CbO1OjGqCwlLYheyxjcd12zeKcN/FgnIk4QaIew9TbUGQpgSa3ts EfMiQAdx/npo0sGv6wmnE1fwUXfJkjW/L6cJ9OtV4DAevhy3ilbmJiVhVB8k75WB /ET6F/UMFP4A6IUinFc8TA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 45d1s8n51p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:04:02 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 52ICYhxV009449 for ; Tue, 18 Mar 2025 13:04:00 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2044.outbound.protection.outlook.com [104.47.58.44]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 45dxkyk7ma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Mar 2025 13:04:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Gxlxm+Ajk+/W2r3fFtvP3XCQQryWvHKfaY0XIhb/ZoXC6SjWlzMrNfHCTfLiF4/M3pmZAWpVdhR7WI8GaB9Yv3W0qQihZtaHAMAbXrEOnLbcgKk9B2Qy1UaZ69ujuQpd2pufrfm5aphx3B7QE0wk+oIZ+KnyhQ4gs/xyp/jgfglaucaYUmTI3o1u1SL8J/OVqUH61hLHPOMqEIIb88SY+QZ9L5nmEHYejRerHHtz6WUzdqD+5qb/tzwT70CM7BCPl685xpn7wEviULaS/nckF9K8vZY8xfXCvJw0FGc2FKIeTr0rh0d62MDzcE6Da+mS1EDumee2KrKLefDQF/eZdA== 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=1ZuNDd8Aq3cESifGsBZ5zZdXu1DtRPnGFcF4ZNCvu44=; b=B1k8rZH9frkBxJti5VKNKQEy6+GoGSQ+oiuBw1B2jctcJqOTryupiLZhtkcWLQRNHnY9ui5IrzbjVpGaqxfiGdXV6Wt8eeB1Q9ewuPQcShdCDrUTTxjCZzpn2LngQCE0zfmRS5nbFoB6hfu7V23jF+SQsuAH5VPvzgzg97tU0Mf8SbxIlS8Vi1h/loyeuqmxhSESw3wHUPHfBzu6aSLRybkg89IDKoBHfVszbNJ1v3avHNLfBMSkYrzU7ST92RxhzXpJMjz0hGegESYshlSk8xahlANHZOOevh9hO6CtN9iMKPAm9uCnl3YIqPdYtmNuwbZSyhcz2vfVDIZe9wgGxQ== 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=1ZuNDd8Aq3cESifGsBZ5zZdXu1DtRPnGFcF4ZNCvu44=; b=eZQpgYiwK4iQuDq+gvH38iWjQybDNrpdV7h/hEKAA6nw9ttf+1O0h8EIw5Pu3ZU9wTVtuX2fn3chAT2jw64vrR+jOCf1JQRQOwgXnbPUTU+3cL1YSyUaOettNgJZyLLGCZfZFCFl2SdIDIG99Sq6ZJ19jaMsiSz9RXwWVLbmcFY= Received: from CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) by CY8PR10MB6684.namprd10.prod.outlook.com (2603:10b6:930:93::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.33; Tue, 18 Mar 2025 13:03:59 +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.8534.031; Tue, 18 Mar 2025 13:03:59 +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 Subject: [RFC 5/5] aarch64: Add SFrame support for aarch64 architecture Date: Tue, 18 Mar 2025 15:03:33 +0200 Message-ID: <20250318130333.18829-6-claudiu.zissulescu-ianculescu@oracle.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250318130333.18829-5-claudiu.zissulescu-ianculescu@oracle.com> References: <20250318130333.18829-1-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-2-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-3-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-4-claudiu.zissulescu-ianculescu@oracle.com> <20250318130333.18829-5-claudiu.zissulescu-ianculescu@oracle.com> X-ClientProxiedBy: VI1PR07CA0298.eurprd07.prod.outlook.com (2603:10a6:800:130::26) To CY5PR10MB6011.namprd10.prod.outlook.com (2603:10b6:930:28::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR10MB6011:EE_|CY8PR10MB6684:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d95bdc8-f570-431a-07c2-08dd661d58f2 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: d4qZVXny/qtUwHUtGamK25qXTXj7XxyvI1gL0nSxtVM1BsEKL9o2OaeUj5VnbzjYQxhjrZ4LVrwX1j++//zjAGBRz84isEc0u9pAjB54BPcWTvPLW5+Bn4KUnzCDlgwiC7xkI9HGlRcw1EXpKdIoaDRXIQBbMFRO9fyUlf2L9Ri88VDxNWij4C4VkJGsX4kVFDGeqpIzD3w5045SM2jhR2G4kq1dOm401wtpLLL4RkkCPvOttOVnvaiPdZIX/rldIrywhhxjWb41RogNkxbOwk74lXfC3iyu4+e0Ue4pvravdq2Titphi4hEaDP2angOkrMhWKQNEGWNR5l9xZuDgGxSSAMjeDk0iIS3a0GyvlVA0no1CmNGYreMqx9r219ySFsL2Ko/WStYC824HhrYr7s46iD98kVmx0P53OKy1zupX5qbR1vZFLmauxV88ks/GuzoKsDPOFY+jHnBfXT2pLL0ErRixUh9C0vhEdiWu4C3eJBZ+fpzmpi2WQJavf1MFhTQBpKrwfzPKWV9dKz29YLJ/uHWG744O59H3l885P/qgZFS5IvC3YjB31OZTBV2bXgFgtEw8m71dYAaEr0EOBxjoNadLq1RGzy/CnrkELNNkfJv4ClD55B69ugIJhyInPjOuaGxPHrXAJsHyrnQvBCViMq/9NSYf2hv9/tDA0MRSNUakVjtJYtVWIcsGrpxJRincLjTg9fBWIwnBdFvwOl4ATCE7r2XqPum6mC/hbT3FACc3PuFi1XOVA6OLhFPxYzHbg1iu0fUjLizNXhVfh5GU6AA45qHIxuJinimZnfRxxlHT51cu11H4ZoyfabEtiGPfQVJAC9BQjFihkjWq6sw3kBpi0hB/O9YFGAMrxY7IoYgU6sur234SdKEC5VQYfgJuX7SGgR77fBUC+tCYQwe06uJWxcOYW5zkNrYRDqlwkGzsiIrwe5bzpAmtnk1PnxD7SKPpYyIoGIBeCXDojd+uf5xm1PJebZWgkMCEQvWntSUWYKSil2JNdiAh3/gLFE/7aw9K4LqI/+UmLcJJV9jADYCz22gF+He1VEy1GUQqoAXF/dB/85Kt5BwOOnOw9xaKqvJznIdfQw8idTa44eVl4kztM3rQI9E9yVoj/rQJ1sS1OP/DjNKoYacQU3PX00sDdfnmqj/W2j9WCUOk/YsKQSDLN6zPyLoFPDPzLWsTREfm8DQqQkZ40ICbc+QDT2PzjLYbvRwBLX9YXuD5REvqZikL+6qIB3PChK4yzEMHxU3j1pSd9hzdxbG5yzVLiizqEvYogK3vYuC6LqJAbh7UWw3LiTIO2KqGNciGY+EWvHfJOWpG92Q2uCB+0V5ocUj8Aej1T+fpns1OkBcSg== 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)(13003099007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: R6h6GGiUDbt1ait5PSmwuS3fALYcjQ6ihURr+SOm+HVS05u5QQxGmSbVXnuqi4JqiWhHneipnLWig37+531LdOjjWjBtF4dOS+4781VUgHwdj63Rr9NG/fswxJ84MXKz3ACgsh4XrLON8KuL7h2svu4nOvp+xLxfzCxbKJy6O7C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j5E6EOlQsBBXcYVKkgY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d95bdc8-f570-431a-07c2-08dd661d58f2 X-MS-Exchange-CrossTenant-AuthSource: CY5PR10MB6011.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2025 13:03:58.9924 (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: I9AKM3pl914KWEPC03RBC4WMppNH2Il5oUbXQLzaZJGhU2uibmloafB+le4JERj8YTw/zs1QGBFwKACAjDuYnM9iYnWXhW+A5cHpH1u22EDzpxA1XqKTAh2sFBF2Wxcq/slX+3y3B9HvL10zJKLPNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6684 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-18_06,2025-03-17_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2502280000 definitions=main-2503180097 X-Proofpoint-ORIG-GUID: fbFPOyFKhEcxq1pT_Lwpgu29NTyh2vsK X-Proofpoint-GUID: fbFPOyFKhEcxq1pT_Lwpgu29NTyh2vsK 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_H2, 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/aarch64/bits/dl_find_object.h | 28 ++++++++ sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h | 70 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 sysdeps/aarch64/bits/dl_find_object.h create mode 100644 sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h diff --git a/sysdeps/aarch64/bits/dl_find_object.h b/sysdeps/aarch64/bits/dl_find_object.h new file mode 100644 index 0000000000..edcccfe31f --- /dev/null +++ b/sysdeps/aarch64/bits/dl_find_object.h @@ -0,0 +1,28 @@ +/* System dependent definitions for finding objects by address. + 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 + . */ + +#ifndef _DLFCN_H +# error "Never use directly; include instead." +#endif + +#define DLFO_STRUCT_HAS_EH_DBASE 0 +#define DLFO_STRUCT_HAS_EH_COUNT 0 +#define DLFO_EH_SEGMENT_TYPE PT_GNU_EH_FRAME + +#define DLFO_SFRAME_SEGMENT_TYPE PT_GNU_SFRAME +#define DLFO_STRUCT_HAS_SFRAME 1 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..c41474fc6e --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/uw-sigframe.h @@ -0,0 +1,70 @@ +/* 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 + +#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) +{ + /* Linux kernel's rt_sigframe structure. */ + struct rt_sigframe + { + siginfo_t info; + ucontext_t uc; + }; + + unsigned int *pc = (unsigned int *) frame->pc; + struct sigcontext *sc; + struct 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 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; +}