Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp862673lqt; Fri, 7 Jun 2024 00:14:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVHOBtiCk//KydSr+Fth21LCbQdSCLO4MbQPrPFL3nIxHoJsHRdTw6nqVjJRaDR0UUVChm84xbft1gQarebUoXQnK94VlzGz2KJwzawIQ== X-Google-Smtp-Source: AGHT+IFrfq2/j8HDZVFudqwMLhnHw3TVw0nAwWkmySnPBWHEWiNBtOhA9oLyZKNj2e28ox4Aecr+ X-Received: by 2002:a05:6808:1b26:b0:3c7:52da:2055 with SMTP id 5614622812f47-3d210d1e138mr2287448b6e.2.1717744498616; Fri, 07 Jun 2024 00:14:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717744498; cv=pass; d=google.com; s=arc-20160816; b=OQ79PNGQzNB2SC0znQZzk0bjgyUyfTDXCQl+rAkEQRTQXxweox6kFmAbRNlxRb6ZGd mXVukSWqfuoSOX2aZ4qqTt9a15LkJBEO+FxsjK6jj0IdZsoJeKBGq1FXH04jerBqHacx 1kLGVisyaVpCuyIuCcVyzmGilaxFtawvb+HMrdV3uZX8IkzmWbogPaIK6bt5gdjXT7ab OXfiWw4o7CnmUVRcrfaLMzDky5NseoSxxWxCP8Q1Ofv2EgUXzvGaQcqI1HcPbgv9QCAL iC+OmOGnppHBVVE5Kb/4OioMARHVq2+UODDdwjyTRnASE/VGyOF2JHnmgZSy+UIbi3vB iFyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-language:content-transfer-encoding:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=PJqNZXxPnmlpQvYVuJ9OkqplO2bQoizZLJeY0xvR/i0=; fh=mwRL44bA+DE/f1UP9cV1obMyw4XCHUqy5rvezUdsesA=; b=BKAa4hg/TuVZ5UyUGV5xOekTbGfoBcd50et7v2x1Q7R9mOVtllg+47q9ZmjjfRJzPQ W6U+KNwzbGL5K+7eYr9CYcwc+CBlwhbZ6/CR8HWa+JytOAGQ1qt4umAe2huAkDyIw0FM pwZ/1yKFLRYIAFraOiKs0BvRD3KTp3rAF+OkZxnRvrIv5I+mjTyUmKnkxgD4ATP9nzKE vq7cLTuFgv/e0oSfg1xsB2Jp6949yz1Os1FTPSEMniv5AsiqL3TYs1SVJJGaBl4Hw0i6 LK583lktMA+1Q0rCoigeY7P1+PhDKs32Zpa4FrDbdX2wGCRhRR3qkMG7YZ7ru5X8azuT hUeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-205501-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205501-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-7954139a1b9si79835085a.640.2024.06.07.00.14.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 00:14:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205501-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-205501-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205501-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3B8051C22356 for ; Fri, 7 Jun 2024 07:14:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE003152530; Fri, 7 Jun 2024 07:14:51 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83B9B14F9CE for ; Fri, 7 Jun 2024 07:14:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717744491; cv=none; b=YP36oq0fB2Tza3mpBqmAyuzbtcdNutx/jHjVXdCmkGpBf3Cl+wWlftA4LadZxdcETXbcFNolzYzrhdichXFrox9xM4z4qf0P6JNCsjAQ0Z7+4NrbsLIaWOcQBHp7xMgN3FAdInOgoOBeHUTrWOxpBZM0ZKYzIwsQUiW0DcVmSKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717744491; c=relaxed/simple; bh=noukMO3+jRs+9c7owGXF7Wluq9C2LqsXKD62IPTB79w=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=gCBJXNNj9hXT6lWY2PQTTbg+fPcUMuLApQwPm6EkkIZYuzYhOsKnMJsCs9HP09szNAf5xpk5X1L+/uSRbenUxPAba8N9d7hng5wLiLkT15HoLdq+tmzKENC8H9B3d/0LApLc9GsEKpm/msteEu6XO5muM6iUJtW5ck3mjSFYID4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [111.9.175.10]) by gateway (Coremail) with SMTP id _____8AxHutms2Jm8ogEAA--.19052S3; Fri, 07 Jun 2024 15:14:46 +0800 (CST) Received: from [10.136.12.26] (unknown [111.9.175.10]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxnsdhs2JmmOkXAA--.60131S3; Fri, 07 Jun 2024 15:14:44 +0800 (CST) Subject: Re: [PATCH] loongarch: Only select HAVE_OBJTOOL and allow ORC unwinder if the inline assembler supports R_LARCH_{32,64}_PCREL To: Xi Ruoyao , Nathan Chancellor , Peter Zijlstra Cc: Huacai Chen , WANG Xuerui , Tiezhu Yang , Nick Desaulniers , Bill Wendling , Justin Stitt , Youling Tang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, mengqinggang@loongson.cn, cailulu@loongson.cn, wanglei@loongson.cn, luweining@loongson.cn, Yujie Liu , Heng Qi , Tejun Heo References: <20240604150741.30252-1-xry111@xry111.site> <20240605054328.GA279426@thelio-3990X> <20240605062548.GF279426@thelio-3990X> <444ec2031ef6ca016cbfa8dfedc51bddc8529ba7.camel@xry111.site> <82b7e6ea-c2cb-6364-ebe9-bff928028408@loongson.cn> <1c132209a612e2e8953f0b458fc01853120db9a9.camel@xry111.site> <2bf11cd2-8449-acda-f5ad-659c38cb018e@loongson.cn> <96a2e8a80c06772b64fcbdba42e1dae2d68a53a7.camel@xry111.site> From: Jinyang He Message-ID: <2bd6ae20-ec56-c1a2-c5dd-e8c978a376d3@loongson.cn> Date: Fri, 7 Jun 2024 15:14:41 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <96a2e8a80c06772b64fcbdba42e1dae2d68a53a7.camel@xry111.site> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8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5MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j0mhrUUU UU= On 2024-06-07 13:42, Xi Ruoyao wrote: > On Thu, 2024-06-06 at 10:10 +0800, Jinyang He wrote: >> What I just confused is that there is no ".cfi_*" >> in the eplogue by clang, which may cause wrong backtrace if gdb set >> >> breakpoint there and backtrace. (But this is out of this topic.) > I don't think it'll cause wrong backtrace. The real assemble code has > restored the registers and missing .cfi_restore will just make unwinder > restore them again. There are redundant works but not breakages. $ cat hello.c: extern void __attribute__((noinline)) foo() {} int main() {   foo();   return (int)(long)__builtin_frame_address(0); } $ clang hello.c -S -g -o hello.s -O0 -fPIC $ cat hello.s: [...]         addi.d  $sp, $sp, -32         .cfi_def_cfa_offset 32         st.d    $ra, $sp, 24                    # 8-byte Folded Spill         st.d    $fp, $sp, 16                    # 8-byte Folded Spill         .cfi_offset 1, -8         .cfi_offset 22, -16         addi.d  $fp, $sp, 32         .cfi_def_cfa 22, 0         move    $a0, $zero         st.w    $a0, $fp, -20 .Ltmp2:         .loc    0 3 3 prologue_end              # hello.c:3:3         bl      %plt(foo)         .loc    0 4 21                          # hello.c:4:21         move    $a0, $fp         .loc    0 4 3 is_stmt 0                 # hello.c:4:3         addi.w  $a0, $a0, 0         ld.d    $fp, $sp, 16                    # 8-byte Folded Reload         ld.d    $ra, $sp, 24                    # 8-byte Folded Reload         .loc    0 4 3 epilogue_begin            # hello.c:4:3         addi.d  $sp, $sp, 32         ret [...] So how unwinder do if we ? I think if we not give ".cfi_restore 22" or others info, it will consider   1) the $ra is in cfa-8   2) the cfa is $fp So it will get $ra by $ra = *(long*)($fp-8). So it may unwind failed because $fp has been restored and not the CFA now. > For objtool the main difference seems a thing explained in > https://maskray.me/blog/2020-11-08-stack-unwinding by Fangrui: > > Note: on RISC-V and LoongArch, the stack slot for the previous frame > pointer is stored at fp[-2] instead of fp[0]. See [Consider > standardising which stack slot fp points > to](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/18) > for the RISC-V discussion. In most cases the $fp is saved at cfa-16. But for va args, something becomes different at LoongArch (I do not know the case of riscv), the $fp isn't saved at cfa-16. (e.g. printk?) > So perhaps we just need to code a constant named "PREV_BP_OFFSET" Can you give some detail? > or > something in arch/ and use it in update_cfi_state() instead of fully re- > implement the entire function? I feel that the update_cfi_state should be arch specific. I believe that some logic can be reused, but each arch may have its own logic. Thanks, Jinyang