From patchwork Wed Nov 7 05:40:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 994107 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-489206-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="uZIgAKHK"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Aq6jou9w"; 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 42qZyk56mQz9sCX for ; Wed, 7 Nov 2018 16:41:02 +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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=V1rXf5o6P7UbgBQ5c qsycVz1wOM0jIhAeD1+bSKkVP2/TwlQ79xHZc2iyZ+Ro8sPN5T5PCJnVy+UukP4X HIDVqHXuPfGrVq9hzLKIda8KG+CcPgN51y3bb22IV2t0JcLdn4GkPIWu53GmMA8U CjHfPy8WF9NtEhf1W6VvOFOHuo= 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:references:mime-version :content-type:in-reply-to; s=default; bh=jHQHlzq7KSf4+Tu4dXR0Q91 uKTE=; b=uZIgAKHK/Q2e0rA/5BbOy0jmZxGQVcRcghyQMxtmR/pdyLSbpFg/Ajj V2OoLt85dYlznz6ejQneIKAR13vId7KisB28f0MrPsP9psNA7CI5w8lwsJSL563/ qfgh55mz2B9WTFx/L7FwZdF4nhTlmtbfR1/6PHMpeWrU50hgKYpE= Received: (qmail 82556 invoked by alias); 7 Nov 2018 05:40:53 -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 82535 invoked by uid 89); 7 Nov 2018 05:40:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=holding, cum, WHICH X-HELO: mail-pg1-f172.google.com Received: from mail-pg1-f172.google.com (HELO mail-pg1-f172.google.com) (209.85.215.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Nov 2018 05:40:47 +0000 Received: by mail-pg1-f172.google.com with SMTP id z10so4997718pgp.7 for ; Tue, 06 Nov 2018 21:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mn/sTHGUI5cStD2ihbwWFPIHlMiuIQzFQ9MoHKpp6i4=; b=Aq6jou9wGReikrJ7qc1Kkvq+32lcO15EPlmtDQIrV+SU7I4XakekHH20kX1rdzD+Pp 3W3KmywZjHuesAV8R0ODlLK+phn3PkvlhQ9eJDwICYXRMBKWrjxdAE8M0GX9gB7cewN8 q/Yg+O2/5hAgJi8KPzJtGkQ2XAS4KpXWpRKijg9xsp74q2yWB4Nv+gHkefNiIdTzoQX/ GochtRR3QMHT8OLAmoz6ZGbN+nuPfD/tdknC0oMcVZVf/NlCt1v3Zq9bw+6t2DrG+7Yk 44oZW+1PMkUU7geXAKcmC0M1IYR5b8pTfa8F6GE86S34Ka9OvEQWM5cssyBMurs9SAS4 v1oA== Received: from bubble.grove.modra.org ([58.175.241.133]) by smtp.gmail.com with ESMTPSA id e2-v6sm49827144pgv.25.2018.11.06.21.40.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 21:40:43 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 0074F8033C; Wed, 7 Nov 2018 16:10:39 +1030 (ACDT) Date: Wed, 7 Nov 2018 16:10:39 +1030 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 6/6] [RS6000] inline plt call sequences Message-ID: <20181107054039.GS29482@bubble.grove.modra.org> References: <20181107053326.GM29482@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181107053326.GM29482@bubble.grove.modra.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-IsSubscribed: yes Finally, the point of the previous patches in this series, support for inline PLT calls, keyed off -fno-plt. This emits code using new relocations that tie all insns in the sequence together, so that the linker can edit the sequence back to a direct call should the call target turn out to be local. An example of ELFv2 code to call puts is as follows: .reloc .,R_PPC64_PLTSEQ,puts std 2,24(1) .reloc .,R_PPC64_PLT16_HA,puts addis 12,2,0 .reloc .,R_PPC64_PLT16_LO_DS,puts ld 12,0(12) .reloc .,R_PPC64_PLTSEQ,puts mtctr 12 .reloc .,R_PPC64_PLTCALL,puts bctrl ld 2,24(1) "addis 12,2,puts@plt@ha" and "ld 12,puts@plt@l(12)" are also supported by the assembler. gcc instead uses the explicit R_PPC64_PLT16_HA and R_PPC64_PLT16_LO_DS relocs because when the call is to __tls_get_addr an extra reloc is emitted at every place where one is shown above, to specify the __tls_get_addr arg. The linker expects the extra reloc to come first. .reloc enforces that ordering. The patch also changes code emitted for longcalls if the assembler supports the new marker relocs, so that these too can be edited. One side effect of longcalls using PLT16 relocs is that they can now be resolved lazily by ld.so. I don't support lazy inline PLT calls for ELFv1, because ELFv1 would need barriers to reliably load both the function address and toc pointer from the PLT. ELFv1 -fno-plt uses the longcall sequence instead, which isn't edited by GNU ld. * config.in (HAVE_AS_PLTSEQ): Add. * config/rs6000/predicates.md (indirect_call_operand): New. * config/rs6000/rs6000-protos.h (rs6000_output_pltseq): Declare. * config/rs6000/rs6000.c (init_cumulative_args): Set cookie CALL_LONG for -fno-plt. (print_operand ): Handle UNSPEC_PLTSEQ. (rs6000_output_indirect_call): Emit .reloc directives for UNSPEC_PLTSEQ calls. (rs6000_output_pltseq): New function. (rs6000_longcall_ref): Add arg parameter. Use PLT16 insns if relocs supported by assembler. Move SYMBOL_REF test to callers. (rs6000_call_aix): Adjust rs6000_longcall_ref call. Package insns in UNSPEC_PLTSEQ, preserving original func_desc. (rs6000_call_sysv): Likewise. (rs6000_sibcall_sysv): New function. * config/rs6000/rs6000-protos.h (rs6000_sibcall_sysv): Declare. * config/rs6000/rs6000.h (HAVE_AS_PLTSEQ): Provide default. * config/rs6000/rs6000.md (UNSPEC_PLTSEQ, UNSPEC_PLT16_HA, UNSPEC_PLT16_LO): New. (pltseq_tocsave, pltseq_plt16_ha, pltseq_plt16_lo, pltseq_mtctr): New. (call_indirect_nonlocal_sysv): Don't differentiate zero from non-zero cookie in constraints. Test explicitly for flags in length attr. Handle unspec operand 1. (call_value_indirect_nonlocal_sysv): Likewise. (call_indirect_aix, call_value_indirect_aix): Handle unspec operand 1. (call_indirect_elfv2, call_value_indirect_elfv2): Likewise. (sibcall, sibcall_value): Use rs6000_sibcall_sysv. (sibcall_indirect_nonlocal_sysv): New pattern. (sibcall_value_indirect_nonlocal_sysv): Likewise. (sibcall_nonlocal_sysv, sibcall_value_nonlocal_sysv): Remove indirect call alternatives. * configure.ac: Check for gas plt sequence marker support. * configure: Regenerate. diff --git a/gcc/config.in b/gcc/config.in index 67a1e6cfc4c..86ff5e8636b 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -577,6 +577,12 @@ #endif +/* Define if your assembler supports R_PPC*_PLTSEQ relocations. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_PLTSEQ +#endif + + /* Define if your assembler supports .ref */ #ifndef USED_FOR_TARGET #undef HAVE_AS_REF diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index 8f13c1457e4..805d92ea1f1 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -1055,6 +1055,24 @@ (define_predicate "call_operand" || REGNO (op) >= FIRST_PSEUDO_REGISTER") (match_code "symbol_ref"))) +;; Return 1 if the operand, used inside a MEM, is a valid first argument +;; to an indirect CALL. This is LR, CTR, or a PLTSEQ unspec using CTR. +(define_predicate "indirect_call_operand" + (match_code "reg,unspec") +{ + if (REG_P (op)) + return (REGNO (op) == LR_REGNO + || REGNO (op) == CTR_REGNO); + if (GET_CODE (op) == UNSPEC) + { + if (XINT (op, 1) != UNSPEC_PLTSEQ) + return false; + op = XVECEXP (op, 0, 0); + return REG_P (op) && REGNO (op) == CTR_REGNO; + } + return false; +}) + ;; Return 1 if the operand is a SYMBOL_REF for a function known to be in ;; this file. (define_predicate "current_file_function_operand" diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h index 9e84c692a9b..27a161983da 100644 --- a/gcc/config/rs6000/rs6000-protos.h +++ b/gcc/config/rs6000/rs6000-protos.h @@ -113,6 +113,7 @@ extern void print_operand (FILE *, rtx, int); extern void print_operand_address (FILE *, rtx); extern const char *rs6000_output_call (rtx *, unsigned int, bool); extern const char *rs6000_output_indirect_call (rtx *, unsigned int, bool); +extern const char *rs6000_output_pltseq (rtx *, int); extern enum rtx_code rs6000_reverse_condition (machine_mode, enum rtx_code); extern rtx rs6000_emit_eqne (machine_mode, rtx, rtx, rtx); @@ -202,6 +203,7 @@ extern void rs6000_emit_eh_reg_restore (rtx, rtx); extern void rs6000_call_aix (rtx, rtx, rtx, rtx); extern void rs6000_sibcall_aix (rtx, rtx, rtx, rtx); extern void rs6000_call_sysv (rtx, rtx, rtx, rtx); +extern void rs6000_sibcall_sysv (rtx, rtx, rtx, rtx); extern void rs6000_aix_asm_output_dwarf_table_ref (char *); extern void get_ppc476_thunk_name (char name[32]); extern bool rs6000_overloaded_builtin_p (enum rs6000_builtins); diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 36e59692793..d90d9823943 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -10706,7 +10706,7 @@ void init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, rtx libname ATTRIBUTE_UNUSED, int incoming, int libcall, int n_named_args, - tree fndecl ATTRIBUTE_UNUSED, + tree fndecl, machine_mode return_mode ATTRIBUTE_UNUSED) { static CUMULATIVE_ARGS zero_cumulative; @@ -10727,10 +10727,20 @@ init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, cum->nargs_prototype = n_named_args; /* Check for a longcall attribute. */ - if ((!fntype && rs6000_default_long_calls) - || (fntype - && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)) - && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))) + if (((!fntype && rs6000_default_long_calls) + || (fntype + && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)) + && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))) + || (DEFAULT_ABI != ABI_DARWIN + && !(fndecl + && !DECL_EXTERNAL (fndecl) + && !DECL_WEAK (fndecl) + && (*targetm.binds_local_p) (fndecl)) + && (flag_plt + ? (fntype + && lookup_attribute ("noplt", TYPE_ATTRIBUTES (fntype))) + : !(fntype + && lookup_attribute ("plt", TYPE_ATTRIBUTES (fntype)))))) cum->call_cookie |= CALL_LONG; if (TARGET_DEBUG_ARG) @@ -20963,6 +20973,8 @@ print_operand (FILE *file, rtx x, int code) case 'T': /* Print the symbolic name of a branch target register. */ + if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PLTSEQ) + x = XVECEXP (x, 0, 0); if (GET_CODE (x) != REG || (REGNO (x) != LR_REGNO && REGNO (x) != CTR_REGNO)) output_operand_lossage ("invalid %%T value"); @@ -21106,6 +21118,8 @@ print_operand (FILE *file, rtx x, int code) return; case 'z': + if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PLTSEQ) + x = XVECEXP (x, 0, 1); /* X is a SYMBOL_REF. Write out the name preceded by a period and without any trailing data in brackets. Used for function names. If we are configured for System V (or the embedded ABI) on @@ -21221,6 +21235,8 @@ print_operand (FILE *file, rtx x, int code) output_addr_const (file, CONST_CAST_RTX (tocrel_base_oac)); else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSGD) output_addr_const (file, XVECEXP (x, 0, 0)); + else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_PLTSEQ) + output_addr_const (file, XVECEXP (x, 0, 1)); else output_addr_const (file, x); return; @@ -21457,60 +21473,158 @@ rs6000_output_indirect_call (rtx *operands, unsigned int fun, bool sibcall) might produce 10 digits. FUN is 0 or 1 as of 2018-03. */ gcc_assert (fun <= 6); - static char str[144]; + static char str[144]; /* 1 spare */ + char *s = str; const char *ptrload = TARGET_64BIT ? "d" : "wz"; + if (DEFAULT_ABI == ABI_AIX) + s += sprintf (s, + "l%s 2,%%%u\n\t", + ptrload, fun + 2); + bool speculate = (rs6000_speculate_indirect_jumps || (REG_P (operands[fun]) && REGNO (operands[fun]) == LR_REGNO)); + if (HAVE_AS_PLTSEQ && GET_CODE (operands[fun]) == UNSPEC) + { + const char *rel64 = TARGET_64BIT ? "64" : ""; + char tls[28]; + tls[0] = 0; + if (GET_CODE (operands[fun + 1]) == UNSPEC) + { + if (XINT (operands[fun + 1], 1) == UNSPEC_TLSGD) + sprintf (tls, ".reloc .,R_PPC%s_TLSGD,%%%u\n\t", + rel64, fun + 1); + else if (XINT (operands[fun + 1], 1) == UNSPEC_TLSLD) + sprintf (tls, ".reloc .,R_PPC%s_TLSLD,%%&\n\t", + rel64); + else + gcc_unreachable (); + } + + const char *addend = (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT + && flag_pic == 2 ? "+32768" : ""); + if (!speculate) + { + s += sprintf (s, + "%s.reloc .,R_PPC%s_PLTSEQ,%%z%u%s\n\t", + tls, rel64, fun, addend); + s += sprintf (s, "crset 2\n\t"); + } + s += sprintf (s, + "%s.reloc .,R_PPC%s_PLTCALL,%%z%u%s\n\t", + tls, rel64, fun, addend); + } + else if (!speculate) + s += sprintf (s, "crset 2\n\t"); + if (DEFAULT_ABI == ABI_AIX) { if (speculate) - sprintf (str, - "l%s 2,%%%u\n\t" + sprintf (s, "b%%T%ul\n\t" "l%s 2,%%%u(1)", - ptrload, fun + 2, fun, ptrload, fun + 3); + fun, ptrload, fun + 3); else - sprintf (str, - "crset 2\n\t" - "l%s 2,%%%u\n\t" + sprintf (s, "beq%%T%ul-\n\t" "l%s 2,%%%u(1)", - ptrload, fun + 2, fun, ptrload, fun + 3); + fun, ptrload, fun + 3); } else if (DEFAULT_ABI == ABI_ELFv2) { if (speculate) - sprintf (str, + sprintf (s, "b%%T%ul\n\t" "l%s 2,%%%u(1)", fun, ptrload, fun + 2); else - sprintf (str, - "crset 2\n\t" + sprintf (s, "beq%%T%ul-\n\t" "l%s 2,%%%u(1)", fun, ptrload, fun + 2); } - else if (DEFAULT_ABI == ABI_V4) + else { if (speculate) - sprintf (str, + sprintf (s, "b%%T%u%s", fun, "l" + sibcall); else - sprintf (str, - "crset 2\n\t" + sprintf (s, "beq%%T%u%s-%s", fun, "l" + sibcall, sibcall ? "\n\tb $" : ""); } - else - gcc_unreachable (); return str; } +#if HAVE_AS_PLTSEQ +/* Output indirect call insns. + WHICH is 0 for tocsave, 1 for plt16_ha, 2 for plt16_lo, 3 for mtctr. */ +const char * +rs6000_output_pltseq (rtx *operands, int which) +{ + const char *rel64 = TARGET_64BIT ? "64" : ""; + char tls[28]; + tls[0] = 0; + if (GET_CODE (operands[3]) == UNSPEC) + { + if (XINT (operands[3], 1) == UNSPEC_TLSGD) + sprintf (tls, ".reloc .,R_PPC%s_TLSGD,%%3\n\t", + rel64); + else if (XINT (operands[3], 1) == UNSPEC_TLSLD) + sprintf (tls, ".reloc .,R_PPC%s_TLSLD,%%&\n\t", + rel64); + else + gcc_unreachable (); + } + + gcc_assert (DEFAULT_ABI == ABI_ELFv2 || DEFAULT_ABI == ABI_V4); + static char str[96]; /* 15 spare */ + const char *off = WORDS_BIG_ENDIAN ? "+2" : ""; + const char *addend = (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT + && flag_pic == 2 ? "+32768" : ""); + switch (which) + { + case 0: + sprintf (str, + "%s.reloc .,R_PPC%s_PLTSEQ,%%z2\n\t" + "st%s", + tls, rel64, TARGET_64BIT ? "d 2,24(1)" : "w 2,12(1)"); + break; + case 1: + if (DEFAULT_ABI == ABI_V4 && !flag_pic) + sprintf (str, + "%s.reloc .%s,R_PPC%s_PLT16_HA,%%z2\n\t" + "lis %%0,0", + tls, off, rel64); + else + sprintf (str, + "%s.reloc .%s,R_PPC%s_PLT16_HA,%%z2%s\n\t" + "addis %%0,%%1,0", + tls, off, rel64, addend); + break; + case 2: + sprintf (str, + "%s.reloc .%s,R_PPC%s_PLT16_LO%s,%%z2%s\n\t" + "l%s %%0,0(%%1)", + tls, off, rel64, TARGET_64BIT ? "_DS" : "", addend, + TARGET_64BIT ? "d" : "wz"); + break; + case 3: + sprintf (str, + "%s.reloc .,R_PPC%s_PLTSEQ,%%z2%s\n\t" + "mtctr %%1", + tls, rel64, addend); + break; + default: + gcc_unreachable (); + } + return str; +} +#endif + #if defined (HAVE_GAS_HIDDEN) && !TARGET_MACHO /* Emit an assembler directive to set symbol visibility for DECL to VISIBILITY_TYPE. */ @@ -32522,11 +32636,8 @@ rs6000_set_default_type_attributes (tree type) longcall attribute. */ static rtx -rs6000_longcall_ref (rtx call_ref) +rs6000_longcall_ref (rtx call_ref, rtx arg) { - if (GET_CODE (call_ref) != SYMBOL_REF) - return call_ref; - /* System V adds '.' to the internal name, so skip them. */ const char *call_name = XSTR (call_ref, 0); if (*call_name == '.') @@ -32538,6 +32649,36 @@ rs6000_longcall_ref (rtx call_ref) call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); } + if (HAVE_AS_PLTSEQ + && TARGET_TLS_MARKERS + && (DEFAULT_ABI == ABI_ELFv2 || DEFAULT_ABI == ABI_V4)) + { + rtx base = const0_rtx; + int regno; + if (DEFAULT_ABI == ABI_ELFv2) + { + base = gen_rtx_REG (Pmode, TOC_REGISTER); + regno = 12; + } + else + { + if (flag_pic) + base = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); + regno = 11; + } + /* Reg must match that used by linker PLT stubs. For ELFv2, r12 + may be used by a function global entry point. For SysV4, r11 + is used by __glink_PLTresolve lazy resolver entry. */ + rtx reg = gen_rtx_REG (Pmode, regno); + rtx hi = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, base, call_ref, arg), + UNSPEC_PLT16_HA); + rtx lo = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, reg, call_ref, arg), + UNSPEC_PLT16_LO); + emit_insn (gen_rtx_SET (reg, hi)); + emit_insn (gen_rtx_SET (reg, lo)); + return reg; + } + return force_reg (Pmode, call_ref); } @@ -37508,8 +37649,7 @@ chain_already_loaded (rtx_insn *last) void rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) { - const bool direct_call_p - = GET_CODE (func_desc) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (func_desc); + rtx func = func_desc; rtx toc_reg = gen_rtx_REG (Pmode, TOC_REGNUM); rtx toc_load = NULL_RTX; rtx toc_restore = NULL_RTX; @@ -37523,12 +37663,13 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) tlsarg = global_tlsarg; /* Handle longcall attributes. */ - if (INTVAL (cookie) & CALL_LONG) - func_desc = rs6000_longcall_ref (func_desc); + if ((INTVAL (cookie) & CALL_LONG) != 0 + && GET_CODE (func_desc) == SYMBOL_REF) + func = rs6000_longcall_ref (func_desc, tlsarg); /* Handle indirect calls. */ - if (GET_CODE (func_desc) != SYMBOL_REF - || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (func_desc))) + if (GET_CODE (func) != SYMBOL_REF + || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (func))) { /* Save the TOC into its reserved slot before the call, and prepare to restore it after the call. */ @@ -37549,7 +37690,17 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) gen_rtx_PLUS (Pmode, stack_ptr, stack_toc_offset)); MEM_VOLATILE_P (stack_toc_mem) = 1; - emit_move_insn (stack_toc_mem, toc_reg); + if (HAVE_AS_PLTSEQ + && TARGET_TLS_MARKERS + && DEFAULT_ABI == ABI_ELFv2 + && GET_CODE (func_desc) == SYMBOL_REF) + { + rtvec v = gen_rtvec (3, toc_reg, func_desc, tlsarg); + rtx mark_toc_reg = gen_rtx_UNSPEC (Pmode, v, UNSPEC_PLTSEQ); + emit_insn (gen_rtx_SET (stack_toc_mem, mark_toc_reg)); + } + else + emit_move_insn (stack_toc_mem, toc_reg); } if (DEFAULT_ABI == ABI_ELFv2) @@ -37557,9 +37708,25 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) /* A function pointer in the ELFv2 ABI is just a plain address, but the ABI requires it to be loaded into r12 before the call. */ func_addr = gen_rtx_REG (Pmode, 12); - if (!rtx_equal_p (func_addr, func_desc)) - emit_move_insn (func_addr, func_desc); + if (!rtx_equal_p (func_addr, func)) + emit_move_insn (func_addr, func); abi_reg = func_addr; + /* Indirect calls via CTR are strongly preferred over indirect + calls via LR, so move the address there. Needed to mark + this insn for linker plt sequence editing too. */ + func_addr = gen_rtx_REG (Pmode, CTR_REGNO); + if (HAVE_AS_PLTSEQ + && TARGET_TLS_MARKERS + && GET_CODE (func_desc) == SYMBOL_REF) + { + rtvec v = gen_rtvec (3, abi_reg, func_desc, tlsarg); + rtx mark_func = gen_rtx_UNSPEC (Pmode, v, UNSPEC_PLTSEQ); + emit_insn (gen_rtx_SET (func_addr, mark_func)); + v = gen_rtvec (2, func_addr, func_desc); + func_addr = gen_rtx_UNSPEC (Pmode, v, UNSPEC_PLTSEQ); + } + else + emit_move_insn (func_addr, abi_reg); } else { @@ -37571,9 +37738,15 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) not have any executable code. */ /* Load up address of the actual function. */ - func_desc = force_reg (Pmode, func_desc); + func = force_reg (Pmode, func); func_addr = gen_reg_rtx (Pmode); - emit_move_insn (func_addr, gen_rtx_MEM (Pmode, func_desc)); + emit_move_insn (func_addr, gen_rtx_MEM (Pmode, func)); + + /* Indirect calls via CTR are strongly preferred over indirect + calls via LR, so move the address there. */ + rtx ctr_reg = gen_rtx_REG (Pmode, CTR_REGNO); + emit_move_insn (ctr_reg, func_addr); + func_addr = ctr_reg; /* Prepare to load the TOC of the called function. Note that the TOC load must happen immediately before the actual call so @@ -37581,7 +37754,7 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) comment in frob_update_context. */ rtx func_toc_offset = GEN_INT (GET_MODE_SIZE (Pmode)); rtx func_toc_mem = gen_rtx_MEM (Pmode, - gen_rtx_PLUS (Pmode, func_desc, + gen_rtx_PLUS (Pmode, func, func_toc_offset)); toc_load = gen_rtx_USE (VOIDmode, func_toc_mem); @@ -37589,14 +37762,15 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) originally direct, the 3rd word has not been written since no trampoline has been built, so we ought not to load it, lest we override a static chain value. */ - if (!direct_call_p + if (!(GET_CODE (func_desc) == SYMBOL_REF + && SYMBOL_REF_FUNCTION_P (func_desc)) && TARGET_POINTERS_TO_NESTED_FUNCTIONS && !chain_already_loaded (get_current_sequence ()->next->last)) { rtx sc_reg = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM); rtx func_sc_offset = GEN_INT (2 * GET_MODE_SIZE (Pmode)); rtx func_sc_mem = gen_rtx_MEM (Pmode, - gen_rtx_PLUS (Pmode, func_desc, + gen_rtx_PLUS (Pmode, func, func_sc_offset)); emit_move_insn (sc_reg, func_sc_mem); abi_reg = sc_reg; @@ -37609,7 +37783,7 @@ rs6000_call_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) assume the TOC register is set; for non-local calls, the PLT stub needs the TOC register. */ abi_reg = toc_reg; - func_addr = func_desc; + func_addr = func; } /* Create the call. */ @@ -37664,22 +37838,51 @@ rs6000_sibcall_aix (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) /* Expand code to perform a call under the SYSV4 ABI. */ void -rs6000_call_sysv (rtx value, rtx func, rtx tlsarg, rtx cookie) +rs6000_call_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) { + rtx func = func_desc; rtx func_addr; rtx call[3]; rtx insn; + rtx abi_reg = NULL_RTX; if (global_tlsarg) tlsarg = global_tlsarg; /* Handle longcall attributes. */ - if (INTVAL (cookie) & CALL_LONG) - func = rs6000_longcall_ref (func); + if ((INTVAL (cookie) & CALL_LONG) != 0 + && GET_CODE (func_desc) == SYMBOL_REF) + { + func = rs6000_longcall_ref (func_desc, tlsarg); + /* If the longcall was implemented using PLT16 relocs, then r11 + needs to be valid at the call for lazy linking. */ + if (HAVE_AS_PLTSEQ + && TARGET_TLS_MARKERS) + abi_reg = func; + } /* Handle indirect calls. */ if (GET_CODE (func) != SYMBOL_REF) - func_addr = force_reg (Pmode, func); + { + func = force_reg (Pmode, func); + + /* Indirect calls via CTR are strongly preferred over indirect + calls via LR, so move the address there. Needed to mark + this insn for linker plt sequence editing too. */ + func_addr = gen_rtx_REG (Pmode, CTR_REGNO); + if (HAVE_AS_PLTSEQ + && TARGET_TLS_MARKERS + && GET_CODE (func_desc) == SYMBOL_REF) + { + rtvec v = gen_rtvec (3, func, func_desc, tlsarg); + rtx mark_func = gen_rtx_UNSPEC (Pmode, v, UNSPEC_PLTSEQ); + emit_insn (gen_rtx_SET (func_addr, mark_func)); + v = gen_rtvec (2, func_addr, func_desc); + func_addr = gen_rtx_UNSPEC (Pmode, v, UNSPEC_PLTSEQ); + } + else + emit_move_insn (func_addr, func); + } else func_addr = func; @@ -37695,6 +37898,73 @@ rs6000_call_sysv (rtx value, rtx func, rtx tlsarg, rtx cookie) insn = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (3, call)); insn = emit_call_insn (insn); + if (abi_reg) + use_reg (&CALL_INSN_FUNCTION_USAGE (insn), abi_reg); +} + +/* Expand code to perform a sibling call under the SysV4 ABI. */ + +void +rs6000_sibcall_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) +{ + rtx func = func_desc; + rtx func_addr; + rtx call[3]; + rtx insn; + rtx abi_reg = NULL_RTX; + + if (global_tlsarg) + tlsarg = global_tlsarg; + + /* Handle longcall attributes. */ + if ((INTVAL (cookie) & CALL_LONG) != 0 + && GET_CODE (func_desc) == SYMBOL_REF) + { + func = rs6000_longcall_ref (func_desc, tlsarg); + /* If the longcall was implemented using PLT16 relocs, then r11 + needs to be valid at the call for lazy linking. */ + if (HAVE_AS_PLTSEQ + && TARGET_TLS_MARKERS) + abi_reg = func; + } + + /* Handle indirect calls. */ + if (GET_CODE (func) != SYMBOL_REF) + { + func = force_reg (Pmode, func); + + /* Indirect sibcalls must go via CTR. Needed to mark + this insn for linker plt sequence editing too. */ + func_addr = gen_rtx_REG (Pmode, CTR_REGNO); + if (HAVE_AS_PLTSEQ + && TARGET_TLS_MARKERS + && GET_CODE (func_desc) == SYMBOL_REF) + { + rtvec v = gen_rtvec (3, func, func_desc, tlsarg); + rtx mark_func = gen_rtx_UNSPEC (Pmode, v, UNSPEC_PLTSEQ); + emit_insn (gen_rtx_SET (func_addr, mark_func)); + v = gen_rtvec (2, func_addr, func_desc); + func_addr = gen_rtx_UNSPEC (Pmode, v, UNSPEC_PLTSEQ); + } + else + emit_move_insn (func_addr, func); + } + else + func_addr = func; + + /* Create the call. */ + call[0] = gen_rtx_CALL (VOIDmode, gen_rtx_MEM (SImode, func_addr), tlsarg); + if (value != NULL_RTX) + call[0] = gen_rtx_SET (value, call[0]); + + unsigned int mask = CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS; + call[1] = gen_rtx_USE (VOIDmode, GEN_INT (INTVAL (cookie) & mask)); + call[2] = simple_return_rtx; + + insn = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (3, call)); + insn = emit_call_insn (insn); + if (abi_reg) + use_reg (&CALL_INSN_FUNCTION_USAGE (insn), abi_reg); } /* Return whether we need to always update the saved TOC pointer when we update diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index f59c0b6b685..c7934c601ed 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -224,6 +224,10 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); #define HAVE_AS_TLS 0 #endif +#ifndef HAVE_AS_PLTSEQ +#define HAVE_AS_PLTSEQ 0 +#endif + #ifndef TARGET_LINK_STACK #define TARGET_LINK_STACK 0 #endif diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index d1451509aa7..849a100e2c5 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -147,6 +147,9 @@ (define_c_enum "unspec" UNSPEC_SIGNBIT UNSPEC_SF_FROM_SI UNSPEC_SI_FROM_SF + UNSPEC_PLTSEQ + UNSPEC_PLT16_HA + UNSPEC_PLT16_LO ]) ;; @@ -10236,6 +10239,55 @@ (define_insn "elf_low" (match_operand 2 "" "")))] "TARGET_ELF && !TARGET_64BIT && !flag_pic" "la %0,%2@l(%1)") + +(define_insn "*pltseq_tocsave_" + [(set (match_operand:P 0 "memory_operand" "=m") + (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b") + (match_operand:P 2 "symbol_ref_operand" "s") + (match_operand:P 3 "" "")] + UNSPEC_PLTSEQ))] + "HAVE_AS_PLTSEQ && TARGET_TLS_MARKERS + && DEFAULT_ABI == ABI_ELFv2" +{ + return rs6000_output_pltseq (operands, 0); +}) + +(define_insn "*pltseq_plt16_ha_" + [(set (match_operand:P 0 "gpc_reg_operand" "=r") + (unspec:P [(match_operand:P 1 "" "") + (match_operand:P 2 "symbol_ref_operand" "s") + (match_operand:P 3 "" "")] + UNSPEC_PLT16_HA))] + "HAVE_AS_PLTSEQ && TARGET_TLS_MARKERS + && (DEFAULT_ABI == ABI_ELFv2 || DEFAULT_ABI == ABI_V4)" +{ + return rs6000_output_pltseq (operands, 1); +}) + +(define_insn "*pltseq_plt16_lo_" + [(set (match_operand:P 0 "gpc_reg_operand" "=r") + (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b") + (match_operand:P 2 "symbol_ref_operand" "s") + (match_operand:P 3 "" "")] + UNSPEC_PLT16_LO))] + "HAVE_AS_PLTSEQ && TARGET_TLS_MARKERS + && (DEFAULT_ABI == ABI_ELFv2 || DEFAULT_ABI == ABI_V4)" +{ + return rs6000_output_pltseq (operands, 2); +} + [(set_attr "type" "load")]) + +(define_insn "*pltseq_mtctr_" + [(set (match_operand:P 0 "register_operand" "=c") + (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r") + (match_operand:P 2 "symbol_ref_operand" "s") + (match_operand:P 3 "" "")] + UNSPEC_PLTSEQ))] + "HAVE_AS_PLTSEQ && TARGET_TLS_MARKERS + && (DEFAULT_ABI == ABI_ELFv2 || DEFAULT_ABI == ABI_V4)" +{ + return rs6000_output_pltseq (operands, 3); +}) ;; Call and call_value insns (define_expand "call" @@ -10392,9 +10444,9 @@ (define_insn "*call_value_local64" ;; which indicates how to set cr1 (define_insn "*call_indirect_nonlocal_sysv" - [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l,c,*l")) + [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X")) (match_operand 1)) - (use (match_operand:SI 2 "immediate_operand" "O,O,n,n")) + (use (match_operand:SI 2 "immediate_operand" "n,n,n")) (clobber (reg:SI LR_REGNO))] "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN" @@ -10407,18 +10459,17 @@ (define_insn "*call_indirect_nonlocal_sysv" return rs6000_output_indirect_call (operands, 0, false); } - [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") - (set_attr_alternative "length" - [(if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "8") - (const_string "4")) - (const_string "4") - (if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "12") - (const_string "8")) - (const_string "8")])]) + [(set_attr "type" "jmpreg") + (set (attr "length") + (cond [(and (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "12") + (ior (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "8")] + (const_string "4")))]) (define_insn_and_split "*call_nonlocal_sysv" [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s")) @@ -10478,9 +10529,9 @@ (define_insn "*call_nonlocal_sysv_secure" (define_insn "*call_value_indirect_nonlocal_sysv" [(set (match_operand 0 "" "") - (call (mem:SI (match_operand:P 1 "register_operand" "c,*l,c,*l")) + (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X")) (match_operand 2))) - (use (match_operand:SI 3 "immediate_operand" "O,O,n,n")) + (use (match_operand:SI 3 "immediate_operand" "n,n,n")) (clobber (reg:SI LR_REGNO))] "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN" @@ -10493,18 +10544,17 @@ (define_insn "*call_value_indirect_nonlocal_sysv" return rs6000_output_indirect_call (operands, 1, false); } - [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") - (set_attr_alternative "length" - [(if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "8") - (const_string "4")) - (const_string "4") - (if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "12") - (const_string "8")) - (const_string "8")])]) + [(set_attr "type" "jmpreg") + (set (attr "length") + (cond [(and (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[3]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "12") + (ior (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[3]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "8")] + (const_string "4")))]) (define_insn_and_split "*call_value_nonlocal_sysv" [(set (match_operand 0 "" "") @@ -10617,10 +10667,10 @@ (define_insn "*call_value_nonlocal_aix" ;; Operand3 is the offset of the stack location holding the current TOC pointer (define_insn "*call_indirect_aix" - [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l")) + [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X")) (match_operand 1)) - (use (match_operand:P 2 "memory_operand" ",")) - (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) + (use (match_operand:P 2 "memory_operand" ",,")) + (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_AIX" { @@ -10635,10 +10685,10 @@ (define_insn "*call_indirect_aix" (define_insn "*call_value_indirect_aix" [(set (match_operand 0 "" "") - (call (mem:SI (match_operand:P 1 "register_operand" "c,*l")) + (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X")) (match_operand 2))) - (use (match_operand:P 3 "memory_operand" ",")) - (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 4 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) + (use (match_operand:P 3 "memory_operand" ",,")) + (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 4 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_AIX" { @@ -10656,9 +10706,9 @@ (define_insn "*call_value_indirect_aix" ;; Operand2 is the offset of the stack location holding the current TOC pointer (define_insn "*call_indirect_elfv2" - [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l")) + [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X")) (match_operand 1)) - (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 2 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) + (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 2 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_ELFv2" { @@ -10673,9 +10723,9 @@ (define_insn "*call_indirect_elfv2" (define_insn "*call_value_indirect_elfv2" [(set (match_operand 0 "" "") - (call (mem:SI (match_operand:P 1 "register_operand" "c,*l")) + (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X")) (match_operand 2))) - (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT)) + (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT)) (clobber (reg:P LR_REGNO))] "DEFAULT_ABI == ABI_ELFv2" { @@ -10738,6 +10788,12 @@ (define_expand "sibcall" rs6000_sibcall_aix (NULL_RTX, operands[0], operands[1], operands[2]); DONE; } + + if (DEFAULT_ABI == ABI_V4) + { + rs6000_sibcall_sysv (NULL_RTX, operands[0], operands[1], operands[2]); + DONE; + } }) (define_expand "sibcall_value" @@ -10763,6 +10819,12 @@ (define_expand "sibcall_value" rs6000_sibcall_aix (operands[0], operands[1], operands[2], operands[3]); DONE; } + + if (DEFAULT_ABI == ABI_V4) + { + rs6000_sibcall_sysv (operands[0], operands[1], operands[2], operands[3]); + DONE; + } }) (define_insn "*sibcall_local32" @@ -10839,10 +10901,38 @@ (define_insn "*sibcall_value_local64" [(set_attr "type" "branch") (set_attr "length" "4,8")]) +(define_insn "*sibcall_indirect_nonlocal_sysv" + [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X")) + (match_operand 1)) + (use (match_operand:SI 2 "immediate_operand" "n,n,n")) + (simple_return)] + "DEFAULT_ABI == ABI_V4 + || DEFAULT_ABI == ABI_DARWIN" +{ + if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS) + output_asm_insn ("crxor 6,6,6", operands); + + else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS) + output_asm_insn ("creqv 6,6,6", operands); + + return rs6000_output_indirect_call (operands, 0, true); +} + [(set_attr "type" "jmpreg") + (set (attr "length") + (cond [(and (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "12") + (ior (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "8")] + (const_string "4")))]) + (define_insn "*sibcall_nonlocal_sysv" - [(call (mem:SI (match_operand:P 0 "call_operand" "s,s,c,c")) - (match_operand 1 "" "")) - (use (match_operand 2 "immediate_operand" "O,n,O,n")) + [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s")) + (match_operand 1)) + (use (match_operand 2 "immediate_operand" "O,n")) (simple_return)] "(DEFAULT_ABI == ABI_DARWIN || DEFAULT_ABI == ABI_V4) @@ -10854,29 +10944,45 @@ (define_insn "*sibcall_nonlocal_sysv" else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - if (which_alternative >= 2) - return rs6000_output_indirect_call (operands, 0, true); - else - return rs6000_output_call (operands, 0, true); + return rs6000_output_call (operands, 0, true); } [(set_attr "type" "branch") - (set_attr_alternative "length" - [(const_string "4") - (const_string "8") - (if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "12") - (const_string "4")) - (if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "16") - (const_string "8"))])]) + (set_attr "length" "4,8")]) + +(define_insn "*sibcall_value_indirect_nonlocal_sysv" + [(set (match_operand 0 "" "") + (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X")) + (match_operand 2))) + (use (match_operand:SI 3 "immediate_operand" "n,n,n")) + (simple_return)] + "DEFAULT_ABI == ABI_V4 + || DEFAULT_ABI == ABI_DARWIN" +{ + if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS) + output_asm_insn ("crxor 6,6,6", operands); + + else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS) + output_asm_insn ("creqv 6,6,6", operands); + + return rs6000_output_indirect_call (operands, 1, true); +} + [(set_attr "type" "jmpreg") + (set (attr "length") + (cond [(and (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[3]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "12") + (ior (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (match_test "(INTVAL (operands[3]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))")) + (const_string "8")] + (const_string "4")))]) (define_insn "*sibcall_value_nonlocal_sysv" [(set (match_operand 0 "" "") - (call (mem:SI (match_operand:P 1 "call_operand" "s,s,c,c")) - (match_operand 2 "" ""))) - (use (match_operand:SI 3 "immediate_operand" "O,n,O,n")) + (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s")) + (match_operand 2))) + (use (match_operand:SI 3 "immediate_operand" "O,n")) (simple_return)] "(DEFAULT_ABI == ABI_DARWIN || DEFAULT_ABI == ABI_V4) @@ -10888,29 +10994,10 @@ (define_insn "*sibcall_value_nonlocal_sysv" else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - if (which_alternative >= 2) - { - if (rs6000_speculate_indirect_jumps) - return "b%T1"; - else - /* Can use CR0 since it is volatile across sibcalls. */ - return "crset 2\;beq%T1-\;b $"; - } - else - return rs6000_output_call (operands, 1, true); + return rs6000_output_call (operands, 1, true); } [(set_attr "type" "branch") - (set_attr_alternative "length" - [(const_string "4") - (const_string "8") - (if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "12") - (const_string "4")) - (if_then_else (eq (symbol_ref "rs6000_speculate_indirect_jumps") - (const_int 0)) - (const_string "16") - (const_string "8"))])]) + (set_attr "length" "4,8")]) ;; AIX ABI sibling call patterns. diff --git a/gcc/configure.ac b/gcc/configure.ac index 59585912556..5b81faa95eb 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -4636,6 +4636,12 @@ LCF0: [AC_DEFINE(HAVE_AS_ENTRY_MARKERS, 1, [Define if your assembler supports the R_PPC64_ENTRY relocation.])]) + gcc_GAS_CHECK_FEATURE([plt sequence marker support], + gcc_cv_as_powerpc_pltseq_markers, [2,31,0],-a32 --fatal-warnings, + [ .reloc .,R_PPC_PLTSEQ; nop],, + [AC_DEFINE(HAVE_AS_PLTSEQ, 1, + [Define if your assembler supports R_PPC*_PLTSEQ relocations.])]) + case $target in *-*-aix*) gcc_GAS_CHECK_FEATURE([AIX .ref support],