From patchwork Tue Jun 9 01:47:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1305535 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=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=wuDQdJfL; 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 49gtLS1lQzz9sRK for ; Tue, 9 Jun 2020 11:48:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 72E8938708A8; Tue, 9 Jun 2020 01:48:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72E8938708A8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591667291; bh=thuMP4We5CysJTtcnnhJT7Ze77BCqD4kQ3YmKN/wenk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wuDQdJfLCUBMhcoVEs5+eiHglBO/8GBkYU6L2UMDW9psToRb/Ur9bas5LgkW9/yDu 3f0WBa0xCxdFSnAM9mIblMM8c8mFDLWGjISxjoOiDc2DHs3Ise4sh5qbJVJX8ovVOd ng7e0lEWQ5RsJlcUT1xFd+JZ6/IBeJmm3uzrZB0U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by sourceware.org (Postfix) with ESMTPS id BCCD0385DC00 for ; Tue, 9 Jun 2020 01:48:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BCCD0385DC00 Received: by mail-pg1-x541.google.com with SMTP id r18so3311522pgk.11 for ; Mon, 08 Jun 2020 18:48:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=thuMP4We5CysJTtcnnhJT7Ze77BCqD4kQ3YmKN/wenk=; b=CbHp07xvYzguXG7nm5lrFIt2Rn+H7EPGCNliuNSTD99AFa9HxkGe/UOTicaqkrheEK Y4vBFjWwYNv5Zk/gNeuvo1E5kuT6FEYMyX1Yv464UaiwlARGHq4udvBxJZ32Kjnll6I4 UDgN+SkKj2Eyh44KcemuKnr2wrLlEcwez5BvgBdk3CoSp+8oIlxyARd7wBhbkGaFb1yr i1oMiJI2ZqukOkDPb/SkjBOeENyDbwN7Teh83k9JJIIEDCGlLpBW/v2KxZ5umcd4RGIx anZDUJ014xU0Vt3wgVtVEQi8Oo7KbvK2E4Jf397Fxgtg3mX7V7k51bq8J097ybbHnrcS NnhA== X-Gm-Message-State: AOAM530qaRWUio0t6CoW3XYkV0OrgWEjiQPDL3SiBPuUEUgba7nIuN+v DZmb74pDLDNYd/U7SkL0nP+MTBBW X-Google-Smtp-Source: ABdhPJwcN9gWSDTWFMO02MsKMhYkWyrOmc+joCX/q11k90wQbDlNCwbg4exssjpwV0w3jnA57x+n6g== X-Received: by 2002:aa7:9abc:: with SMTP id x28mr21241355pfi.39.1591667287594; Mon, 08 Jun 2020 18:48:07 -0700 (PDT) Received: from octofox.cadence.com ([2601:641:400:e00:7571:e536:944d:12bc]) by smtp.gmail.com with ESMTPSA id a14sm8009514pfc.133.2020.06.08.18.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2020 18:48:06 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [committed] xtensa: libgcc: fix PR target/95571 Date: Mon, 8 Jun 2020 18:47:48 -0700 Message-Id: <20200609014748.10670-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, GIT_PATCH_0, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, KAM_NUMSUBJECT, KAM_SHORT, 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: , X-Patchwork-Original-From: Max Filippov via Gcc-patches From: Max Filippov Reply-To: Max Filippov Cc: Sterling Augustine , linux-xtensa@linux-xtensa.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Rewrite uw_install_context without function calls to avoid register spilling in _Unwind_RaiseException during return context installation. 2020-06-08 Max Filippov gcc/testsuite/ * g++.target/xtensa/pr95571.C: New test. * g++.target/xtensa/xtensa.exp: New testsuite. libgcc/ * config/xtensa/unwind-dw2-xtensa.c (uw_install_context): Merge with uw_install_context_1. --- Tested with xtensa-linux-uclibc, committed to master. gcc/testsuite/g++.target/xtensa/pr95571.C | 43 ++++++++++++++++++++ gcc/testsuite/g++.target/xtensa/xtensa.exp | 43 ++++++++++++++++++++ libgcc/config/xtensa/unwind-dw2-xtensa.c | 46 +++++++++++----------- 3 files changed, 108 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/g++.target/xtensa/pr95571.C create mode 100644 gcc/testsuite/g++.target/xtensa/xtensa.exp diff --git a/gcc/testsuite/g++.target/xtensa/pr95571.C b/gcc/testsuite/g++.target/xtensa/pr95571.C new file mode 100644 index 000000000000..59fe28528380 --- /dev/null +++ b/gcc/testsuite/g++.target/xtensa/pr95571.C @@ -0,0 +1,43 @@ +/* { dg-do run } */ + +extern "C" void abort(void); +extern "C" void __xtensa_libgcc_window_spill(void); + +static int call; +static int cnt; + +extern "C" void *memcpy(void *dst, const void *src, unsigned int sz) +{ + char *a = (char *)dst; + const char *b = (const char *)src; + + if (call++ == cnt) + __xtensa_libgcc_window_spill(); + + while (sz--) + *a++ = *b++; + + return dst; +} + +int main() +{ + int i; + + for (i = 0; i < 100; ++i) + { + call = 0; + cnt = i; + + try + { + throw 1; + } + catch (int v) + { + if (v != 1) + abort (); + } + } + return 0; +} diff --git a/gcc/testsuite/g++.target/xtensa/xtensa.exp b/gcc/testsuite/g++.target/xtensa/xtensa.exp new file mode 100644 index 000000000000..f4191201d11f --- /dev/null +++ b/gcc/testsuite/g++.target/xtensa/xtensa.exp @@ -0,0 +1,43 @@ +# Specific regression driver for Xtensa. +# Copyright (C) 2020 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . */ + +# GCC testsuite that uses the `dg.exp' driver. + +# Exit immediately if this isn't an Xtensa target. +if {![istarget xtensa*-*-*] } then { + return +} + +# Load support procs. +load_lib g++-dg.exp + +global DEFAULT_CXXFLAGS +if ![info exists DEFAULT_CXXFLAGS] then { + set DEFAULT_CXXFLAGS " -pedantic-errors" +} + +# Initialize `dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] \ + "" $DEFAULT_CXXFLAGS + +# All done. +dg-finish diff --git a/libgcc/config/xtensa/unwind-dw2-xtensa.c b/libgcc/config/xtensa/unwind-dw2-xtensa.c index 056182a794aa..8a6a44a8b685 100644 --- a/libgcc/config/xtensa/unwind-dw2-xtensa.c +++ b/libgcc/config/xtensa/unwind-dw2-xtensa.c @@ -481,37 +481,35 @@ uw_init_context_1 (struct _Unwind_Context *context, void *outer_cfa, /* Install TARGET into CURRENT so that we can return to it. This is a macro because __builtin_eh_return must be invoked in the context of - our caller. */ + our caller, and also because spilling registers of the caller before + the context installation may result in reload of wrong register values + after the context installation due to the change of the stack pointer + in the base save area. This spilling may be caused by an interrupt + handler on baremetal host. */ -#define uw_install_context(CURRENT, TARGET, FRAMES) \ +#define uw_install_context(CURRENT, TARGET, FRAMES) \ do \ { \ - long offset = uw_install_context_1 ((CURRENT), (TARGET)); \ void *handler = __builtin_frob_return_addr ((TARGET)->ra); \ - __builtin_eh_return (offset, handler); \ + long i; \ + \ + /* The eh_return insn assumes a window size of 8, so don't bother \ + copying the save areas for registers a8-a15 since they won't be \ + reloaded. */ \ + for (i = 0; i < 2; ++i) \ + { \ + _Unwind_Word *c = (CURRENT)->reg[i]; \ + _Unwind_Word *t = (TARGET)->reg[i]; \ + int j; \ + \ + if (t && c && t != c) \ + for (j = 0; j < 4; ++j) \ + *c++ = *t++; \ + } \ + __builtin_eh_return (0, handler); \ } \ while (0) -static long -uw_install_context_1 (struct _Unwind_Context *current, - struct _Unwind_Context *target) -{ - long i; - - /* The eh_return insn assumes a window size of 8, so don't bother copying - the save areas for registers a8-a15 since they won't be reloaded. */ - for (i = 0; i < 2; ++i) - { - void *c = current->reg[i]; - void *t = target->reg[i]; - - if (t && c && t != c) - memcpy (c, t, 4 * sizeof (_Unwind_Word)); - } - - return 0; -} - static inline _Unwind_Ptr uw_identify_context (struct _Unwind_Context *context) {