From patchwork Fri Jan 26 07:37:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 192421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp501466dyb; Thu, 25 Jan 2024 23:39:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9X0XIjBnUUThtuEuzek/zv4GX8cvC5/HJfiH0h15mSZEb7tHvbgY7Af7cMVYjIpm/rSll X-Received: by 2002:a05:622a:1748:b0:42a:7ba6:3725 with SMTP id l8-20020a05622a174800b0042a7ba63725mr872708qtk.109.1706254771708; Thu, 25 Jan 2024 23:39:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706254771; cv=pass; d=google.com; s=arc-20160816; b=J6qV8RvLelKKNR49QbQqW4CwEf3RwqcdBBHdkdkfTD0sVGMm5wplaGZ13VdpvWhRUY tDm9tHC4P1LQkNUnK75dPy/VZmelmu90AMAh8/t+QCFPWV+re5cIZkx2rAoC2q0Fr3Qb 5VAStSrbXnfSpvKJw1QfEsOdHGXhCf46kWPvELoPArus0rw08feddBtpsMw7LgzCcBXc ZKZJPqzDhsVHCSUk/A6ERbr+Ec5xLAw0pnJ+DstDz0u7lLVLQjA6eIh1708s1g05bPhX YpIXPLfrsxLho++xWUtYNBQc4C3/OJxDk9LEGxJBpNxXaLtS/fpA8RAnUdukKggLCQJ+ WUpQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to; bh=mPlGOb9/XKWJpWBdh3jSbLMGvcWdG8iFGi4T/YfqEJw=; fh=kLXYvQYlFoGM+V705nfHVJAr1G8Exwjn4Aw52UExiO4=; b=t0kENHAO6AMpcmfkChsfETEmgR8lBhSn4HBjiHo1yhJifUwWYCli+SdCIDf9Ac3zoJ dB/LNghr7yqNeGa9Go1zHb/Bxv/DgQdzrOWIcToYJRFUMVgEHUqMJLAaLLx/DUA0GjX1 R0rH+1hIuvmFaS6tYIsyikZYA8j2T2aZcWJHejRpFINbxw3psQx1/8qNadI5I7nK4qw0 khCyVXUoInOg79q8X6QVtQFrGbwgEX4id8yXH60Oi+ztSRszGJi1UFJaRKXi/sT4II2H aWecLgyuy0Mg9c/xsYzwrObcmzvkVljqcMG7Y6W+6C+PU01x+HVotWsq7/Hps/F2aqzZ UElQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w30-20020a05622a191e00b00429be6b6a64si635205qtc.580.2024.01.25.23.39.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 23:39:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 678FC3858013 for ; Fri, 26 Jan 2024 07:39:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id BE9F03858CD1 for ; Fri, 26 Jan 2024 07:38:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE9F03858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE9F03858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706254716; cv=none; b=EPdcvBFQzV9QyvurCJuAFiwLdIhLHI6A7eOOe2oPrSReK/z8eUtUeDKmLH6EzEZzTKVe7liCOyPInWsKbe2N+8wvoiNZyXPYKuhF9hJ+zac8Eg5Gm2Au0YoG1PZikE7eejxak8y0KXMUtnoRhGeN/61sEO1ySQnNjXngrDF7CIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706254716; c=relaxed/simple; bh=vjyy1+N7yCyQwvWpfOl1cCjzq/0Wy6cicGo6oWA4QOU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=R6czaHnUvjIpdsnSgsiDQU6JMWcTdz9c5/TrZNT7brEj+4n/mce4JCaDu3opapUr6T0vObjuWDLPMGnWpm7riQmE5lvc6aPn9vEQ9aq2eksZDy1WxYzx7zoH8eRzyE1aUdZdWtDObkMEfPbn2SAIw9j0SuqqF64yPoW189v102I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8AxOOh2YbNljCYGAA--.2229S3; Fri, 26 Jan 2024 15:38:30 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMxeYbNlPpUbAA--.44775S5; Fri, 26 Jan 2024 15:38:26 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, Lulu Cheng Subject: [PATCH v4 3/4] LoongArch: Enable explicit reloc for extreme TLS GD/LD with -mexplicit-relocs=auto. Date: Fri, 26 Jan 2024 15:37:44 +0800 Message-Id: <20240126073745.13252-4-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240126073745.13252-1-chenglulu@loongson.cn> References: <20240126073745.13252-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxRMxeYbNlPpUbAA--.44775S5 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoW3Gw1kCrW5uFWxWrWfZrWkAFc_yoW7Wr1fp3 y7Zw17Kr48X392g3WDXa4fXF1kAF42gFW2gF9IqryfCF47J34SqF18tF1YqFy7J3W5K3y7 WF1Fka4rX3W5X3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07Ul4E_UUUUU= X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, KAM_STOCKGEN, SPF_HELO_NONE, 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: 1789137803130085350 X-GMAIL-MSGID: 1789137803130085350 Binutils does not support relaxation using four instructions to obtain symbol addresses gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_explicit_relocs_p): When the code model of the symbol is extreme and -mexplicit-relocs=auto, the macro instruction loading symbol address is not applicable. (loongarch_call_tls_get_addr): Adjust code. (loongarch_legitimize_tls_address): Likewise. gcc/testsuite/ChangeLog: * gcc.target/loongarch/explicit-relocs-extreme-auto-tls-ld-gd.c: New test. * gcc.target/loongarch/explicit-relocs-medium-auto-tls-ld-gd.c: New test. --- gcc/config/loongarch/loongarch.cc | 19 +++++++++---------- .../explicit-relocs-extreme-auto-tls-ld-gd.c | 5 +++++ .../explicit-relocs-medium-auto-tls-ld-gd.c | 5 +++++ 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/explicit-relocs-extreme-auto-tls-ld-gd.c create mode 100644 gcc/testsuite/gcc.target/loongarch/explicit-relocs-medium-auto-tls-ld-gd.c diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 4c64742f78b..b76e201c0ef 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -1971,6 +1971,10 @@ loongarch_explicit_relocs_p (enum loongarch_symbol_type type) if (la_opt_explicit_relocs != EXPLICIT_RELOCS_AUTO) return la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS; + /* The linker don't know how to relax accesses in extreme code model. */ + if (loongarch_symbol_extreme_p (type)) + return true; + switch (type) { case SYMBOL_TLS_IE: @@ -1982,11 +1986,6 @@ loongarch_explicit_relocs_p (enum loongarch_symbol_type type) does not relax 64-bit pc-relative accesses as at now. */ 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 @@ -2776,7 +2775,7 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) start_sequence (); - if (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS) + if (loongarch_explicit_relocs_p (type)) { /* Split tls symbol to high and low. */ rtx high = gen_rtx_HIGH (Pmode, copy_rtx (loc)); @@ -2809,7 +2808,7 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) case CMODEL_MEDIUM: { rtx reg = gen_reg_rtx (Pmode); - if (TARGET_EXPLICIT_RELOCS) + if (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE) { emit_insn (gen_pcalau12i (Pmode, reg, loongarch_tls_symbol)); rtx call = gen_call_value_internal_1 (Pmode, v0, reg, @@ -2845,7 +2844,7 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) case CMODEL_NORMAL: case CMODEL_MEDIUM: { - if (TARGET_EXPLICIT_RELOCS) + if (loongarch_explicit_relocs_p (SYMBOL_GOT_DISP)) { rtx high = gen_reg_rtx (Pmode); loongarch_emit_move (high, @@ -2937,7 +2936,7 @@ loongarch_legitimize_tls_address (rtx loc) tmp1 = gen_reg_rtx (Pmode); tmp2 = loongarch_unspec_address (loc, SYMBOL_TLS_IE); dest = gen_reg_rtx (Pmode); - if (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE) + if (loongarch_explicit_relocs_p (SYMBOL_TLS_IE)) { tmp3 = gen_reg_rtx (Pmode); rtx high = gen_rtx_HIGH (Pmode, copy_rtx (tmp2)); @@ -2994,7 +2993,7 @@ loongarch_legitimize_tls_address (rtx loc) tmp2 = loongarch_unspec_address (loc, SYMBOL_TLS_LE); dest = gen_reg_rtx (Pmode); - if (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE) + if (loongarch_explicit_relocs_p (SYMBOL_TLS_LE)) { tmp3 = gen_reg_rtx (Pmode); rtx high = gen_rtx_HIGH (Pmode, copy_rtx (tmp2)); diff --git a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-extreme-auto-tls-ld-gd.c b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-extreme-auto-tls-ld-gd.c new file mode 100644 index 00000000000..27baf4886d6 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-extreme-auto-tls-ld-gd.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fPIC -mexplicit-relocs=auto -mcmodel=extreme -fno-plt" } */ +/* { dg-final { scan-assembler-not "la.tls.[lg]d" { target tls_native } } } */ + +#include "./explicit-relocs-auto-tls-ld-gd.c" diff --git a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-medium-auto-tls-ld-gd.c b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-medium-auto-tls-ld-gd.c new file mode 100644 index 00000000000..47bffae8af7 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-medium-auto-tls-ld-gd.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fPIC -mexplicit-relocs=auto -mcmodel=medium -fplt" } */ +/* { dg-final { scan-assembler-not "la.global" { target tls_native } } } */ + +#include "./explicit-relocs-auto-tls-ld-gd.c"