From patchwork Mon Feb 27 19:58:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 143258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B908BB6FB9 for ; Tue, 28 Feb 2012 06:59:06 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1330977548; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Received-SPF:Received:Received:Received:From:To:Mail-Followup-To: Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=qRD71rplIeGiTyKRBPMF CL26eiY=; b=Tt8w71FnsW8Ppu+S8VmEPoYN1VaLkJo1dqZuJiOWmjcU36sVnuya HKI81iggblEnhGxAUHS6E4g1LWfjYhe8d0crVIOEphlo/lMfvPQpjAc18N/hF3wm PC/7RofpggZHx0DIgJMtgTeOOwGS0R7t6MBz6eseoitQw1ciKqf6A1M= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received-SPF:Authentication-Results:Received:Received:Received:From:To:Mail-Followup-To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=sSevd3DMD1cdYTxqK7F8PnuHuZ0Tn5OSeZlmtzOHlTjv1dvk4G5m6NyzZN56/v DnnGEqeeWRKNdN3nSLZZClkmeIBtBOiR/SkkPGfLM5q2mXxLesW0IrvAeYlTK+15 E9Zqom6CvLmCcDewUxw9Gjp3hcDBRMVQaJaKb+hwrmFKE=; Received: (qmail 13397 invoked by alias); 27 Feb 2012 19:59:03 -0000 Received: (qmail 13386 invoked by uid 22791); 27 Feb 2012 19:59:02 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_TX X-Spam-Check-By: sourceware.org Received: from mail-wi0-f175.google.com (HELO mail-wi0-f175.google.com) (209.85.212.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Feb 2012 19:58:48 +0000 Received: by wibhq12 with SMTP id hq12so532115wib.20 for ; Mon, 27 Feb 2012 11:58:47 -0800 (PST) Received-SPF: pass (google.com: domain of rdsandiford@googlemail.com designates 10.180.95.1 as permitted sender) client-ip=10.180.95.1; Authentication-Results: mr.google.com; spf=pass (google.com: domain of rdsandiford@googlemail.com designates 10.180.95.1 as permitted sender) smtp.mail=rdsandiford@googlemail.com; dkim=pass header.i=rdsandiford@googlemail.com Received: from mr.google.com ([10.180.95.1]) by 10.180.95.1 with SMTP id dg1mr31295761wib.21.1330372727441 (num_hops = 1); Mon, 27 Feb 2012 11:58:47 -0800 (PST) Received: by 10.180.95.1 with SMTP id dg1mr24835493wib.21.1330372727398; Mon, 27 Feb 2012 11:58:47 -0800 (PST) Received: from localhost (rsandifo.gotadsl.co.uk. [82.133.89.107]) by mx.google.com with ESMTPS id er8sm59733692wib.1.2012.02.27.11.58.46 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 27 Feb 2012 11:58:46 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: PR middle-end/52373: two pc_rtxs, etc. Date: Mon, 27 Feb 2012 19:58:42 +0000 Message-ID: <877gz8oxot.fsf@talisman.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 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 This patch fixed PR 52373, which is a segfault or rtl checking failure (depending on how lucky you are) on mips-sgi-irix6.5. I can't reproduce it on *-elf or *-linux-gnu, probably because we use .cfi_* there. The problem is that, although pc_rtx is expected to be unique, it is recreated by each call to target_reinit, so we can end up with different values through the runtime of the compiler. This confused dwarf2cfi.c, which sets up cie_return_save with a pc_rtx reference when first called, and reuses it for all later functions (by which time we might have created a new pc_rtx). Pointer equality can then fail. The first four global_rtxs aren't target-dependent, so I think we should treat them in the same way as constants. It'll also make debugging slightly easier. The problem is a bit deeper than that really. Having only one CIE isn't fully general, since things like the frame pointer are allowed to change between subtargets (and do on MIPS). But it happens that the CIE we create for MIPS works for both modes, so I think this patch is good enough in practice. Tested on mips-sde-elf with rtl checking enabled. There were no differences. Also tested with a mips-sgi-irix6.5 cc1 cross to verify that it fixes the bug. OK to install? Richard gcc/ * rtl.h (pc_rtx, ret_rtx, simple_return_rtx, cc0_rtx): Redefine as variables. (GR_PC, GR_CC0, GR_RETURN, GR_SIMPLE_RETURN): Delete. * emit-rtl.c (pc_rtx, ret_rtx, simple_return_rtx, cc0_rtx): New variables. (init_emit_regs): Move associated initialization to... (init_emit_once): ...here. Index: gcc/rtl.h =================================================================== --- gcc/rtl.h 2012-02-26 10:30:27.817985876 +0000 +++ gcc/rtl.h 2012-02-26 11:21:47.372978342 +0000 @@ -2089,6 +2089,11 @@ #define CONST1_RTX(MODE) (const_tiny_rtx #define CONST2_RTX(MODE) (const_tiny_rtx[2][(int) (MODE)]) #define CONSTM1_RTX(MODE) (const_tiny_rtx[3][(int) (MODE)]) +extern rtx pc_rtx; +extern rtx cc0_rtx; +extern rtx ret_rtx; +extern rtx simple_return_rtx; + /* If HARD_FRAME_POINTER_REGNUM is defined, then a special dummy reg is used to represent the frame pointer. This is because the hard frame pointer and the automatic variables are separated by an amount @@ -2112,10 +2117,6 @@ #define HARD_FRAME_POINTER_IS_ARG_POINTE /* Index labels for global_rtl. */ enum global_rtl_index { - GR_PC, - GR_CC0, - GR_RETURN, - GR_SIMPLE_RETURN, GR_STACK_POINTER, GR_FRAME_POINTER, /* For register elimination to work properly these hard_frame_pointer_rtx, @@ -2208,12 +2209,6 @@ #define top_of_stack \ #define mode_mem_attrs \ (this_target_rtl->x_mode_mem_attrs) -/* Standard pieces of rtx, to be substituted directly into things. */ -#define pc_rtx (global_rtl[GR_PC]) -#define ret_rtx (global_rtl[GR_RETURN]) -#define simple_return_rtx (global_rtl[GR_SIMPLE_RETURN]) -#define cc0_rtx (global_rtl[GR_CC0]) - /* All references to certain hard regs, except those created by allocating pseudo regs into them (when that's possible), go through these unique rtx objects. */ Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c 2012-02-26 10:30:27.817985876 +0000 +++ gcc/emit-rtl.c 2012-02-26 11:21:47.369978342 +0000 @@ -117,6 +117,12 @@ rtx const_tiny_rtx[4][(int) MAX_MACHINE_ rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1]; +/* Standard pieces of rtx, to be substituted directly into things. */ +rtx pc_rtx; +rtx ret_rtx; +rtx simple_return_rtx; +rtx cc0_rtx; + /* A hash table storing CONST_INTs whose absolute value is greater than MAX_SAVED_CONST_INT. */ @@ -5536,10 +5542,6 @@ init_emit_regs (void) init_reg_modes_target (); /* Assign register numbers to the globally defined register rtx. */ - pc_rtx = gen_rtx_fmt_ (PC, VOIDmode); - ret_rtx = gen_rtx_fmt_ (RETURN, VOIDmode); - simple_return_rtx = gen_rtx_fmt_ (SIMPLE_RETURN, VOIDmode); - cc0_rtx = gen_rtx_fmt_ (CC0, VOIDmode); stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM); frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM); hard_frame_pointer_rtx = gen_raw_REG (Pmode, HARD_FRAME_POINTER_REGNUM); @@ -5855,6 +5857,11 @@ init_emit_once (void) const_tiny_rtx[0][(int) BImode] = const0_rtx; if (STORE_FLAG_VALUE == 1) const_tiny_rtx[1][(int) BImode] = const1_rtx; + + pc_rtx = gen_rtx_fmt_ (PC, VOIDmode); + ret_rtx = gen_rtx_fmt_ (RETURN, VOIDmode); + simple_return_rtx = gen_rtx_fmt_ (SIMPLE_RETURN, VOIDmode); + cc0_rtx = gen_rtx_fmt_ (CC0, VOIDmode); } /* Produce exact duplicate of insn INSN after AFTER.