From patchwork Sun Sep 17 12:51:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 814650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-462327-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GdZA1NBu"; 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 3xw8Cg0GgVz9s81 for ; Sun, 17 Sep 2017 22:51:40 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=Z2p4rCUGf739jdoXd7QGmMNr0QdCo1O+SXVV5SRXc4fEd1cs6K Da4D9zvNH4je3S3quml7Nd04eAiZCyJkoxCboYd+zU5GiVhI56RJ6q4rkVPor4/9 /0y37VGgMLwrx+arRfGDpTKOfRvfZnrwEXyIoVqptwrO4Tu40KT7NgaNY= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=9l9+0opfcnCIRI4Mada+lCgKujg=; b=GdZA1NBuiAhMTweR1K93 R3AzSuJul3wAA+cJZtWlxquhr3Dg9Up+Gjp5diTmQsFY1ZwFE938BXvWMaREnTH/ C9EBak9xs8Rblq6SsUfy0Mt9zUrlvHHknIFm9pH0nMvuNYQtKgwQ/cPoGD1ApitP 9eI2dy7fJRevEMQp/SRohPU= Received: (qmail 71110 invoked by alias); 17 Sep 2017 12:51:32 -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 71101 invoked by uid 89); 17 Sep 2017 12:51:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1946 X-HELO: mail-pf0-f175.google.com Received: from mail-pf0-f175.google.com (HELO mail-pf0-f175.google.com) (209.85.192.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 17 Sep 2017 12:51:30 +0000 Received: by mail-pf0-f175.google.com with SMTP id g65so3530113pfe.13 for ; Sun, 17 Sep 2017 05:51:30 -0700 (PDT) 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:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=1M8SOdd7DMl4kpZa6eX+90KfsoZCBppM4A+by19UFv0=; b=ZL2EotnC7f/CeSp0fzJFoFWGY4n6a5eMkhpCPDw2hPx9aZ+qcoqkKnATikMpBWHrhH phghSOrTqG7UDVzi32u7R9EmCm0s3qrFPw+wGmsFtKnegV+zjlXCaJsRUL7H3XWOXLb5 uOafekj4vEzrv07IjhyGFEOyp8bV4J/+eccIxw2JzwtUCXtYCl+AmKyP29G4cyhktQHr f6VggW6Pb5wuvg7NKEC3BlnB/i2VxGBZ7zBrTA1tdUKSb6+n5JW/7A35NmBNqlQhGSPX UBl9W12lgteMk8crgSB9WF4pMBTs8fKan/+N70GFTIgIyjOFStfzMDg4ZDnLjx/c4iYp 3jNg== X-Gm-Message-State: AHPjjUjaTqfkSb5U4+xK4IrBbFSUVqx+XvGqSFsnCky7bUX5RDjamXGE 77XQiVNV0D2uQlVq2IA= X-Google-Smtp-Source: ADKCNb6IfYiWDfi+AtD77Ul8vysX/nFILdokmXxt4D9gPnNKbTcOmpNoWlRdSosjTIU2wzu74SFtEQ== X-Received: by 10.98.158.201 with SMTP id f70mr30522884pfk.162.1505652688606; Sun, 17 Sep 2017 05:51:28 -0700 (PDT) Received: from bubble.grove.modra.org (CPE-58-175-73-248.czqe1.win.bigpond.net.au. [58.175.73.248]) by smtp.gmail.com with ESMTPSA id m6sm9592215pfm.103.2017.09.17.05.51.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Sep 2017 05:51:27 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 6E593C3091; Sun, 17 Sep 2017 22:21:23 +0930 (ACST) Date: Sun, 17 Sep 2017 22:21:23 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [RS6000] PR81996, __builtin_return_address(0) fails Message-ID: <20170917125123.GP3528@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes When -fstack-protector-all or -fsanitize=address, rs6000.h sets FRAME_GROWS_DOWNWARD. This breaks the assumption in rs6000_return_addr that the stack link is at frame_pointer+0. Bootstrapped and regression tested powerpc64le-linux and powerpc64-linux -m32/-m64. OK? PR target/81996 * gcc/config/rs6000/rs6000.c (rs6000_return_addr): Use stack_pointer_rtx for count 0. Update comments. Break up large rtl expression. diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index e611c45..f14392d 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -24988,24 +24988,23 @@ debug_stack_info (rs6000_stack_t *info) rtx rs6000_return_addr (int count, rtx frame) { - /* Currently we don't optimize very well between prolog and body - code and for PIC code the code can be actually quite bad, so - don't try to be too clever here. */ + /* We can't use get_hard_reg_initial_val for LR when count == 0 if LR + is trashed by the prologue, as it is for PIC on ABI_V4 and Darwin. */ if (count != 0 || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) && flag_pic)) { cfun->machine->ra_needs_full_frame = 1; - return - gen_rtx_MEM - (Pmode, - memory_address - (Pmode, - plus_constant (Pmode, - copy_to_reg - (gen_rtx_MEM (Pmode, - memory_address (Pmode, frame))), - RETURN_ADDRESS_OFFSET))); + if (count == 0) + /* FRAME is set to frame_pointer_rtx by the generic code, but that + is good for loading 0(r1) only when !FRAME_GROWS_DOWNWARD. */ + frame = stack_pointer_rtx; + rtx prev_frame_addr = memory_address (Pmode, frame); + rtx prev_frame = copy_to_reg (gen_rtx_MEM (Pmode, prev_frame_addr)); + rtx lr_save_off = plus_constant (Pmode, + prev_frame, RETURN_ADDRESS_OFFSET); + rtx lr_save_addr = memory_address (Pmode, lr_save_off); + return gen_rtx_MEM (Pmode, lr_save_addr); } cfun->machine->ra_need_lr = 1;