From patchwork Thu Feb 29 07:11:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1906201 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=UcuY+v1X; 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 4TljBd63Qjz20Qg for ; Thu, 29 Feb 2024 18:14:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF6BA3858286 for ; Thu, 29 Feb 2024 07:13:59 +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 4CE783858C31 for ; Thu, 29 Feb 2024 07:13:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CE783858C31 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 4CE783858C31 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=1709190817; cv=none; b=lRIGt0FysaRaJ2/PlJf/qcVfxkQRmxsrKATRRFw1xqUuj9c3Z1IIKdDOIyRwSGOZ8wDIBfmcQ0NxHfqsnFk+S7Oyxf4wM8Lbg4nZ6lEuQYmBy7shYFlGua3e8QLSYHXshj9snYwbkqTkpKChe+tkaEgOVv9PZKjY5AIfbXWu9lU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709190817; c=relaxed/simple; bh=FoMJEu54YS0L1mUzuM282mNvdsFVpWfVGcdwCXxVhDo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ktuMemRzAZ6kobtl06dZ5LL8+PCfGzyli8JcEllCrE0GG3cSG39BhYnP8rVQtkk7kq5n0UAQcRMS5RQ0zG1rbC9naOblmxXdAdGJzZTaA6pdpG7VIjp2OeFb8ECTqKCtmvqOFhUt1whTOaFD0dPf4aSiQYEA5yVt+nfy789xTlQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1709190813; bh=FoMJEu54YS0L1mUzuM282mNvdsFVpWfVGcdwCXxVhDo=; h=From:To:Cc:Subject:Date:From; b=UcuY+v1XZPN0Jq1GaeofQ5R6JV0iv/0/udNS6bjSbAwdEDBygOD98XZ8xv+XvcHAm lZUPOCA8nS1PmTrgT+IAXZb8Jx1/JimsgB6JhNq29ybJjz2LhI1GhdOmdiW1qB5FnL MzJjBx5IvG9kdo/WyYRSa2ToNCAvQkP0e9Y9f+NM= Received: from stargazer.. (unknown [IPv6:240e:358:11be:c900:dc73:854d:832e:5]) (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 AC95F66D0E; Thu, 29 Feb 2024 02:13:29 -0500 (EST) From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: chenglulu , i@xen0n.name, xuchenghua@loongson.cn, mengqinggang@loongson.cn, Xi Ruoyao Subject: [PATCH] LoongArch: Emit R_LARCH_RELAX for TLS IE with non-extreme code model to allow the IE to LE linker relaxation Date: Thu, 29 Feb 2024 15:11:52 +0800 Message-ID: <20240229071309.57435-1-xry111@xry111.site> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-7.8 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, 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 In Binutils we need to make IE to LE relaxation only allowed when there is an R_LARCH_RELAX after R_LARCH_TLE_IE_PC_{HI20,LO12} so an invalid "partial" relaxation won't happen with the extreme code model. So if we are emitting %ie_pc_{hi20,lo12} in a non-extreme code model, emit an R_LARCH_RELAX to allow the relaxation. The IE to LE relaxation does not require the pcalau12i and the ld instruction to be adjacent, so we don't need to limit ourselves to use the macro. For the distro maintainers backporting changes: this change depends on r14-8721, without r14-8721 R_LARCH_RELAX can be emitted mistakenly in the extreme code model. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_print_operand_reloc): Support 'Q' for R_LARCH_RELAX for TLS IE. (loongarch_output_move): Use 'Q' to print R_LARCH_RELAX for TLS IE. * config/loongarch/loongarch.md (ld_from_got): Likewise. gcc/testsuite/ChangeLog: * gcc.target/loongarch/tls-ie-relax.c: New test. * gcc.target/loongarch/tls-ie-norelax.c: New test. * gcc.target/loongarch/tls-ie-extreme.c: New test. --- Bootstrapped & regtested on loongarch64-linux-gnu. Ok for trunk? gcc/config/loongarch/loongarch.cc | 15 ++++++++++++++- gcc/config/loongarch/loongarch.md | 2 +- .../gcc.target/loongarch/tls-ie-extreme.c | 5 +++++ .../gcc.target/loongarch/tls-ie-norelax.c | 5 +++++ gcc/testsuite/gcc.target/loongarch/tls-ie-relax.c | 11 +++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/tls-ie-extreme.c create mode 100644 gcc/testsuite/gcc.target/loongarch/tls-ie-norelax.c create mode 100644 gcc/testsuite/gcc.target/loongarch/tls-ie-relax.c diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 0428b6e65d5..70e31bb831c 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -4981,7 +4981,7 @@ loongarch_output_move (rtx dest, rtx src) if (type == SYMBOL_TLS_LE) return "lu12i.w\t%0,%h1"; else - return "pcalau12i\t%0,%h1"; + return "%Q1pcalau12i\t%0,%h1"; } if (src_code == CONST_INT) @@ -6145,6 +6145,7 @@ loongarch_print_operand_reloc (FILE *file, rtx op, bool hi64_part, 'L' Print the low-part relocation associated with OP. 'm' Print one less than CONST_INT OP in decimal. 'N' Print the inverse of the integer branch condition for comparison OP. + 'Q' Print R_LARCH_RELAX for TLS IE. 'r' Print address 12-31bit relocation associated with OP. 'R' Print address 32-51bit relocation associated with OP. 'T' Print 'f' for (eq:CC ...), 't' for (ne:CC ...), @@ -6282,6 +6283,18 @@ loongarch_print_operand (FILE *file, rtx op, int letter) letter); break; + case 'Q': + if (!TARGET_LINKER_RELAXATION) + break; + + if (code == HIGH) + op = XEXP (op, 0); + + if (loongarch_classify_symbolic_expression (op) == SYMBOL_TLS_IE) + fprintf (file, ".reloc\t.,R_LARCH_RELAX\n\t"); + + break; + case 'r': loongarch_print_operand_reloc (file, op, false /* hi64_part */, true /* lo_reloc */); diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md index f3b5c641fce..525e1e82183 100644 --- a/gcc/config/loongarch/loongarch.md +++ b/gcc/config/loongarch/loongarch.md @@ -2620,7 +2620,7 @@ (define_insn "@ld_from_got" (match_operand:P 2 "symbolic_operand")))] UNSPEC_LOAD_FROM_GOT))] "" - "ld.\t%0,%1,%L2" + "%Q2ld.\t%0,%1,%L2" [(set_attr "type" "move")] ) diff --git a/gcc/testsuite/gcc.target/loongarch/tls-ie-extreme.c b/gcc/testsuite/gcc.target/loongarch/tls-ie-extreme.c new file mode 100644 index 00000000000..00c545a3e8c --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/tls-ie-extreme.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=loongarch64 -mabi=lp64d -mcmodel=extreme -mexplicit-relocs=auto -mrelax" } */ +/* { dg-final { scan-assembler-not "R_LARCH_RELAX" { target tls_native } } } */ + +#include "tls-ie-relax.c" diff --git a/gcc/testsuite/gcc.target/loongarch/tls-ie-norelax.c b/gcc/testsuite/gcc.target/loongarch/tls-ie-norelax.c new file mode 100644 index 00000000000..dd6bf3634a4 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/tls-ie-norelax.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcmodel=normal -mexplicit-relocs -mno-relax" } */ +/* { dg-final { scan-assembler-not "R_LARCH_RELAX" { target tls_native } } } */ + +#include "tls-ie-relax.c" diff --git a/gcc/testsuite/gcc.target/loongarch/tls-ie-relax.c b/gcc/testsuite/gcc.target/loongarch/tls-ie-relax.c new file mode 100644 index 00000000000..e9f7569b1da --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/tls-ie-relax.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcmodel=normal -mexplicit-relocs -mrelax" } */ +/* { dg-final { scan-assembler-times "R_LARCH_RELAX" 2 { target tls_native } } } */ + +extern __thread int errno; + +void +unimplemented (void) +{ + errno = -38; +}