From patchwork Wed Dec 27 08:46:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 82885 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 394363858402 for ; Wed, 27 Dec 2023 08:49:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 1F8563858CD1 for ; Wed, 27 Dec 2023 08:47:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F8563858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1F8563858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703666872; cv=none; b=RFd5mJlU7GE+bIhgg2pROQfmvmUGbzNeEJES+DNbu5xwMbpQSmvbP03XQpcnrnoNY7tB7voGYSDp0I15QL2+VmuAKSk0UcPuSJh0F1Sur+6LVEl4NuSk/1bwLhYavIPXFfFcjt3ejkP3lkxZ3mmlKDK8maGhSOaELANO3uCoQWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703666872; c=relaxed/simple; bh=wKBex2wZHcu22wyy2YMehytzr1/5csaMhJog1YtqjIk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=kJpYmDSeS0narB8ZRjeHIVJO8cwCOTgcGasG4ABWpDfeBs+h//VBejxTo8MFAIWg4VE2JF23i8Hw0wGGrtgOhugv7Ad26pB8Wsl+9sIgpO/b7SGblro1RXmxWI4uq0q94cXZMgwB+L58IWdwHSvHnvAjfqXEhkIE9t9SmcZupiQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rIPZi-0004xW-JI for gcc-patches@gcc.gnu.org; Wed, 27 Dec 2023 03:47:41 -0500 Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8DxfYei5Itlk_gEAA--.1050S3; Wed, 27 Dec 2023 16:47:30 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxneSP5ItlKokMAA--.44813S4; Wed, 27 Dec 2023 16:47:29 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH 2/2] LoongArch: When the code model is extreme, the symbol address is obtained through macro instructions regardless of the value of -mexplicit-relocs. Date: Wed, 27 Dec 2023 16:46:54 +0800 Message-Id: <20231227084654.20614-3-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231227084654.20614-1-chenglulu@loongson.cn> References: <20231227084654.20614-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxneSP5ItlKokMAA--.44813S4 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoW3Cr15Ww13CFyDGrWfZw4DWrX_yoWDtF4kpa y7Ar1Yqr4rGa97K3WkJa4rJrs3Zw4DKrWa9wnxJryxuF4qq3sFqaykKa9rtF4UJF1UtryS vr1I93W7Xanaq3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUcsjjDUUUU Received-SPF: pass client-ip=114.242.206.163; envelope-from=chenglulu@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_FAIL, SPF_HELO_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+patchwork=sourceware.org@gcc.gnu.org Instructions pcalau12i, addi.d, lu32i.d and lu52i.d must be adjancent so that the linker can infer the PC of pcalau12i to apply relocations to lu32i.d and lu52i.d. Otherwise, the results would be incorrect if these four instructions are not in the same 4KiB page. See the link for details: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#extreme-code-model. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_symbol_extreme_p): Add function declaration. (loongarch_explicit_relocs_p): Use the macro instruction to get the symbol address when loongarch_symbol_extreme_p returns true. gcc/testsuite/ChangeLog: * gcc.target/loongarch/attr-model-1.c: Modify the content of the search string in the test case. * gcc.target/loongarch/attr-model-2.c: Likewise. * gcc.target/loongarch/attr-model-3.c: Likewise. * gcc.target/loongarch/attr-model-4.c: Likewise. * gcc.target/loongarch/func-call-extreme-1.c: Likewise. * gcc.target/loongarch/func-call-extreme-2.c: Likewise. * gcc.target/loongarch/func-call-extreme-3.c: Likewise. * gcc.target/loongarch/func-call-extreme-4.c: Likewise. --- gcc/config/loongarch/loongarch.cc | 11 +++++++++++ gcc/testsuite/gcc.target/loongarch/attr-model-1.c | 2 +- gcc/testsuite/gcc.target/loongarch/attr-model-2.c | 2 +- gcc/testsuite/gcc.target/loongarch/attr-model-3.c | 2 +- gcc/testsuite/gcc.target/loongarch/attr-model-4.c | 2 +- .../gcc.target/loongarch/func-call-extreme-1.c | 6 +++--- .../gcc.target/loongarch/func-call-extreme-2.c | 6 +++--- .../gcc.target/loongarch/func-call-extreme-3.c | 6 +++--- .../gcc.target/loongarch/func-call-extreme-4.c | 6 +++--- 9 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index e33b9db5981..aa9a9598000 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -264,6 +264,9 @@ const char *const loongarch_fp_conditions[16]= {LARCH_FP_CONDITIONS (STRINGIFY)}; #undef STRINGIFY +static bool +loongarch_symbol_extreme_p (enum loongarch_symbol_type type); + /* Size of guard page. */ #define STACK_CLASH_PROTECTION_GUARD_SIZE \ (1 << param_stack_clash_protection_guard_size) @@ -1963,6 +1966,14 @@ loongarch_symbolic_constant_p (rtx x, enum loongarch_symbol_type *symbol_type) bool loongarch_explicit_relocs_p (enum loongarch_symbol_type type) { + /* Instructions pcalau12i, addi.d, lu32i.d and lu52i.d must be adjancent + so that the linker can infer the PC of pcalau12i to apply relocations + to lu32i.d and lu52i.d. Otherwise, the results would be incorrect if + these four instructions are not in the same 4KiB page. + Therefore, macro instructions are used when cmodel=extreme. */ + if (loongarch_symbol_extreme_p (type)) + return false; + if (la_opt_explicit_relocs != EXPLICIT_RELOCS_AUTO) return la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS; diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-1.c b/gcc/testsuite/gcc.target/loongarch/attr-model-1.c index 916d715b98b..3963b8957b0 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-1.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-1.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs -mcmodel=normal -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 2 } } */ +/* { dg-final { scan-assembler-times "la\.local.*,\\\$r15," 2 } } */ #define ATTR_MODEL_TEST #include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-2.c b/gcc/testsuite/gcc.target/loongarch/attr-model-2.c index a74c795ac3e..6f154a92499 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-2.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-2.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs -mcmodel=extreme -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 3 } } */ +/* { dg-final { scan-assembler-times "la\.local.*,\\\$r15," 3 } } */ #define ATTR_MODEL_TEST #include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/attr-model-3.c b/gcc/testsuite/gcc.target/loongarch/attr-model-3.c index 5622d508678..eb177905d34 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-3.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-3.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs=auto -mcmodel=normal -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 2 } } */ +/* { dg-final { scan-assembler-times "la\.local.*,\\\$r15," 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 index 482724bb974..570a0bd6690 100644 --- a/gcc/testsuite/gcc.target/loongarch/attr-model-4.c +++ b/gcc/testsuite/gcc.target/loongarch/attr-model-4.c @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-mexplicit-relocs=auto -mcmodel=extreme -O2" } */ -/* { dg-final { scan-assembler-times "%pc64_hi12" 3 } } */ +/* { dg-final { scan-assembler-times "la\.local.*,\\\$r15," 3 } } */ #define ATTR_MODEL_TEST #include "attr-model-test.c" diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c index db1e0f85396..46318f3d23f 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-1.c @@ -1,8 +1,8 @@ /* { dg-do compile } */ /* { dg-options "-mabi=lp64d -O0 -fno-pic -fno-plt -mexplicit-relocs -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" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.local.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ extern void g (void); void diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c index 21bf81ae837..14b6e658ca1 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-2.c @@ -1,8 +1,8 @@ /* { dg-do compile } */ /* { dg-options "-mabi=lp64d -O0 -fpic -fno-plt -mexplicit-relocs -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" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ extern void g (void); void diff --git a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c index a4da44b4a3d..2ccbd2deb7c 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-3.c @@ -1,7 +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" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.local.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ #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 index 16b00f4c5f2..0067024ef7d 100644 --- a/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c +++ b/gcc/testsuite/gcc.target/loongarch/func-call-extreme-4.c @@ -1,7 +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" } } */ +/* { dg-final { scan-assembler "test:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test1:.*la\.global.*,\\\$r15," } } */ +/* { dg-final { scan-assembler "test2:.*la\.local.*,\\\$r15," } } */ #include "func-call-extreme-1.c"