From patchwork Mon Feb 4 11:14:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1035838 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-495227-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="bAYXepN9"; 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 43tQ8p3k5Zz9s3l for ; Mon, 4 Feb 2019 22:14:50 +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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=e1bF8O6m7f6rGq8h iL3ivahVRMzagWp8vod7qmeTFQU2ip8yEJ0pVVmfSPxa1fWeBV3tiOEy+SsATA+I MPnjc5gslqJQ/ojJU6DneuKsOmrOcDSdG2z2esJgxTApBsrsCjfoC/jpEuGKto00 712lM7IELKqFklpVtAEZmrIy0U4= 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 :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=4bZ/OD1Gg/zQ/JW02iOUwW N5K88=; b=bAYXepN9VAJDk1iOVnFpyKqSiky6BiHQ4zYG33jbZoc2m6ilh9uaWi 0UT1eXLQXDaafbexfzYYXETiwgONRdC3OXOTgXYygC2LXMW947LI74YzGyGl1yei 5dzEMVWwyhgCcr4afcMTMF2iKGgc30CuuGyLYuPcwbaGa0gceOCGI= Received: (qmail 2714 invoked by alias); 4 Feb 2019 11:14:43 -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 2693 invoked by uid 89); 4 Feb 2019 11:14:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=broke, Table X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Feb 2019 11:14:35 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 1C5B581368 for ; Mon, 4 Feb 2019 12:14:32 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0LMgQTXNLQA7 for ; Mon, 4 Feb 2019 12:14:32 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id E4F4981339 for ; Mon, 4 Feb 2019 12:14:31 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [SPARC] Fix fallout of PR target/83368 Date: Mon, 04 Feb 2019 12:14:29 +0100 Message-ID: <6200077.SEmg0Osn0Z@polaris> MIME-Version: 1.0 The patch for PR target/83368 changed the PIC register from a hard register to a pseudo and broke the -mflat mode in the process. The attached patch fixes it and does also a bit of housekeeping in the GOT support. Tested on SPARC/Solaris 11, applied on the mainline and 8 branch. 2019-02-04 Eric Botcazou * config/sparc/sparc.h: Remove superfluous blank lines. * config/sparc/sparc.c (global_offset_table_rtx): Rename into... (got_register_rtx): ...this. (sparc_got): Adjust to above renaming. (sparc_tls_got): Likewise. (sparc_delegitimize_address): Likewise. (sparc_output_mi_thunk): Likewise. (sparc_init_pic_reg): Likewise. (save_local_or_in_reg_p): Fix test on the GOT register. (USE_HIDDEN_LINKONCE): Move around. (get_pc_thunk_name): Likewise. (gen_load_pcrel_sym): Likewise. (load_got_register): Likewise. Index: config/sparc/sparc.c =================================================================== --- config/sparc/sparc.c (revision 268508) +++ config/sparc/sparc.c (working copy) @@ -4269,19 +4269,84 @@ sparc_cannot_force_const_mem (machine_mo /* Global Offset Table support. */ static GTY(()) rtx got_helper_rtx = NULL_RTX; -static GTY(()) rtx global_offset_table_rtx = NULL_RTX; +static GTY(()) rtx got_register_rtx = NULL_RTX; +static GTY(()) rtx got_symbol_rtx = NULL_RTX; /* Return the SYMBOL_REF for the Global Offset Table. */ -static GTY(()) rtx sparc_got_symbol = NULL_RTX; - static rtx sparc_got (void) { - if (!sparc_got_symbol) - sparc_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); + if (!got_symbol_rtx) + got_symbol_rtx = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); + + return got_symbol_rtx; +} + +#ifdef HAVE_GAS_HIDDEN +# define USE_HIDDEN_LINKONCE 1 +#else +# define USE_HIDDEN_LINKONCE 0 +#endif + +static void +get_pc_thunk_name (char name[32], unsigned int regno) +{ + const char *reg_name = reg_names[regno]; + + /* Skip the leading '%' as that cannot be used in a + symbol name. */ + reg_name += 1; + + if (USE_HIDDEN_LINKONCE) + sprintf (name, "__sparc_get_pc_thunk.%s", reg_name); + else + ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC", regno); +} + +/* Wrapper around the load_pcrel_sym{si,di} patterns. */ + +static rtx +gen_load_pcrel_sym (rtx op0, rtx op1, rtx op2) +{ + int orig_flag_pic = flag_pic; + rtx insn; + + /* The load_pcrel_sym{si,di} patterns require absolute addressing. */ + flag_pic = 0; + if (TARGET_ARCH64) + insn = gen_load_pcrel_symdi (op0, op1, op2, GEN_INT (REGNO (op0))); + else + insn = gen_load_pcrel_symsi (op0, op1, op2, GEN_INT (REGNO (op0))); + flag_pic = orig_flag_pic; + + return insn; +} + +/* Emit code to load the GOT register. */ + +void +load_got_register (void) +{ + if (!got_register_rtx) + got_register_rtx = gen_rtx_REG (Pmode, GLOBAL_OFFSET_TABLE_REGNUM); + + if (TARGET_VXWORKS_RTP) + emit_insn (gen_vxworks_load_got ()); + else + { + /* The GOT symbol is subject to a PC-relative relocation so we need a + helper function to add the PC value and thus get the final value. */ + if (!got_helper_rtx) + { + char name[32]; + get_pc_thunk_name (name, GLOBAL_OFFSET_TABLE_REGNUM); + got_helper_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name)); + } - return sparc_got_symbol; + emit_insn (gen_load_pcrel_sym (got_register_rtx, sparc_got (), + got_helper_rtx)); + } } /* Ensure that we are not using patterns that are not OK with PIC. */ @@ -4607,7 +4672,7 @@ sparc_tls_got (void) if (TARGET_SUN_TLS && TARGET_ARCH32) { load_got_register (); - return global_offset_table_rtx; + return got_register_rtx; } /* In all other cases, we load a new pseudo with the GOT symbol. */ @@ -4995,7 +5060,7 @@ sparc_delegitimize_address (rtx x) /* This is generated by mov{si,di}_pic_label_ref in PIC mode. */ if (GET_CODE (x) == MINUS - && (XEXP (x, 0) == global_offset_table_rtx + && (XEXP (x, 0) == got_register_rtx || sparc_pic_register_p (XEXP (x, 0)))) { rtx y = XEXP (x, 1); @@ -5092,72 +5157,6 @@ sparc_mode_dependent_address_p (const_rt return false; } -#ifdef HAVE_GAS_HIDDEN -# define USE_HIDDEN_LINKONCE 1 -#else -# define USE_HIDDEN_LINKONCE 0 -#endif - -static void -get_pc_thunk_name (char name[32], unsigned int regno) -{ - const char *reg_name = reg_names[regno]; - - /* Skip the leading '%' as that cannot be used in a - symbol name. */ - reg_name += 1; - - if (USE_HIDDEN_LINKONCE) - sprintf (name, "__sparc_get_pc_thunk.%s", reg_name); - else - ASM_GENERATE_INTERNAL_LABEL (name, "LADDPC", regno); -} - -/* Wrapper around the load_pcrel_sym{si,di} patterns. */ - -static rtx -gen_load_pcrel_sym (rtx op0, rtx op1, rtx op2) -{ - int orig_flag_pic = flag_pic; - rtx insn; - - /* The load_pcrel_sym{si,di} patterns require absolute addressing. */ - flag_pic = 0; - if (TARGET_ARCH64) - insn = gen_load_pcrel_symdi (op0, op1, op2, GEN_INT (REGNO (op0))); - else - insn = gen_load_pcrel_symsi (op0, op1, op2, GEN_INT (REGNO (op0))); - flag_pic = orig_flag_pic; - - return insn; -} - -/* Emit code to load the GOT register. */ - -void -load_got_register (void) -{ - if (!global_offset_table_rtx) - global_offset_table_rtx = gen_rtx_REG (Pmode, GLOBAL_OFFSET_TABLE_REGNUM); - - if (TARGET_VXWORKS_RTP) - emit_insn (gen_vxworks_load_got ()); - else - { - /* The GOT symbol is subject to a PC-relative relocation so we need a - helper function to add the PC value and thus get the final value. */ - if (!got_helper_rtx) - { - char name[32]; - get_pc_thunk_name (name, GLOBAL_OFFSET_TABLE_REGNUM); - got_helper_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name)); - } - - emit_insn (gen_load_pcrel_sym (global_offset_table_rtx, sparc_got (), - got_helper_rtx)); - } -} - /* Emit a call instruction with the pattern given by PAT. ADDR is the address of the call target. */ @@ -5512,7 +5511,7 @@ save_local_or_in_reg_p (unsigned int reg return true; /* GOT register (%l7) if needed. */ - if (regno == PIC_OFFSET_TABLE_REGNUM && crtl->uses_pic_offset_table) + if (regno == GLOBAL_OFFSET_TABLE_REGNUM && got_register_rtx) return true; /* If the function accesses prior frames, the frame pointer and the return @@ -12441,7 +12440,7 @@ sparc_output_mi_thunk (FILE *file, tree start_sequence (); load_got_register (); /* clobbers %o7 */ if (!TARGET_VXWORKS_RTP) - pic_offset_table_rtx = global_offset_table_rtx; + pic_offset_table_rtx = got_register_rtx; scratch = sparc_legitimize_pic_address (funexp, scratch); seq = get_insns (); end_sequence (); @@ -13117,7 +13116,7 @@ sparc_init_pic_reg (void) start_sequence (); load_got_register (); if (!TARGET_VXWORKS_RTP) - emit_move_insn (pic_offset_table_rtx, global_offset_table_rtx); + emit_move_insn (pic_offset_table_rtx, got_register_rtx); seq = get_insns (); end_sequence (); Index: config/sparc/sparc.h =================================================================== --- config/sparc/sparc.h (revision 268508) +++ config/sparc/sparc.h (working copy) @@ -804,7 +804,6 @@ extern enum cmodel sparc_cmodel; #define STATIC_CHAIN_REGNUM (TARGET_ARCH64 ? 5 : 2) /* Register which holds the global offset table, if any. */ - #define GLOBAL_OFFSET_TABLE_REGNUM 23 /* Register which holds offset table for position-independent data references. @@ -812,7 +811,6 @@ extern enum cmodel sparc_cmodel; so we use a pseudo-register to make sure it is properly saved and restored around calls to setjmp. Now the ABI of VxWorks RTP makes it live on entry to PLT entries so we use the canonical GOT register in this case. */ - #define PIC_OFFSET_TABLE_REGNUM \ (TARGET_VXWORKS_RTP && flag_pic ? GLOBAL_OFFSET_TABLE_REGNUM : INVALID_REGNUM) @@ -822,7 +820,6 @@ extern enum cmodel sparc_cmodel; Originally it was -1, but later on the container of options changed to unsigned byte, so we decided to pick 127 as default value, which does reflect an undefined default value in case of 0/1. */ - #define DEFAULT_PCC_STRUCT_RETURN 127 /* Functions which return large structures get the address