From patchwork Thu Dec 7 12:20:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1873178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=xry111.site header.i=@xry111.site header.a=rsa-sha256 header.s=default header.b=Hq3wqJhc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SmD1X02gFz23mf for ; Thu, 7 Dec 2023 23:22:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02885385AC2C for ; Thu, 7 Dec 2023 12:22:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 2454F385AC2C for ; Thu, 7 Dec 2023 12:22:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2454F385AC2C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2454F385AC2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701951748; cv=none; b=hsTlk229B5e2My9z/M3P19kca5i5Gfoo/k4Sz1x0RaP3QDJ0WORD1c6UCcuq/mYONZuXKM2UZW2rIf79aC7wYjJCgUustIi8hN/e8DJtqno0kvstXn6bA/hkNGUEVapnVYiWVqpBLg93+WNlrXxgxdcIwy1ENla+nxg2KonK0qA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701951748; c=relaxed/simple; bh=2EibJTfgHNvg7h62MHdEMaWsHNFm34rrJ8BYSgnZ5ak=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PV7it8B6dK78JT9ZdCSRQXQBRddZS08Iecrb5sPIO6PmT2KTfw5RSAtYJCxv7O5jQQjhgN3osqqRKqFz4GXCJRibn8OlV+3srxU2zD/zKZlaAjQPudxE2WDnxWT8VmfYystjwEpjDeap9BwXHjltRNcdGUBbJXm/4HsfzJyC5+4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1701951741; bh=2EibJTfgHNvg7h62MHdEMaWsHNFm34rrJ8BYSgnZ5ak=; h=From:To:Cc:Subject:Date:From; b=Hq3wqJhcYZZctGbJfObTbEtdyeSd1BBcUAp9WFzD4D97sD+LYtAL6wo5749oxjiGt ezUSUmotFZUBMIUp4v1OlG6kUibx/6LeJyCxaqXaywB9Ue8kzGVhrKd/Uuw3ccqLdk aNJwpW+eHqqqZy+CoBBopErNIgIerJSjImM7x2Sk= Received: from stargazer.. (unknown [113.140.11.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 3C00266C53; Thu, 7 Dec 2023 07:22:19 -0500 (EST) From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: chenglulu , i@xen0n.name, xuchenghua@loongson.cn, yangtiezhu@loongson.cn, hejinyang@loongson.cn, Xi Ruoyao Subject: [PATCH] LoongArch: Allow -mcmodel=extreme and model attribute with -mexplicit-relocs=auto Date: Thu, 7 Dec 2023 20:20:15 +0800 Message-ID: <20231207122014.19826-2-xry111@xry111.site> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, LIKELY_SPAM_FROM, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org There seems no real reason to require -mexplicit-relocs=always for -mcmodel=extreme or model attribute. As the linker does not know how to relax a 3-operand la.local or la.global pseudo instruction, just emit explicit relocs for SYMBOL_PCREL64, and under TARGET_CMODEL_EXTREME also SYMBOL_GOT_DISP. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_explicit_relocs_p): Return true for SYMBOL_PCREL64. Return true for SYMBOL_GOT_DISP if TARGET_CMODEL_EXTREME. (loongarch_split_symbol): Check for la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE instead of TARGET_EXPLICIT_RELOCS. (loongarch_print_operand_reloc): Likewise. (loongarch_option_override_internal): Likewise. (loongarch_handle_model_attribute): Likewise. gcc/testsuite/ChangeLog: * gcc.target/loongarch/attr-model-3.c: New test. * gcc.target/loongarch/attr-model-4.c: New test. * gcc.target/loongarch/func-call-extreme-3.c: New test. * gcc.target/loongarch/func-call-extreme-4.c: New test. --- Bootstrapped and regtested on loongarch64-linux-gnu. Not sure if it's a good idea to commit it now as we are in stage 3, maybe it's better to defer this into GCC 15. Any idea? gcc/config/loongarch/loongarch.cc | 25 ++++++++++++------- .../gcc.target/loongarch/attr-model-3.c | 6 +++++ .../gcc.target/loongarch/attr-model-4.c | 6 +++++ .../loongarch/func-call-extreme-3.c | 7 ++++++ .../loongarch/func-call-extreme-4.c | 7 ++++++ 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/attr-model-3.c create mode 100644 gcc/testsuite/gcc.target/loongarch/attr-model-4.c create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 3545e66a10e..5274b513807 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -1958,9 +1958,16 @@ loongarch_explicit_relocs_p (enum loongarch_symbol_type type) case SYMBOL_TLS_LE: case SYMBOL_TLSGD: case SYMBOL_TLSLDM: - /* The linker don't know how to relax TLS accesses. */ + case SYMBOL_PCREL64: + /* The linker don't know how to relax TLS accesses or 64-bit + pc-relative accesses. */ return true; case SYMBOL_GOT_DISP: + /* The linker don't know how to relax GOT accesses in extreme + code model. */ + if (TARGET_CMODEL_EXTREME) + return true; + /* If we are performing LTO for a final link, and we have the linker plugin so we know the resolution of the symbols, then all GOT references are binding to external symbols or @@ -3124,7 +3131,7 @@ loongarch_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out) if (loongarch_symbol_extreme_p (symbol_type) && can_create_pseudo_p ()) { - gcc_assert (TARGET_EXPLICIT_RELOCS); + gcc_assert (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE); temp1 = gen_reg_rtx (Pmode); emit_move_insn (temp1, gen_rtx_LO_SUM (Pmode, gen_rtx_REG (Pmode, 0), @@ -5891,7 +5898,7 @@ loongarch_print_operand_reloc (FILE *file, rtx op, bool hi64_part, loongarch_classify_symbolic_expression (op); if (loongarch_symbol_extreme_p (symbol_type)) - gcc_assert (TARGET_EXPLICIT_RELOCS); + gcc_assert (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE); switch (symbol_type) { @@ -7493,9 +7500,9 @@ loongarch_option_override_internal (struct gcc_options *opts, switch (la_target.cmodel) { case CMODEL_EXTREME: - if (!TARGET_EXPLICIT_RELOCS) - error ("code model %qs needs %s", - "extreme", "-mexplicit-relocs=always"); + if (la_opt_explicit_relocs == EXPLICIT_RELOCS_NONE) + error ("code model %qs is not compatible with %s", + "extreme", "-mexplicit-relocs=none"); if (opts->x_flag_plt) { @@ -7796,11 +7803,11 @@ loongarch_handle_model_attribute (tree *node, tree name, tree arg, int, *no_add_attrs = true; return NULL_TREE; } - if (!TARGET_EXPLICIT_RELOCS) + if (la_opt_explicit_relocs == EXPLICIT_RELOCS_NONE) { error_at (DECL_SOURCE_LOCATION (decl), - "%qE attribute requires %s", name, - "-mexplicit-relocs=always"); + "%qE attribute is not compatible with %s", name, + "-mexplicit-relocs=none"); *no_add_attrs = true; return NULL_TREE; } diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-3.c b/gcc/testsuite/gcc.target/loongarch/attr-model-3.c new file mode 100644 index 00000000000..5622d508678 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-3.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-mexplicit-relocs=auto -mcmodel=normal -O2" } */ +/* { dg-final { scan-assembler-times "%pc64_hi12" 2 } } */ + +#define ATTR_MODEL_TEST +#include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-4.c b/gcc/testsuite/gcc.target/loongarch/attr-model-4.c new file mode 100644 index 00000000000..482724bb974 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-4.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-mexplicit-relocs=auto -mcmodel=extreme -O2" } */ +/* { dg-final { scan-assembler-times "%pc64_hi12" 3 } } */ + +#define ATTR_MODEL_TEST +#include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c new file mode 100644 index 00000000000..a4da44b4a3d --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs=auto -mcmodel=extreme" } */ +/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ +/* { dg-final { scan-assembler "test1:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ +/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ + +#include "func-call-extreme-1.c" diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c new file mode 100644 index 00000000000..16b00f4c5f2 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs=auto -mcmodel=extreme" } */ +/* { dg-final { scan-assembler "test:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ +/* { dg-final { scan-assembler "test1:.*pcalau12i.*%got_pc_hi20.*\n\taddi\.d.*%got_pc_lo12.*\n\tlu32i\.d.*%got64_pc_lo20.*\n\tlu52i\.d.*%got64_pc_hi12.*\n\tldx\.d" } } */ +/* { dg-final { scan-assembler "test2:.*pcalau12i.*%pc_hi20.*\n\taddi\.d.*%pc_lo12.*\n\tlu32i\.d.*%pc64_lo20.*\n\tlu52i\.d.*pc64_hi12.*\n\tadd\.d" } } */ + +#include "func-call-extreme-1.c"