From patchwork Fri Feb 2 13:00:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 195853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp408348dyc; Fri, 2 Feb 2024 05:01:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrLn26ts24BIXgstvIkm3JtJpkwPJhOpK+f167r62g2FATwPPBfoajMuijdgK+309HOW1y X-Received: by 2002:a05:6870:d1c6:b0:218:f6e1:95c0 with SMTP id b6-20020a056870d1c600b00218f6e195c0mr3976732oac.18.1706878906481; Fri, 02 Feb 2024 05:01:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706878906; cv=pass; d=google.com; s=arc-20160816; b=z1QmN7enPgSSgs9ifTqzgaDEb1JnnOLpElfEMwFDEu1btHNFMfN1dtsqUxxjUd+lC2 pECGGNryLZeiDf/QlIhtls/4zqYL9Kk+jafkNqlyfLwXu30Hrb0ETxbWpNKMa0PbxkJi w+MHm/24f0AGOxM/M1Xar/KaODq+ptpOcd4SPnJybFRqbFLfiQbe7pPKgO3qLXEkETvN vqkAlrJ6Br+xKeuFIZ2jj89T0uls6xRPzYKZg+LEO1mo79QHRL1RrBWm3Wv5dNlfZfjB 7NTE3HtOT3stR1t8wIZZSyWeUuP9pOcUXbbWiXHdDwzmdggMj3dk4XM5n2X5E5LrgJMK uejw== 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=JaPqHEqrIaTDscOLrn4tQj7t/dHhFRYc6hlmAb6gx6k=; fh=k3Q7coLgt2DPOM9BsMotbHMPDyMWy12kmT3R8w4ODt8=; b=UwxNXAxBgXK+18i93YxsdaWoKYQ3IbRgiTFbQSPaXp95zL+Ui2bJqzhtoJoc4XXcjG 55y/zxyrWzIMH5omDTGJ9PFHGSe4m/XTf65rejxqDStflJZIPebhWai2DCCcpeAhcxzR TxtV1Yu1m/vPvncgYjKtgOx+jy33Sc+ud29Wg5ibb1KEKcUDIIazpUwUdCsNuvLOSTEH 1gtx+bb5WHw6F75fv4SAHpKXJnRVGBKwd8Necxb96iZsIZpyANXTSImZWdXum4662Fq4 zeIpnXZNWFeX36//ieCDulTogicdMewKdARB7HAHk8M+7FSiEAkpypQbLCopvalvLzBu cHdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=Enhw4UwB; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site X-Forwarded-Encrypted: i=1; AJvYcCUDS/qBvg1uMBa3jOFNbgL0vvKcSReqmLh2MkGBnMUq+8xZAjMblcPCT0QlRqlNLGuQSqq1pEypf1zEfn2USmcVgUbTbQ== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w1-20020a05620a148100b0078553af0b7esi1505252qkj.90.2024.02.02.05.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 05:01:46 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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=Enhw4UwB; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 14406385800D for ; Fri, 2 Feb 2024 13:01:45 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 291C738582B7 for ; Fri, 2 Feb 2024 13:01:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 291C738582B7 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 291C738582B7 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=1706878895; cv=none; b=YfZQtaqpbzjvo1V4Lf4YE8NVzIwpjDHfbaBhwk8BtJmmhzCPsVvIaIAK6K0X7XQbNxVzMC2OQEb3IXIAFvU1FK3eWDfpUwrrkES/nJDv6jiWwbc1gdO3eY7pR/exBFtU6DBf56P5coyuISCrhzTQ67a5Iz9IyLE0uYf8gogRzgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706878895; c=relaxed/simple; bh=h+BpgFZGmO+b19lMt9pzihMKnDCN2DdzRc7vqV6CdsI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Zd/l2862GbMhdnRvI+90t8YosYp4djyfkUwu3mRrRGqp+u/v09cyOr9ak0SrQdiXets6HckTIpzOU1RyrPKNb9H0Ae/BI2+B6ucJgIjYBrup7ruLZ63yMbNJfkcKFzPJ8B5zllbSbIIzluuySIG3h41ROj+0rpzXt0aMq+Fj/BE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1706878887; bh=h+BpgFZGmO+b19lMt9pzihMKnDCN2DdzRc7vqV6CdsI=; h=From:To:Cc:Subject:Date:From; b=Enhw4UwBFrZ6QbECwp+ufj0wsN9sfY+gjG628mebR6xdwyXGcjwETTDceUQya+vSk H+KMwtI/f/y/wS1iyqdzpU/QktiomxtdtSGpZssxzpHPzkTvcjqWZAWHnrV6Ot0W5p T2rij7A3Zdh5GyZPzAhdFx+k+cGZr+iLrmpZBNDo= Received: from stargazer.. (unknown [IPv6:240e:457:1030:42a3:b2e5:c862:48d6:8912]) (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 342036694B; Fri, 2 Feb 2024 08:01:22 -0500 (EST) From: Xi Ruoyao To: binutils@sourceware.org Cc: mengqinggang@loongson.cn, changjiachen@stu.xupt.edu.cn, Nick Clifton , Xi Ruoyao Subject: [PATCH] LoongArch: gas: Fix the types of symbols referred with %le_*_r in the symtab Date: Fri, 2 Feb 2024 21:00:58 +0800 Message-ID: <20240202130057.84624-2-xry111@xry111.site> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789792255625345684 X-GMAIL-MSGID: 1789792255625345684 When a symbol is referred with %le_{hi20,lo12,add}_r, it's definitely a TLS symbol and we should set its type to TLS in the symtab. Otherwise when building Perl with gcc-14 -flto, we get: /usr/bin/ld: PL_current_context: TLS definition in ./miniperl.ltrans0.ltrans.o section .tbss mismatches non-TLS reference in ./miniperl.ltrans1.ltrans.o A minimal reproducer: $ cat t1.s .section .tbss .globl x x: .word 0 $ cat t2.s f: lu12i.w $a0, %le_hi20_r(x) add.d $a0, $a0, $tp, %le_add_r(x) li.w $a1, 1 st.w $a1, $a0, %le_lo12_r(x) $ gas/as-new t1.s -o t1.o $ gas/as-new t2.s -o t2.o $ ld/ld-new t1.o t2.o ld/ld-new: x: TLS definition in t1.o section .tbss mismatches non-TLS reference in t2.o Unfortunately this was undetected before Binutils-2.42 release because GCC < 14 does not use %le_*_r, and without LTO it's very rare to have a TLS LE definition and its reference in two different translation units. So this fix should be backported to Binutils-2.42 branch too. Signed-off-by: Xi Ruoyao --- gas/config/tc-loongarch.c | 3 +++ gas/testsuite/gas/loongarch/tls_le_r_sym_type.d | 3 +++ gas/testsuite/gas/loongarch/tls_le_r_sym_type.s | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 gas/testsuite/gas/loongarch/tls_le_r_sym_type.d create mode 100644 gas/testsuite/gas/loongarch/tls_le_r_sym_type.s diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index e0aff36bbbb..91f5f1d0681 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -1340,6 +1340,9 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) case BFD_RELOC_LARCH_TLS_DESC_LO12: case BFD_RELOC_LARCH_TLS_DESC64_LO20: case BFD_RELOC_LARCH_TLS_DESC64_HI12: + case BFD_RELOC_LARCH_TLS_LE_ADD_R: + case BFD_RELOC_LARCH_TLS_LE_HI20_R: + case BFD_RELOC_LARCH_TLS_LE_LO12_R: /* Add tls lo (got_lo reloc type). */ if (fixP->fx_addsy == NULL) as_bad_where (fixP->fx_file, fixP->fx_line, diff --git a/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d new file mode 100644 index 00000000000..43bcd789769 --- /dev/null +++ b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d @@ -0,0 +1,3 @@ +#readelf: -s +#... +.*TLS[ \t]+GLOBAL[ \t]+DEFAULT[ \t]+UND[ \t]+x diff --git a/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s new file mode 100644 index 00000000000..3ccedae921f --- /dev/null +++ b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s @@ -0,0 +1,6 @@ +f: + lu12i.w $a0, %le_hi20_r(x) + add.d $a0, $a0, $tp, %le_add_r(x) + li.w $a1, 1 + st.w $a1, $a0, %le_lo12_r(x) + ret