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: 175112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4741236vqy; Thu, 7 Dec 2023 04:22:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9srARX2u7aMvemXdF0YZ1agND0dtc9YlhGaBlvViyJCX82m14xDe9o0gpwsa3R86prMrv X-Received: by 2002:ac8:5989:0:b0:423:aa14:ea51 with SMTP id e9-20020ac85989000000b00423aa14ea51mr3224341qte.68.1701951769522; Thu, 07 Dec 2023 04:22:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701951769; cv=pass; d=google.com; s=arc-20160816; b=m7ZUN4S0ityfdiNTXgiDWCqcJkJXuv2HkV2qk9oGNIZlA8Yuzxk0JOgBLuNaJR/D1Z ZH0ajK/QiuK9jf3Wgj7y5GonE8qznCDrFPKcyBE0TdrR8sBQEMzMFCltBq/etrUe/zTu YhJPsX4XTTtno1joDaKO+2Mwn/wFeDQlM0tdeFmFmYB5MH8CfX3B2VoVy18vM/YW/h4v bhIbJCrTJAldHbXi2PlWFipXwaJ84GBXN0QLRC93eQtsvTPBdXa0VfZ6JYdtX7m88sot 57kJJGBInheEpOy3Mq6q3lWfC8J43nGHZ3X/c6Vy0XRJeRAr6Hlm3tNjmkCAV4pnehbf DRKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=lAB7zBhS/8yQyPRHHR6FnNDoNMjwDnPbInwrwWgAem4=; fh=4APu7jAs8s2HFT9s70Hl5oTn7MRA03X/wm/lLPQMKk0=; b=NHC7d5ay8At8fmoTkzlUHSZ6xxg8QbizPyti83Xb/Gt4TDRM0KdwM6IJ2ileGsyqim 32F7P7Qjg8lPOXG9sodDguVInCRL13zKs328QU7fgGgCZaY7+r2ySfHROCKEGxSkKLLF Oq9fog/X3z8nIY+UNydns+OelDVqJlcMm4bZ5/AdOmxBLFk/tP9KOiTzYG4wBRCx7YBQ fbYlm1rFFkXRGAbHDGHWGwr962dDunN3dCO9eGrKn8pRPC0PkzB7e3EfIHB6l3uQ2oVX W0kGt2JxB79GLFi80Lx7ljG3haRttVHbWnR6TlIl2JThhK3h3+aIGhsSa/1UJACF67A+ 14XQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=Hq3wqJhc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t7-20020ac87387000000b00421b37cfde8si1171487qtp.185.2023.12.07.04.22.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 04:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=Hq3wqJhc; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4CE85385E037 for ; Thu, 7 Dec 2023 12:22:49 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784625778499094194 X-GMAIL-MSGID: 1784625778499094194 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"