Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3362436pxb; Mon, 17 Jan 2022 18:37:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqzjsdAv98qeqL84J8UbcHK1sCRMzY6UW2fOP3gWMo+rFoYA1z0RMePvVGbzlDRbn/wmpa X-Received: by 2002:a17:902:c406:b0:14a:52e4:3e5e with SMTP id k6-20020a170902c40600b0014a52e43e5emr25644628plk.4.1642473451713; Mon, 17 Jan 2022 18:37:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642473451; cv=none; d=google.com; s=arc-20160816; b=Ntl8GkfNrJRB76MJjzniZoQQuat5dTD2yZrK/744TBrmBycXxxxSJfGBl5WPMwb03h UcO643RtoiT0+HD5YzoBiO4LkQYm7zKvryoXbhMW3qHvVA2vArNmfPxCBykX9yIX23n9 ALNG7rZbYFzopbkkx9YtXARBsJ3kHuETPbNFiE1dJ51hAjp49gaMOsWFy2xOJLw/Jgga cmh2ZkGkQ2JrVMmeNZcJ37fbFUbvQuXeo0HeLPiJP+7J3gFG2sxvtthRUalkrzTS0UeJ 5U74weJ2aJLg1ipQDIZwmeoJalZeYytI7Jeui/HKMW85ldpfmak8EdZg+/WA7d9y8Kd3 fV+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from; bh=S9DejE8wXn5EuM0qldesMkconMjPAH2efb83gkMhzAc=; b=IfFc61J4Yn+87X9E8NWABZrl9VJnlFhYE83VCjv2SClqgqlgPuFjQA66mY4dmZ9v8J djnfaCuYmZXRnz4HtQon8pM9K0DfL1GAPvuWxF46wPuLweoJdDYslwlcd9hNGPqWnB2N zhoJTe9VFj1OKN+MvjDwvtpxezYtRBBcDApUzJPtgvxmuMlIHTjAzmBfp5HrAORr9pw4 Ef64zFoH13F3tcOvm0ZWjFeJavCg1FgB3hkljrPy6vQcMdcOw1smYj+vNyJ9R4RUF3pA zzNgb931EmmwyRxZkGG4Wgc/QC7NG4515AGMhSoRp2G21VX8kCrotVevnFTBZLyIN060 I2tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si14119709plp.528.2022.01.17.18.37.19; Mon, 17 Jan 2022 18:37:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240689AbiAQQLI (ORCPT + 99 others); Mon, 17 Jan 2022 11:11:08 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:41750 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237430AbiAQQLF (ORCPT ); Mon, 17 Jan 2022 11:11:05 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4Jcxj127Sfz1qxHZ; Mon, 17 Jan 2022 17:11:01 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4Jcxj11LGyz1qqkB; Mon, 17 Jan 2022 17:11:01 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id Q6HIU5Zbaqg4; Mon, 17 Jan 2022 17:11:00 +0100 (CET) X-Auth-Info: WBIdWVkrdSiGmO+QDBQxoTmVr79e6qe1UsEYV5yN1imGIbBKMcVHNSoaZeLM3kUt Received: from igel.home (ppp-46-244-183-111.dynamic.mnet-online.de [46.244.183.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Mon, 17 Jan 2022 17:11:00 +0100 (CET) Received: by igel.home (Postfix, from userid 1000) id 1E58D2C3ABC; Mon, 17 Jan 2022 17:10:59 +0100 (CET) From: Andreas Schwab To: Changbin Du Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] riscv: eliminate unreliable __builtin_frame_address(1) References: <20220117154433.3124-1-changbin.du@gmail.com> X-Yow: Where's the Coke machine? Tell me a joke!! Date: Mon, 17 Jan 2022 17:10:59 +0100 In-Reply-To: <20220117154433.3124-1-changbin.du@gmail.com> (Changbin Du's message of "Mon, 17 Jan 2022 23:44:33 +0800") Message-ID: <87czkq7370.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Jan 17 2022, Changbin Du wrote: > I tried different pieces of code which uses __builtin_frame_address(1) > (with both gcc version 7.5.0 and 10.3.0) to verify whether it works as > expected on riscv64. The result is negative. > > What the compiler had generated is as below: > 31 fp = (unsigned long)__builtin_frame_address(1); > 0xffffffff80006024 <+200>: ld s1,0(s0) > > It takes '0(s0)' as the address of frame 1 (caller), but the actual address > should be '-16(s0)'. > > | ... | <-+ > +-----------------+ | > | return address | | > | previous fp | | > | saved registers | | > | local variables | | > $fp --> | ... | | > +-----------------+ | > | return address | | > | previous fp --------+ > | saved registers | > $sp --> | local variables | > +-----------------+ > > This leads the kernel can not dump the full stack trace on riscv. > > [ 7.222126][ T1] Call Trace: > [ 7.222804][ T1] [] dump_backtrace+0x2c/0x3a > > This problem is not exposed on most riscv builds just because the '0(s0)' > occasionally is the address frame 2 (caller's caller), if only ra and fp > are stored in frame 1 (caller). > > | ... | <-+ > +-----------------+ | > | return address | | > $fp --> | previous fp | | > +-----------------+ | > | return address | | > | previous fp --------+ > | saved registers | > $sp --> | local variables | > +-----------------+ > > This could be a *bug* of gcc that should be fixed. Yes, it would be nice to get this fixed. The riscv target does not override DYNAMIC_CHAIN_ADDRESS, thus the default is used, which has the noted effect. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."