From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2053.outbound.protection.outlook.com [40.107.22.53]) by sourceware.org (Postfix) with ESMTPS id 512BE3898C6B for ; Fri, 6 May 2022 13:32:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 512BE3898C6B ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ej8dcRRVPbWP23r/XdUgA1+0JM1/ypYaozXZ1T+hKy1LgyxWnBjlssHrCVJKiY3v6Y3DU8xjEokAgGFYqZAIyBSB9F0yTD8fmzN/g+ZTdqr5+W+5boltFm1TRzabucT+HVQysaAXmXSYZOytXg3D+AXvW4RgWK6RB2R1BHRW/BPkTHY0ZcT1PlIyKAc6ubA09QmwUGecK+HDk/6lFuthLxwKVQngjoRn8cn96Ph2VTQpTSHc0U7K6l9Vrx1AnkhxSK/3bYmZhTlkw/Bc8lf8nUGIglkazMjORaCYNhEl8In7j1vMcVhv/cXxqjKgqiAkNCGj8JBVOP6B0jQrvF3gDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=mzg3ugIEVkJpx1HToexgzpSPtCNoNfOsmzalb3cU6mU=; b=B+LBW33bW8sDuu9LCQIDNDXU9NFN6s8uc2DYhfS3O6CCfQfplE2YOLbGdcZ+krMde3La31dac7BpMbH08Ge9vgjw60i+/P0ubdcokTfc/i7PsCZI1P/KdfjKp2cjGBniGuMPm1MUi6PGTqVVL5w3gOLaQ2GzY6bE/dhdPeBg4Alvx+otaxDJFgGKvRlScv+3gWoVRnURcWI7Jz0CpcHAJewYBb6Dy8q6fXN0Io/uOm8yH4DAfaY08Td7pNuFheXgZCGRwRoJYGn8ErIbhcZ6PyOwmlfl+vQK98VyQVugOL1KX9wKSVHl95xzb0BOljKe/GqMN8JdyBc8sFbDEYYvLA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB8P191CA0021.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:130::31) by VI1PR08MB3008.eurprd08.prod.outlook.com (2603:10a6:803:43::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Fri, 6 May 2022 13:32:35 +0000 Received: from DBAEUR03FT049.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:130:cafe::21) by DB8P191CA0021.outlook.office365.com (2603:10a6:10:130::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.18 via Frontend Transport; Fri, 6 May 2022 13:32:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT049.mail.protection.outlook.com (100.127.142.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Fri, 6 May 2022 13:32:35 +0000 Received: ("Tessian outbound 2d401af10eb3:v118"); Fri, 06 May 2022 13:32:35 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2ecb5569fcc30212 X-CR-MTA-TID: 64aa7808 Received: from c66713c87bb7.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7052F5FF-3A3D-4FB9-A523-8D4973D380E1.1; Fri, 06 May 2022 13:32:29 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c66713c87bb7.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 06 May 2022 13:32:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JveaQCG8FUgJiDB7DIBayDchBv46ew845Waq2tKEMgdfugSrqKq8nt+yqYStHha08XKhQzDiplvVeBmoNdFr8EhIgX85++pGwvWlEb5uetWwa5//lMVXuOOQTqCuEcceDkWZy4Oa0AbVF6oYG0PnNmROS7GyWYRdrHrx5zIrNVsX2FVMgschyFIyz8itBm97hB9+ye8rlFwYPAcKVIWiWyWuqn08aGB/z51UXjHlf4b/ltvV6BzT783F6Gdvx3+CIIpuhdi6AP0OCcAJy7zbTwXiBE/Xg1MChoiRztY2zdxKpnB9PA2ILTJBQEL2Sy/DUII4i06pNj9RTSYE/TxLEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=mzg3ugIEVkJpx1HToexgzpSPtCNoNfOsmzalb3cU6mU=; b=bYrh9xnmqI3yTMJBxgYcCYPbf2xitAMjySIx1sAu9GxCGIVCmybKwEpZsqLICJVJV39TjhgZ0vb81b3i3JG9qE6CyFjfT+vNCGItqA+qTjFA3SGp1hgmT1LT3qEQ+6wAyqCmw5ToV9nm1tkn+Ehr+JvbgAHADSi9zYI95Eh0jcwncQWOK4HqkoMSNCKq5rTeVVRCCSzxtkF48g8CFuE/jXf353hij2VT1xtVNAkmsSPqKhcBiN7P3XsIBp+gUhnhsxZrcRJ8s30t8p4SqVZsAZLTMORJ+aTZAvAkAqjDi5nLeSVUVo5erqgeoj7634eCiH003EsIKaP/7/Mc6RoBhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by AS8PR08MB6757.eurprd08.prod.outlook.com (2603:10a6:20b:39e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14; Fri, 6 May 2022 13:32:27 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7080:6233:cf8f:a8a6]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7080:6233:cf8f:a8a6%7]) with mapi id 15.20.5206.025; Fri, 6 May 2022 13:32:27 +0000 Message-ID: <257aa215-a141-6d9b-672d-ea8ce209b107@arm.com> Date: Fri, 6 May 2022 14:32:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: Restoring pc to a different value than lr on aarch64 Content-Language: en-US To: Yichao Yu , gdb@sourceware.org References: From: Luis Machado In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0462.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1aa::17) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 04c81f5c-7107-46d4-ba99-08da2f64e1a4 X-MS-TrafficTypeDiagnostic: AS8PR08MB6757:EE_|DBAEUR03FT049:EE_|VI1PR08MB3008:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: DhwZpBq+Ae9L+RfMND86J+FK6D4t8YPhG/HiratoaXofmog8EANIGvPFt2nUhZWH5IKu2eSD88Ftx7+gh5kcoOa1sC9FQTbQd1BNtBC7R7s858pAh+Guq82plJF5YkuZ/NfE9CMZWPPYRWeeIuXXs3c4BwYavItB1tVfRtgeTM9M0ZaT4ZzZfUJi9lV8vCrGteywwktCVPknbkEHOdMkCUmHc3LOnt4CcbOUIFdpiOuY1wL7zKpkH4yLHIC0/2Ue0uftzdYIHk+RedeDn9zfGOrVojh4NivH6TqQmEJpX2DZXnTC8Fpvr8elPYqMI/gRr7TPQyg3cD/eUs4iKkT46f7yaeO+i7GJi+yvxueUJuT1wazPRPh9o1bEnXdS78CRB975rFJggRQQVXtp2rPKV1fQPJsyWgj7k+nEXTzuiL0aC7d/k0xIxWRVs3DB9S35tQc9kWc94Dmh145LjYzUZ9iddkmRfJKD3W7vzhv/XGtP8yeSVs0BUQs7WSEYdq9r16W/1Rfcc58sKcsnHC5JXGFjkhVvHmQjCs9/XdMGyNAqgemGYrtUAaeh/PzM+dDCj9A6S+RxDV9ayuVSd8UUvk26QapRGZnQ/AuUcEGdDQyJVaHjLJIJKvPneL2oM0UswqX7klHbk2PUBq5JQwJsBQULy6AKavT0pZVgy0xEsf3XCud48XnemuG5y/Y7vX4fBisnsB2KuQy0oy/02uDsH4MJKySR4ZlB18rOPESTKUfUKYaavTmrbdiVJJ7kUxoDEaRpd6jBfj6j/waGpP02s6XhpCbBD+qy2jlpKtuhJOfq6DK+Vcy0X+XF6MzWUYKU X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB3919.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(316002)(6486002)(38100700002)(8936002)(53546011)(6512007)(26005)(966005)(5660300002)(6666004)(44832011)(31696002)(2616005)(6506007)(86362001)(31686004)(8676002)(2906002)(186003)(66946007)(66476007)(66556008)(83380400001)(36756003)(508600001)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6757 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: a3c55506-6379-493c-ef6b-08da2f64dc82 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cl/RylQvqaXEQzr1/sg2QfDBr8M8X7F55KiucqVEZxMJ4Zs3N5wZg2dGzENhbtMIXp1SWeWReH914M/uBdN+Onb08KXAjx2tVk6hF6Y5ATy+8AQbw4NvSzX26GQW3ZFTYBiI2f9vlQ7TwBxr/9tx6hrZiUdaMl+2gmjSmp4z+668j4oAdv9mdv3Nf+jKusbvaRwo0LHvAW24SUFXH8zIOdvPt8oukAwy5d51sxMZUxg1U0rAK3mIsNbyHB1gstM8/Cm4y9CgzuhyUWNxoB1M+nveMVIsFNyD3hO1Vs6hLP19sxzFfOo4wSAnNGPSvT1fKBjjHB+Im5h6yvV6VtGKdIfP536ZJd+Hxxoaqh3nxugEzwKLbyfHFxgnbBA5aFSt6k4eIdD1hczyoKH4A9Qss+UDHvXSF2QAzdJfxSZzf542rrDWdgmgnII9njGME2sAM2N2NCOa3ZDAzC4roKnZKxOGY5MygNU120CltSQDeflrzT3F4BjPP6SlcRxoI+kqz/FhuBG645rZ03k7TRPQPeeQQimHlQKFpSfWCl+YW1+sFOdsgaclee11GGKhe/ktQaHgMT9S1XdWqsz9AlKzZxaT+JtzCVNz2A4EsJLYE1Yj947MpSHKebbNWAXGbMXeiYDX9UQuabEGgC32K9ypMcRM0qeKwi4gA69xU6UWcBoxOdrlSkrUIiz8ukng2Tr/l2zBWSO7Liyk6ssVtHbTYbdDZZMn2jN0E5MfkozXyLCKD4MRajVYLj/yFv7q7LfU5eTNmtYXXRBZ4Y4cZLV+wRZpt69eVBcw3J6d8bGAvb0= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(26005)(6512007)(53546011)(6506007)(31696002)(86362001)(2906002)(508600001)(8936002)(966005)(6486002)(6666004)(356005)(36756003)(44832011)(5660300002)(70586007)(83380400001)(70206006)(81166007)(336012)(47076005)(31686004)(40460700003)(82310400005)(8676002)(316002)(186003)(2616005)(36860700001)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2022 13:32:35.5094 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 04c81f5c-7107-46d4-ba99-08da2f64e1a4 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3008 X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, KAM_NUMSUBJECT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2022 13:32:40 -0000 On 5/6/22 13:46, Yichao Yu via Gdb wrote: > On Fri, May 6, 2022 at 8:05 AM Yichao Yu wrote: >> >> I have a case in my code where I want to restore the value of lr (x30) >> during unwinding, to a different value than the return address of the >> code. However, it seems that for aarch64, >> (aarch64_dwarf2_frame_init_reg among other functions) hardcode x30 and >> pc to be exactly the same value after unwinding. > > Actually I misspoke for that. It seems that sp is probably fine and > the only thing missing causing pc to not work is that > aarch64_dwarf_reg_to_regnum doesn't understand the PC dwarf reg > number. It seems that the only thing needed is to add a > > + if (reg == AARCH64_DWARF_PC) > + return AARCH64_PC_REGNUM; > > to that function. > Yes, GDB always assumes the PC from the previous frame is the LR from the current frame. That is what GCC generates. If a different setup is needed, GDB needs to be taught about it. >> >> According to aadwarf64[1], >> >>> having both LR and PC columns is useful for describing asynchronously created stack frames. A DWARF expression may use this register to restore the context in case of a signal context. >> >> so assume the intention is that if I explicitly unwind the pc in >> addition to lr, it should work. I tried to do that, and also to set >> return address column to 32, as well as trying to mark the frame as >> signal frame but none of them seems to work. Is there any way for gdb >> to honer the explicit unwinding of pc? >> >> Also it seems that the sp is also card coded to be cfa. My code also >> contains explicit saving and restoring of that as well so if that's >> the case (haven't tested yet) it would be a problem too... >> >> Would it be possible to not use this hard-coded logic if the frame >> contains explicit override of the pc value? >> >> Yichao >> >> A bit more about the actual code. This is done as part of runtime >> patching code. The actual restoration of lr is done by returning to a >> runtime allocated stub that restores lr and directly branch back to >> the return location. After returning, all registers values are >> restored back to their previous one. The stack pointer is also >> switched out since we cannot rely on how much stack space the call >> site has available. This seems to work in a similar way as signal handler. GDB needs to be taught where to find the registers so it can properly unwind things. >> >> [1] https://github.com/ARM-software/abi-aa/blob/8a7b266879c60ca1c76e94ebb279b2dac60ed6a5/aadwarf64/aadwarf64.rst#note-9