From patchwork Sat Sep 28 10:26:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 278731 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5DE3B2C0092 for ; Sat, 28 Sep 2013 20:26:26 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :content-type:content-transfer-encoding:subject:date:message-id :cc:to:mime-version; q=dns; s=default; b=MnUBsDaarufg9Q4qHBjL6LZ 8EkCgVsI49LbPkfuiv1m4/Aa6tcB+nV3W58E1YjFF7zfgJ+SmOFld0fUGBS1blRY aL9uy3F2T6ByhdiV6ahgHC7myax+hDfZ3mW/+i3giwUmSC96ZZ8gIS+xfA05ROnk sFJW2k3DYjGMqeL75Sxs= 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:from :content-type:content-transfer-encoding:subject:date:message-id :cc:to:mime-version; s=default; bh=6ZBWutICczY+fffsO+6ZqkoTly4=; b= pjn9lZcxSfUH8DH8MJmeLTG71Np2Eitn2HO9UgqoLZoie9rUJCiTKBQk3ykH4BNM IifqZR9J1GbDSpPqwwHtFGZSFv+4c4gvgUW4MPK7ZQ8X7gL0J7pt3wKjAxe2ifml FQh+mIAxKzKwQEM9xVPawqD+8h94ACmlBBIzFFO18gY= Received: (qmail 12786 invoked by alias); 28 Sep 2013 10:26:20 -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 12777 invoked by uid 89); 28 Sep 2013 10:26:20 -0000 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 28 Sep 2013 10:26:20 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, RDNS_NONE, SPF_HELO_FAIL autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VPrj0-0007WQ-SK from Iain_Sandoe@mentor.com ; Sat, 28 Sep 2013 03:26:10 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Sat, 28 Sep 2013 03:26:10 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Sat, 28 Sep 2013 11:26:08 +0100 From: Iain Sandoe Subject: [Patch, Darwin/PPC] fix PR10901 Date: Sat, 28 Sep 2013 11:26:05 +0100 Message-ID: CC: Mike Stump , David Edelsohn To: GCC Patches MIME-Version: 1.0 (Apple Message framework v1283) Hi, this might be the oldest bug i've fixed so far. We currently generate wrong code for non-local gotos which breaks, amongst other things, nested functions. I fixed this a while ago for x86 Darwin and here is a version to fix it on PPC. (the patch is darwin-local save the definitions of the UNSPECs). this has been in my (and Dominique's) ppc tree for some time, OK for trunk? (and open branches?) - long-standing, wrong-code bug. Iain gcc: PR target/10901 * config/darwin-protos.h (machopic_get_function_picbase): New. * config/darwin.c (machopic_get_function_picbase): New. * config/rs6000/darwin.md (load_macho_picbase_si): Update picbase label for a new func. (load_macho_picbase_di): Likewise. (reload_macho_picbase): New expand. (reload_macho_picbase_si): New insn. (reload_macho_picbase_di): New insn. (nonlocal_goto_receiver): New define and split. * config/rs6000/rs6000.md (unspec enum): Add UNSPEC_RELD_MPIC. (unspecv enum): Add UNSPECV_NLGR. diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h index 36d16b9..fe43ef3 100644 --- a/gcc/config/darwin-protos.h +++ b/gcc/config/darwin-protos.h @@ -26,6 +26,7 @@ extern void machopic_output_function_base_name (FILE *); extern const char *machopic_indirection_name (rtx, bool); extern const char *machopic_mcount_stub_name (void); extern bool machopic_should_output_picbase_label (void); +extern const char *machopic_get_function_picbase (void); #ifdef RTX_CODE diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index ab48558..cb1bc38 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -405,6 +405,19 @@ machopic_output_function_base_name (FILE *file) fprintf (file, "L%d$pb", current_pic_label_num); } +char curr_picbasename[32]; + +const char * +machopic_get_function_picbase (void) +{ + /* If dynamic-no-pic is on, we should not get here. */ + gcc_assert (!MACHO_DYNAMIC_NO_PIC_P); + + update_pic_label_number_if_needed (); + snprintf (curr_picbasename, 32, "L%d$pb", current_pic_label_num); + return (const char *) curr_picbasename; +} + bool machopic_should_output_picbase_label (void) { diff --git a/gcc/config/rs6000/darwin.md b/gcc/config/rs6000/darwin.md index 24e8cfa..0fb2422 100644 --- a/gcc/config/rs6000/darwin.md +++ b/gcc/config/rs6000/darwin.md @@ -260,7 +260,10 @@ You should have received a copy of the GNU General Public License (unspec:SI [(match_operand:SI 0 "immediate_operand" "s") (pc)] UNSPEC_LD_MPIC))] "(DEFAULT_ABI == ABI_DARWIN) && flag_pic" - "bcl 20,31,%0\\n%0:" +{ + machopic_should_output_picbase_label (); /* Update for new func. */ + return "bcl 20,31,%0\\n%0:"; +} [(set_attr "type" "branch") (set_attr "length" "4")]) @@ -269,7 +272,10 @@ You should have received a copy of the GNU General Public License (unspec:DI [(match_operand:DI 0 "immediate_operand" "s") (pc)] UNSPEC_LD_MPIC))] "(DEFAULT_ABI == ABI_DARWIN) && flag_pic && TARGET_64BIT" - "bcl 20,31,%0\\n%0:" +{ + machopic_should_output_picbase_label (); /* Update for new func. */ + return "bcl 20,31,%0\\n%0:"; +} [(set_attr "type" "branch") (set_attr "length" "4")]) @@ -370,3 +376,86 @@ You should have received a copy of the GNU General Public License } [(set_attr "type" "branch,branch") (set_attr "length" "4,8")]) + +(define_expand "reload_macho_picbase" + [(set (reg:SI 65) + (unspec [(match_operand 0 "" "")] + UNSPEC_RELD_MPIC))] + "(DEFAULT_ABI == ABI_DARWIN) && flag_pic" +{ + if (TARGET_32BIT) + emit_insn (gen_reload_macho_picbase_si (operands[0])); + else + emit_insn (gen_reload_macho_picbase_di (operands[0])); + + DONE; +}) + +(define_insn "reload_macho_picbase_si" + [(set (reg:SI 65) + (unspec:SI [(match_operand:SI 0 "immediate_operand" "s") + (pc)] UNSPEC_RELD_MPIC))] + "(DEFAULT_ABI == ABI_DARWIN) && flag_pic" +{ + if (machopic_should_output_picbase_label ()) + { + static char tmp[64]; + const char *cnam = machopic_get_function_picbase (); + snprintf (tmp, 64, "bcl 20,31,%s\\n%s:\\n%%0:", cnam, cnam); + return tmp; + } + else + return "bcl 20,31,%0\\n%0:"; +} + [(set_attr "type" "branch") + (set_attr "length" "4")]) + +(define_insn "reload_macho_picbase_di" + [(set (reg:DI 65) + (unspec:DI [(match_operand:DI 0 "immediate_operand" "s") + (pc)] UNSPEC_RELD_MPIC))] + "(DEFAULT_ABI == ABI_DARWIN) && flag_pic && TARGET_64BIT" +{ + if (machopic_should_output_picbase_label ()) + { + static char tmp[64]; + const char *cnam = machopic_get_function_picbase (); + snprintf (tmp, 64, "bcl 20,31,%s\\n%s:\\n%%0:", cnam, cnam); + return tmp; + } + else + return "bcl 20,31,%0\\n%0:"; +} + [(set_attr "type" "branch") + (set_attr "length" "4")]) + +;; We need to restore the PIC register, at the site of nonlocal label. + +(define_insn_and_split "nonlocal_goto_receiver" + [(unspec_volatile [(const_int 0)] UNSPECV_NLGR)] + "TARGET_MACHO && flag_pic" + "#" + "&& reload_completed" + [(const_int 0)] +{ + if (crtl->uses_pic_offset_table) + { + static unsigned n = 0; + rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME); + rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); + rtx tmplrtx; + char tmplab[20]; + + ASM_GENERATE_INTERNAL_LABEL(tmplab, "Lnlgr", ++n); + tmplrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab)); + + emit_insn (gen_reload_macho_picbase (tmplrtx)); + emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO)); + emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplrtx)); + } + else + /* Not using PIC reg, no reload needed. */ + emit_note (NOTE_INSN_DELETED); + + DONE; +})