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: 208232 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp223277dyb; Wed, 28 Feb 2024 23:14:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXS+dDLtb8yznflH6+A/Rmc4xzMkxbGCrfM/V7GX5KlpPRQcgeXBCAyBXSqbEqGeHYjsvDURUBm42wrUG7LU8U+ATMNng== X-Google-Smtp-Source: AGHT+IFKnImvDvGQr/F1XuV1vFaJCxL3hbAPQcRbDhp78QFje0YIzGnRbp6ay5THRklXeNntUSyT X-Received: by 2002:a0d:d64d:0:b0:604:a566:2555 with SMTP id y74-20020a0dd64d000000b00604a5662555mr1366610ywd.6.1709190869052; Wed, 28 Feb 2024 23:14:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709190869; cv=pass; d=google.com; s=arc-20160816; b=qNykFYNfJdirwlExwydsHKleV9K/HTHas1GwaD3HVysB0Xx4bngtKuOmhae//C1u/5 ZIwK2w3qBzYBcSEZiwno1i2LCqO7y5fm3m02Dl40eoRHKADtUwjkmPjPyC/mNRrSI4rz iD0cvh+em6hb1RCdzRY7OQwXT4h56ulHQqM5cuNC9TDhU7ML9+IyBaTrVWaKhwxFF1+8 xkwOpFOf1iqC7Hdb7MqMFPRzj+Sz5H3lWciLpd+jX5tUdXPapv7Cd5R2+bSPasLqLaQ7 6ryKyk9w14HpYBmd3URUTAZ7O60RfFtjG/5TIX5AFrD04sf3qkl/PTDW/+gYCYk7qWnQ 8eXA== 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=fg2Af8xmawKbRXSrgYu6PkZocm7mcrfBUxn4n11JPi0=; fh=WHvD1u5mZctXQMyNO+b6pB/B6rwPjatTlYt4eFNpRQ8=; b=FnJ54KkHwVz52g3dw9o+MRyPkHsx68Crp+gwjiF/ZhPITuwweHPFa8DNwDQNyikrBv HO86JZ+Rz3bUXRfwP8+ZDMB50q/Vb5FbsCHm2GGWgViQqGzqaDNch5oU4Isa1q1umxlN 8U2Yo5YEV6BmF6qh8KUm+WeNRxGqXOGf0CYD8+uyAg1OaxeqyoMT+ajJ9If053r82IuP F03j9m66NwZdp53F5sf6pcwEEBz+AdAhkhbRcy9OqUX5lpVyEraZvVOFUbILWQbXGGEr G3JE24a3muqWOIZNY8oOKMOqFGkxQAdcu5vCfHnI8rFE5BXIZWB8Rw8+Ylvpp9P5WaGh gfrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=UcuY+v1X; 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"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x21-20020ac85395000000b0042e6702435asi769094qtp.678.2024.02.28.23.14.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 23:14:29 -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; dkim=pass header.i=@xry111.site header.s=default header.b=UcuY+v1X; 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"; 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 AB3503858433 for ; Thu, 29 Feb 2024 07:14:28 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792216524950296354 X-GMAIL-MSGID: 1792216524950296354 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; +}