From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 0EAF03858D33 for ; Tue, 31 May 2022 12:11:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0EAF03858D33 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24VAEAWe009414; Tue, 31 May 2022 12:11:17 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gdh3124t2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 May 2022 12:11:17 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24VC9OEf018503; Tue, 31 May 2022 12:11:15 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3gbcae42y4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 May 2022 12:11:15 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24VBupPC52035916 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 May 2022 11:56:51 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30A5711C050; Tue, 31 May 2022 12:11:13 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A04B11C04C; Tue, 31 May 2022 12:11:13 +0000 (GMT) Received: from [9.171.78.238] (unknown [9.171.78.238]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 31 May 2022 12:11:12 +0000 (GMT) Message-ID: <02882452-a27b-0e3d-64b2-d7657ac9031b@linux.ibm.com> Date: Tue, 31 May 2022 14:11:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: CFI for saved argument registers Content-Language: en-US To: gcc@gcc.gnu.org References: <7d266787-9a64-07e6-bf7b-1bd01119517c@linux.ibm.com> From: Andreas Krebbel In-Reply-To: <7d266787-9a64-07e6-bf7b-1bd01119517c@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: w3ksdK3uYJI68Vyj1kHrBbzqhupI8iIw X-Proofpoint-GUID: w3ksdK3uYJI68Vyj1kHrBbzqhupI8iIw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-05-31_04,2022-05-30_03,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2205310063 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2022 12:11:19 -0000 On 5/16/22 08:29, Andreas Krebbel via Gcc wrote: > Hi, > > I'm trying to provide a simple dwarf unwinder with access to the > argument register content. The goal is to make this information > available for optimized code without having to access debug > information for things like call site args. The extra overhead > of saving the values to the stack is acceptable in that case. > > For that purpose I save the argument registers to the stack as we > would do for a variable argument lists. But this time I also provide > the CFI to allow the unwinder to locate the save slots. Since I never > actually intend to restore the content there is no matching > cfi_restore for the cfi_offset and dwarf2cfi complains about the > traces being inconsistent because of that. I couldn't find a way to > prevent this. > > The only way I see right now is adding a new reg note to invalidate > the save information in the reg_save array in dwarf2cfi. > > Would this be acceptable? Is there perhaps an easier way to achieve that? Attached is a small patch adding a new reg note REG_CFA_NORESTORE. I would attach that new note to the register save insn to indicate that this register will not be restored. I'll have to emit the REG_CFA_OFFSET note as well then. An insn saving r2-r6 without restoring them would look like this then: (insn/f 31 21 32 2 (parallel [ (set/f (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 16 [0x10])) [4 S8 A8]) (reg:DI 2 %r2)) (set/f (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 24 [0x18])) [4 S8 A8]) (reg:DI 3 %r3)) (set/f (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 32 [0x20])) [4 S8 A8]) (reg:DI 4 %r4)) (set/f (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 40 [0x28])) [4 S8 A8]) (reg:DI 5 %r5)) (set/f (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 48 [0x30])) [4 S8 A8]) (reg:DI 6 %r6)) ]) "/home/andreas/preserveargs/reduce2/t.c":2:51 -1 (expr_list:REG_CFA_OFFSET (set (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 48 [0x30])) [4 S8 A8]) (reg:DI 6 %r6)) (expr_list:REG_CFA_NO_RESTORE (reg:DI 6 %r6) (expr_list:REG_CFA_OFFSET (set (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 40 [0x28])) [4 S8 A8]) (reg:DI 5 %r5)) (expr_list:REG_CFA_NO_RESTORE (reg:DI 5 %r5) (expr_list:REG_CFA_OFFSET (set (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 32 [0x20])) [4 S8 A8]) (reg:DI 4 %r4)) (expr_list:REG_CFA_NO_RESTORE (reg:DI 4 %r4) (expr_list:REG_CFA_OFFSET (set (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 24 [0x18])) [4 S8 A8]) (reg:DI 3 %r3)) (expr_list:REG_CFA_NO_RESTORE (reg:DI 3 %r3) (expr_list:REG_CFA_OFFSET (set (mem/c:DI (plus:DI (reg/f:DI 15 %r15) (const_int 16 [0x10])) [4 S8 A8]) (reg:DI 2 %r2)) (expr_list:REG_CFA_NO_RESTORE (reg:DI 2 %r2) (nil)))))))))))) diff --git a/gcc/dwarf2cfi.c b/gcc/dwarf2cfi.c index 362ff3fdac27..2cbc2465c3a7 100644 --- a/gcc/dwarf2cfi.c +++ b/gcc/dwarf2cfi.c @@ -1346,7 +1346,7 @@ dwarf2out_frame_debug_cfa_val_expression (rtx set) /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */ static void -dwarf2out_frame_debug_cfa_restore (rtx reg) +dwarf2out_frame_debug_cfa_restore (rtx reg, bool emit_cfi) { gcc_assert (REG_P (reg)); @@ -1354,7 +1354,8 @@ dwarf2out_frame_debug_cfa_restore (rtx reg) if (!span) { unsigned int regno = dwf_regno (reg); - add_cfi_restore (regno); + if (emit_cfi) + add_cfi_restore (regno); update_row_reg_save (cur_row, regno, NULL); } else @@ -1369,7 +1370,8 @@ dwarf2out_frame_debug_cfa_restore (rtx reg) reg = XVECEXP (span, 0, par_index); gcc_assert (REG_P (reg)); unsigned int regno = dwf_regno (reg); - add_cfi_restore (regno); + if (emit_cfi) + add_cfi_restore (regno); update_row_reg_save (cur_row, regno, NULL); } } @@ -2155,6 +2157,7 @@ dwarf2out_frame_debug (rtx_insn *insn) break; case REG_CFA_RESTORE: + case REG_CFA_NO_RESTORE: n = XEXP (note, 0); if (n == NULL) { @@ -2163,7 +2166,7 @@ dwarf2out_frame_debug (rtx_insn *insn) n = XVECEXP (n, 0, 0); n = XEXP (n, 0); } - dwarf2out_frame_debug_cfa_restore (n); + dwarf2out_frame_debug_cfa_restore (n, REG_NOTE_KIND (note) == REG_CFA_RESTORE); handled_one = true; break; diff --git a/gcc/reg-notes.def b/gcc/reg-notes.def index 995052ebc28e..3e8cc189301c 100644 --- a/gcc/reg-notes.def +++ b/gcc/reg-notes.def @@ -167,6 +167,8 @@ REG_CFA_NOTE (CFA_VAL_EXPRESSION) first pattern is the register to be restored. */ REG_CFA_NOTE (CFA_RESTORE) +REG_CFA_NOTE (CFA_NO_RESTORE) + /* Attached to insns that are RTX_FRAME_RELATED_P, marks insn that sets vDRAP from DRAP. If vDRAP is a register, vdrap_reg is initalized to the argument, if it is a MEM, it is ignored. */