From patchwork Wed Sep 9 10:33:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jozef Lawrynowicz X-Patchwork-Id: 1360573 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mittosystems.com header.i=@mittosystems.com header.a=rsa-sha256 header.s=google header.b=E0HCNRwl; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BmdfT4f5fz9sTN for ; Wed, 9 Sep 2020 20:33:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A1FF3857818; Wed, 9 Sep 2020 10:33:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 732B73857C74 for ; Wed, 9 Sep 2020 10:33:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 732B73857C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jozef.l@mittosystems.com Received: by mail-wr1-x436.google.com with SMTP id o5so2320751wrn.13 for ; Wed, 09 Sep 2020 03:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition; bh=Vp6kFOL9Ix07vuHHCIHT6roDaB1/agTIXabQIrUKjRY=; b=E0HCNRwlDEit4WcCb2HhXIF4qRmQqyYRqnuUQ8hFQUN6+iU+93j9IAbTEfRQtgHRHl YTnTYw5h374m6b+ZlWSUy8fYAHwwPJK3sn6Tdls6viQTsGj7FNJ8GHJbzbH2EtRYBWp7 WEmOAsvHUd8I/gbtcUSJEAcEGCaILrwh3ZVkMYggh8L0fxoFTQEidRUpuR3kq1Ny37Dx FCmH2rOAAfdq0x8xOcxoP7LCFiwt6oQ/KympEKST8WIPVmlVwV1ZfmRMMAgfvOOgIrQL mHNXvH9Z2CX/LyVY5Q1Qy8CbYDnRJbrSvaOLQsuMUB26Ud+bIxl9gIU1pIrtYe3bHh5A hAtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition; bh=Vp6kFOL9Ix07vuHHCIHT6roDaB1/agTIXabQIrUKjRY=; b=Wc7aSncVP+hTq3HfqjrF7P3ZVv0HaIT832myT8Ld75LatIa+c487wvIdvrHvoH5eoV kEqls6mKilKzbrVFpwYUnmqMiX1GLbwAmWtKdypTOr4zdIF/dxcoeDcZxVKM3iY1UIxX ee2OHJPZ/hmRHVkkumgfi7KzUNwogIbiCmG7LvDmfKpu3EtiQWT7szuDC4Cy6HdlRMip CfF42SlRz6ZfEQTvba6vwbqc0OttENhR727btZ7xeg/9OL4WYKxHY28lQu63QjfcdiAE dM8847J0L/IXsYFYa3N3q6YoUIpwBxPHs4+yhf4SHXTAz3h25T6A7nrvBsDCs/AeEet1 xFUg== X-Gm-Message-State: AOAM5313q/JnZ0JsZbxSuCNsZ/eGjAkBIe0o4X4VS57/I+heC8ih8dQe TpmQjYAwnkLiw71OcN2Wy+EYuKHYknIamQ== X-Google-Smtp-Source: ABdhPJy621WMJb4bHrtms1rng086GDtNoLqRIq3EpW11Z/dx1RmVEJ+a22tb1zEnrrtlX2vStoHe6Q== X-Received: by 2002:adf:f88d:: with SMTP id u13mr2786543wrp.213.1599647625166; Wed, 09 Sep 2020 03:33:45 -0700 (PDT) Received: from jozef-acer-manjaro ([2a01:4b00:87fd:900:5e1d:5c99:56da:76e8]) by smtp.gmail.com with ESMTPSA id k4sm3487145wrx.51.2020.09.09.03.33.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 03:33:44 -0700 (PDT) Date: Wed, 9 Sep 2020 11:33:42 +0100 From: Jozef Lawrynowicz To: gcc-patches@gcc.gnu.org Subject: [PATCH] MSP430: Fix CFA generation during function epilogues Message-ID: <20200909103342.3gj2c6vipuex4qby@jozef-acer-manjaro> Mail-Followup-To: gcc-patches@gcc.gnu.org MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" There is no CFA information generated for instructions which manipulate the stack during function epilogues. This means a debugger cannot determine the position of variables on the stack whilst the epilogue is in progress. This can cause the debugger to give erroneous information when printing a backtrace whilst stepping through the epilogue, or cause software watchpoints set on stack variables to become invalidated after a function epilogue is executed. The patch fixes this by marking stack manipulation insns as frame_related, and adding reg_note RTXs to stack pop instructions in the epilogue. Successfully regtested on trunk for msp430-elf in the default, -mlarge, -mcpu=msp430 and -mlarge/-mcode-region=either/-mdata-region=either configurations. This fixes some tests from watchpoint.exp in the GDB testsuite. Ok for trunk? Thanks, Jozef From 272b38a374eddf7327a61ff9b1730f0a2dd40233 Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Mon, 7 Sep 2020 20:34:40 +0100 Subject: [PATCH] MSP430: Fix CFA generation during function epilogues There is no CFA information generated for instructions which manipulate the stack during function epilogues. This means a debugger cannot determine the position of variables on the stack whilst the epilogue is in progress. This can cause the debugger to give erroneous information when printing a backtrace whilst stepping through the epilogue, or cause software watchpoints set on stack variables to become invalidated after a function epilogue is executed. The patch fixes this by marking stack manipulation insns as frame_related, and adding reg_note RTXs to stack pop instructions in the epilogue. gcc/ChangeLog: * config/msp430/msp430.c (increment_stack): Mark insns which increment the stack as frame_related. (msp430_expand_prologue): Add comments. (msp430_expand_epilogue): Mark insns which decrement the stack as frame_related. Add reg_note to stack pop insns describing position of register variables on the stack. --- gcc/config/msp430/msp430.c | 72 +++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c index 129b916715e..1cb1b8f8626 100644 --- a/gcc/config/msp430/msp430.c +++ b/gcc/config/msp430/msp430.c @@ -1700,9 +1700,9 @@ increment_stack (HOST_WIDE_INT amount) { inc = GEN_INT (amount); if (TARGET_LARGE) - emit_insn (gen_addpsi3 (sp, sp, inc)); + F (emit_insn (gen_addpsi3 (sp, sp, inc))); else - emit_insn (gen_addhi3 (sp, sp, inc)); + F (emit_insn (gen_addhi3 (sp, sp, inc))); } } @@ -2413,6 +2413,8 @@ msp430_expand_prologue (void) for (i = 15; i >= 4; i--) if (cfun->machine->need_to_save[i]) { + /* We need to save COUNT sequential registers starting from regnum + I. */ int seq, count; rtx note; @@ -2427,6 +2429,7 @@ msp430_expand_prologue (void) p = F (emit_insn (gen_pushm (gen_rtx_REG (Pmode, i), GEN_INT (count)))); + /* Document the stack decrement as a result of PUSHM. */ note = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1)); XVECEXP (note, 0, 0) @@ -2475,8 +2478,10 @@ msp430_expand_prologue (void) void msp430_expand_epilogue (int is_eh) { - int i; + int i, j; int fs; + rtx sp = stack_pointer_rtx; + rtx p; int helper_n = 0; if (is_naked_func ()) @@ -2545,19 +2550,27 @@ msp430_expand_epilogue (int is_eh) for (i = 4; i <= 15; i++) if (cfun->machine->need_to_save[i]) { - int seq, count; + /* We need to restore COUNT sequential registers starting from regnum + I. */ + int seq; + int count = 1; + int helper_used = 0; + rtx note, addr; - for (seq = i + 1; seq <= 15 && cfun->machine->need_to_save[seq]; seq ++) - ; - count = seq - i; + if (msp430x) + { + for (seq = i + 1; seq <= 15 && cfun->machine->need_to_save[seq]; + seq++) + ; + count = seq - i; + } if (msp430x) { /* Note: With TARGET_LARGE we still use POPM as POPX.A is two bytes bigger. */ - emit_insn (gen_popm (stack_pointer_rtx, GEN_INT (seq - 1), - GEN_INT (count))); - i += count - 1; + p = F (emit_insn (gen_popm (stack_pointer_rtx, GEN_INT (seq - 1), + GEN_INT (count)))); } else if (i == 11 - helper_n && ! msp430_is_interrupt_func () @@ -2569,11 +2582,44 @@ msp430_expand_epilogue (int is_eh) && helper_n > 1 && !is_eh) { - emit_jump_insn (gen_epilogue_helper (GEN_INT (helper_n))); - return; + p = F (emit_jump_insn (gen_epilogue_helper (GEN_INT (helper_n)))); + count = helper_n; + helper_used = 1; } else - emit_insn (gen_pop (gen_rtx_REG (Pmode, i))); + p = F (emit_insn (gen_pop (gen_rtx_REG (Pmode, i)))); + + /* Document the stack increment as a result of POPM. */ + note = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (count + 1)); + + addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx, + GEN_INT (count * (TARGET_LARGE ? 4 : 2))); + + XVECEXP (note, 0, 0) = F (gen_rtx_SET (stack_pointer_rtx, addr)); + + + /* *sp++ = R[i+j] */ + /* sp R4 + ... + sp+N R10. */ + for (j = 0; j < count; j++) + { + int ofs = j * (TARGET_LARGE ? 4 : 2); + + if (ofs) + addr = gen_rtx_PLUS (Pmode, sp, GEN_INT (ofs)); + else + addr = stack_pointer_rtx; + + XVECEXP (note, 0, j + 1) + = F (gen_rtx_SET (gen_rtx_MEM (Pmode, addr), + gen_rtx_REG (Pmode, i + j))); + } + add_reg_note (p, REG_FRAME_RELATED_EXPR, note); + i += count - 1; + + if (helper_used) + return; } if (is_eh)