From patchwork Sat Feb 29 20:46:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1247145 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-520408-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=wQozgNbV; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Opj3Ttfr; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48VJP64fXVz9sPg for ; Sun, 1 Mar 2020 07:47:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:subject:from:reply-to:to:date:mime-version :content-type; q=dns; s=default; b=R2RhhXZtitEWHwiH8P9T3X8+GNu9K 6jAZl6kA8b3CdrNKZrIZfOdiTcXsSN+Kgo4BypkRN36UNguQbpGILogV5TrBdeAF iU+YAHdZzr0who5oOVTdht3IxMRHKYkVUbSpdQkTGzVIB6N5xtftlPe3NnHlFijA fB1vrKVfl5NVQM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:subject:from:reply-to:to:date:mime-version :content-type; s=default; bh=VUCu/lIv2ywz7JktFgppMAV48kw=; b=wQo zgNbVfN/7y4lxr8+5EyAYK4pN2ioTZmrqNZ5FjT4a4LxoSkmC3qlsmebMQp9eiwE 4PQoG0aNqD4aQvrnzGDdV1ca1wQn4caw+Pu5vxz7+uZAz9tTKEBygaN969GD5R1K NJMQUqYSH0IHQz5GR0dUpquCLJFUiCHiNPtB6BSY= Received: (qmail 80149 invoked by alias); 29 Feb 2020 20:46:57 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 80141 invoked by uid 89); 29 Feb 2020 20:46:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=circa X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 29 Feb 2020 20:46:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583009213; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type; bh=iVBO9zPuWeQeitySeKYbdOUyNJ6HM0KSGNfvDiJNF28=; b=Opj3TtfrWgx5StbekhsH4bC1NHTLQbC0hjaY0unmHJSxkWGiHoOVst+rdB+SQwU1SCLJc1 OWyTBrh4UxHG4wfgRYvkxxgBkghUzmqhotOTrSFPWiczaJE1WzO3n73oRSrIwylYBB5aDh rQ1SRzo6mRdFImI3CAixphjxt+9+O6E= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-6AQ190kAOBKekT5v0uqrlg-1; Sat, 29 Feb 2020 15:46:50 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DCC4B801E53 for ; Sat, 29 Feb 2020 20:46:49 +0000 (UTC) Received: from ovpn-116-163.phx2.redhat.com (ovpn-116-163.phx2.redhat.com [10.3.116.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id B00831001902 for ; Sat, 29 Feb 2020 20:46:49 +0000 (UTC) Message-ID: <32da4d9c196bd30988776e19c4f210381b630c92.camel@redhat.com> Subject: [committed] Fix STATIC_CHAIN_REGNUM for v850 port From: Jeff Law Reply-To: law@redhat.com To: gcc-patches List Date: Sat, 29 Feb 2020 13:46:49 -0700 User-Agent: Evolution 3.34.4 (3.34.4-1.fc31) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes Wow, I think I wrote the v850 port back in circa 1997 and this bug has been latent all this time. Vlad's IRA changes twiddled register allocation in just the right way to expose this bug. I'm not sure what I was thinking, but apparently I made a spectacularly bad choice for the STATIC_CHAIN_REGNUM in choosing a call-saved register (r20). It's simply wrong to use a call-saved register for the static chain. Think about what the case if we take the address of a nested function. We actually get the address of the trampoline. Then assume we call through that function pointer at some point deeper in the call stack. At the call site we have to express that the static chain register was changed, but there's no way to know at the call site -- that's the whole point of using the trampoline, it looks just like a normal indirect call. The only was I can see to fix this is to fix the static chain register to be a call clobbered register which is an ABI change. Thankfully the combination of v850 and nested functions probably isn't used terribly much. I've verified this fixed the recent v850 regressions. Committing to the trunk. Jeff commit c7dbc54958321d296ca4e283f26f279f6a5342a7 Author: Jeff Law Date: Sat Feb 29 13:45:37 2020 -0700 Make STATIC_CHAIN_REGNUM a call used register. * config/v850/v850.h (STATIC_CHAIN_REGNUM): Change to r19. * config/v850/v850.c (v850_asm_trampoline_template): Update accordingly. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7d95db8623f..2a69c680a9b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-02-28 Jeff Law + + * config/v850/v850.h (STATIC_CHAIN_REGNUM): Change to r19. + * config/v850/v850.c (v850_asm_trampoline_template): Update + accordingly. + 2020-02-28 Michael Meissner PR target/93937 diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c index 074adf87687..4b0e28c1786 100644 --- a/gcc/config/v850/v850.c +++ b/gcc/config/v850/v850.c @@ -2961,7 +2961,7 @@ static void v850_asm_trampoline_template (FILE *f) { fprintf (f, "\tjarl .+4,r12\n"); - fprintf (f, "\tld.w 12[r12],r20\n"); + fprintf (f, "\tld.w 12[r12],r19\n"); fprintf (f, "\tld.w 16[r12],r12\n"); fprintf (f, "\tjmp [r12]\n"); fprintf (f, "\tnop\n"); diff --git a/gcc/config/v850/v850.h b/gcc/config/v850/v850.h index 823bc5e17e3..7ae583c7df2 100644 --- a/gcc/config/v850/v850.h +++ b/gcc/config/v850/v850.h @@ -438,8 +438,9 @@ enum reg_class /* Base register for access to arguments of the function. */ #define ARG_POINTER_REGNUM 35 -/* Register in which static-chain is passed to a function. */ -#define STATIC_CHAIN_REGNUM 20 +/* Register in which static-chain is passed to a function. + This must be a call used register. */ +#define STATIC_CHAIN_REGNUM 19 /* If defined, this macro specifies a table of register pairs used to eliminate unneeded registers that point into the stack frame. If