From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.43.0