From patchwork Mon Aug 24 23:26:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaz Kojima X-Patchwork-Id: 510334 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 613BD140271 for ; Tue, 25 Aug 2015 09:26:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=A8ZsHrZO; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:to:subject:from:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=jPKwYOXewpOTrrfX NKSXmgZRSU4foUTjtZd6U0n8oIS2Ez35e+5PnVCsqH0N2viHMY4ePyNm7HUq5L1W JkdH8uQXHnxoRu0BPohHxVNjDdv81vN/oj5uwuXVt1+V1GZgRIDkTuhC6liPimVX IHxvLMUAipMyOX8UzA4xqQwYtK4= 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 :message-id:to:subject:from:mime-version:content-type :content-transfer-encoding; s=default; bh=ThWVLp1uaAMbkDDQOpzGYO gYpwk=; b=A8ZsHrZOOU+qYFbCJgkEvYrv06ff0B0gcVhkD3X+ycRtNLMeiTPwGF 9tUyGVexs7VYG5O/WLqqz5ikmDxk1xSVFXpHpEvTosHpfQirrtEIIIQf+LYo5AhK qef+PgW44yR1kAmWU+TYfuLFriDB7V9XN/3mngggph2aTS60/TX6k= Received: (qmail 18717 invoked by alias); 24 Aug 2015 23:26:11 -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 18707 invoked by uid 89); 24 Aug 2015 23:26:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mo-sw.iij4u.or.jp Received: from mo-sw1501.iij4u.or.jp (HELO mo-sw.iij4u.or.jp) (210.130.239.241) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 24 Aug 2015 23:26:09 +0000 Received: by mo-sw.iij4u.or.jp (4u-mo-sw1501) id t7ONQ5Tt028755; Tue, 25 Aug 2015 08:26:06 +0900 Received: from localhost (24.26.30.125.dy.iij4u.or.jp [125.30.26.24]) by mbox.iij4u.or.jp (4u-mbox1501) id t7ONQ0Yj024557; Tue, 25 Aug 2015 08:26:05 +0900 Date: Tue, 25 Aug 2015 08:26:00 +0900 (JST) Message-Id: <20150825.082600.240826486.kkojima@rr.iij4u.or.jp> To: gcc-patches@gcc.gnu.org Subject: [patch commit SH] Fix PR target/66609 From: Kaz Kojima Mime-Version: 1.0 X-IsSubscribed: yes I've commit the attached patch to fix PR target/66609. SH doesn't take into account weak symbol references for the pc relative calls and sibcalls. See PR target/66609 for details. The patch introduces a new unspec enum UNSPEC_PCREL so to generate pc relative symbols like foo@PCREL and use them for pc relative sibcall jump targets if needed. It's tested on sh4-unknown-linux-gnu with no new failures. Regards, kaz --- 2015-08-24 Kaz Kojima PR target/66609 * config/sh/sh.c (sh_asm_output_addr_const_extra): Handle UNSPEC_PCREL. (nonpic_symbol_mentioned_p): Likewise. (sh_delegitimize_address): Likewise. (sh_function_ok_for_sibcall): Take into account weak symbols. (sh_expand_sym_label2reg): New. * config/sh/sh-protos.h (sh_expand_sym_label2reg): Declare. * config/sh/sh.md (UNSPEC_PCREL): New enum. (call_pcrel): Use sh_expand_sym_label2reg. (call_value_pcrel, sibcall_pcrel, sibcall_value_pcrel): Likewise. (symPCREL_label2reg) New expand. diff --git a/config/sh/sh-protos.h b/config/sh/sh-protos.h index 5a552e2..3e4211b 100644 --- a/config/sh/sh-protos.h +++ b/config/sh/sh-protos.h @@ -159,6 +159,7 @@ extern int sh_eval_treg_value (rtx op); extern HOST_WIDE_INT sh_disp_addr_displacement (rtx mem_op); extern int sh_max_mov_insn_displacement (machine_mode mode, bool consider_sh2a); extern bool sh_movsf_ie_ra_split_p (rtx, rtx, rtx); +extern void sh_expand_sym_label2reg (rtx, rtx, rtx, bool); /* Result value of sh_find_set_of_reg. */ struct set_of_reg diff --git a/config/sh/sh.c b/config/sh/sh.c index 450d634..db4153b 100644 --- a/config/sh/sh.c +++ b/config/sh/sh.c @@ -1604,6 +1604,10 @@ sh_asm_output_addr_const_extra (FILE *file, rtx x) output_addr_const (file, XVECEXP (x, 0, 0)); fputs ("@GOTPLT", file); break; + case UNSPEC_PCREL: + output_addr_const (file, XVECEXP (x, 0, 0)); + fputs ("@PCREL", file); + break; case UNSPEC_DTPOFF: output_addr_const (file, XVECEXP (x, 0, 0)); fputs ("@DTPOFF", file); @@ -10441,6 +10445,7 @@ nonpic_symbol_mentioned_p (rtx x) || XINT (x, 1) == UNSPEC_DTPOFF || XINT (x, 1) == UNSPEC_TPOFF || XINT (x, 1) == UNSPEC_PLT + || XINT (x, 1) == UNSPEC_PCREL || XINT (x, 1) == UNSPEC_SYMOFF || XINT (x, 1) == UNSPEC_PCREL_SYMOFF)) return false; @@ -10714,7 +10719,8 @@ sh_delegitimize_address (rtx orig_x) rtx symplt = XEXP (XVECEXP (y, 0, 0), 0); if (GET_CODE (symplt) == UNSPEC - && XINT (symplt, 1) == UNSPEC_PLT) + && (XINT (symplt, 1) == UNSPEC_PLT + || XINT (symplt, 1) == UNSPEC_PCREL)) return XVECEXP (symplt, 0, 0); } } @@ -11702,9 +11708,24 @@ sh_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) || crtl->args.info.stack_regs == 0) && ! sh_cfun_interrupt_handler_p () && (! flag_pic - || (decl && ! TREE_PUBLIC (decl)) + || (decl && ! (TREE_PUBLIC (decl) || DECL_WEAK (decl))) || (decl && DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT))); } + +/* Expand to appropriate sym*_label2reg for SYM and SIBCALL_P. */ +void +sh_expand_sym_label2reg (rtx reg, rtx sym, rtx lab, bool sibcall_p) +{ + const_tree decl = SYMBOL_REF_DECL (sym); + bool is_weak = (decl && DECL_P (decl) && DECL_WEAK (decl)); + + if (!is_weak && SYMBOL_REF_LOCAL_P (sym)) + emit_insn (gen_sym_label2reg (reg, sym, lab)); + else if (sibcall_p) + emit_insn (gen_symPCREL_label2reg (reg, sym, lab)); + else + emit_insn (gen_symPLT_label2reg (reg, sym, lab)); +} /* Machine specific built-in functions. */ diff --git a/config/sh/sh.md b/config/sh/sh.md index ad49f72..7e6070f 100644 --- a/config/sh/sh.md +++ b/config/sh/sh.md @@ -135,6 +135,7 @@ UNSPEC_PLT UNSPEC_CALLER UNSPEC_GOTPLT + UNSPEC_PCREL UNSPEC_ICACHE UNSPEC_INIT_TRAMP UNSPEC_FCOSA @@ -9470,11 +9471,8 @@ label: [(const_int 0)] { rtx lab = PATTERN (gen_call_site ()); - - if (SYMBOL_REF_LOCAL_P (operands[0])) - emit_insn (gen_sym_label2reg (operands[2], operands[0], lab)); - else - emit_insn (gen_symPLT_label2reg (operands[2], operands[0], lab)); + + sh_expand_sym_label2reg (operands[2], operands[0], lab, false); emit_call_insn (gen_calli_pcrel (operands[2], operands[1], copy_rtx (lab))); DONE; } @@ -9605,10 +9603,7 @@ label: { rtx lab = PATTERN (gen_call_site ()); - if (SYMBOL_REF_LOCAL_P (operands[1])) - emit_insn (gen_sym_label2reg (operands[3], operands[1], lab)); - else - emit_insn (gen_symPLT_label2reg (operands[3], operands[1], lab)); + sh_expand_sym_label2reg (operands[3], operands[1], lab, false); emit_call_insn (gen_call_valuei_pcrel (operands[0], operands[3], operands[2], copy_rtx (lab))); DONE; @@ -10008,7 +10003,7 @@ label: rtx lab = PATTERN (gen_call_site ()); rtx call_insn; - emit_insn (gen_sym_label2reg (operands[2], operands[0], lab)); + sh_expand_sym_label2reg (operands[2], operands[0], lab, true); call_insn = emit_call_insn (gen_sibcalli_pcrel (operands[2], operands[1], copy_rtx (lab))); SIBLING_CALL_P (call_insn) = 1; @@ -10200,7 +10195,7 @@ label: rtx lab = PATTERN (gen_call_site ()); rtx call_insn; - emit_insn (gen_sym_label2reg (operands[3], operands[1], lab)); + sh_expand_sym_label2reg (operands[3], operands[1], lab, true); call_insn = emit_call_insn (gen_sibcall_valuei_pcrel (operands[0], operands[3], operands[2], @@ -10748,6 +10743,16 @@ label: UNSPEC_SYMOFF)))] "TARGET_SH1" "") +(define_expand "symPCREL_label2reg" + [(set (match_operand:SI 0 "" "") + (const:SI + (unspec:SI + [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PCREL)) + (const:SI (plus:SI (match_operand:SI 2 "" "") + (const_int 2)))] UNSPEC_PCREL_SYMOFF)))] + "TARGET_SH1" + "") + (define_expand "symGOT_load" [(set (match_dup 2) (match_operand 1 "" "")) (set (match_dup 3) (plus (match_dup 2) (reg PIC_REG)))