From patchwork Fri Dec 1 09:07:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: changjiachen X-Patchwork-Id: 172331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp983423vqy; Fri, 1 Dec 2023 01:08:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFajrebKI55s2tr3UWqnEqSlYxa00nTkOUip2ZYTTvkUHx0sD2g6tOOgBOXx8K/rnlgkYrc X-Received: by 2002:ac8:5882:0:b0:423:74a5:2847 with SMTP id t2-20020ac85882000000b0042374a52847mr26572780qta.49.1701421707285; Fri, 01 Dec 2023 01:08:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701421707; cv=pass; d=google.com; s=arc-20160816; b=Aopm0dkGXU7XrtihpTT3L+glPHvHovQVaPYul/2j0+xSflAOQeKzVtSre8hjfCgS+/ vlzo3y+0tNA6T1546zSuJUZcvf3uks3O8yUS6Rl9WV5pS6nEE4MzzeTpN7UT92a5Y0tt +LHQRDPmhO9hshJ7lB/Cl4B0G84TgBrdmC733Q2xT3ZxT+i/sslbpJYBDBo4jTlPmpfW BIeJGIAvFqOfn8evu7zt46CvROLoZO7tO8Im9G7BwJLXwmRqjdDhN2c6hA2pIUeJ2feS WPjwKOFspOojuE+Obln4cUWrhJ/dl17OwCMxXJLsqmGxMQ1qCXU1XRx0PBTWmmDu84qq naqg== 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=4eS8b/jgEjtXTc7J3HNOqPY7OMNsZPuu8JtZ9+8NLsI=; fh=W1lXzvrBv/RFWlDbqsdKVtGlKtndxGWKzaE/S+FMPJw=; b=CHevTDvijmZjumulPwTuBKhhT0lVClTVuKWA0FwFiY4E9UR/MBH/Xkd9uG+2Z3jy7i rMu64vTCNHQ9ofaCrzYyX+LYm55/YsmLpKbjnwiIfmuFO7Y50+S3zuxgCZT7EaCCZlxO ylPBFG3xr1btg5B66vSBX0lsqjnmBBKV91ghOEMTqVKBco0KWCVBgGkeLLigY5LiKcP3 GAGf58ChDuE/4bkOwl6BuPSgWYDOGRPmPiYLDzpxJrJymvHhDGG2x17gY6gSd0QPXzSc 5vK6UWpsjOpWU0tWk62xpWJt982u5gZ2FbuPtMdkNnp/2oI0Cd/bFJVHx2rqxR49OEPC AiyA== ARC-Authentication-Results: i=2; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xupt.edu.cn Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ew11-20020a05622a514b00b00423e912e24dsi3070643qtb.365.2023.12.01.01.08.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:08:27 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xupt.edu.cn Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BA24384F9BE for ; Fri, 1 Dec 2023 09:08:25 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m49198.qiye.163.com (mail-m49198.qiye.163.com [45.254.49.198]) by sourceware.org (Postfix) with ESMTPS id 66F80385C335 for ; Fri, 1 Dec 2023 09:08:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66F80385C335 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=stu.xupt.edu.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=stu.xupt.edu.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 66F80385C335 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=45.254.49.198 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701421686; cv=none; b=tI0bmhE113SzmCxl9bck9K42z5tG523MyFK363ikldSynCnNJEnsFvoJspoYyUTedsvk9OR54m/DZ/f45gyCppzMF+isgIHSWeq3DmoOj4pYxNQfNXWupLhw1+kNxQ177oEhySBUQQs5jX4BRd0JbAcO9BKN6/IH1qo9+658bZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701421686; c=relaxed/simple; bh=uBPgK62wOJ/HfJEE7SmuLAk5RNcXcQlUr4zyJgDnnLs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=NeRxQnjOwYnW8qUu70DbsYED5bPE1Q85eA+bjshbn1XnsJxnmYR3kKQ0TsyzgHx22x07GUhVi2dYJzX/IZLDUBWhghR78tv6A9Rbj9pzSZCFiNQc/UJ9/iKwCNBPDeb4PzgWn/F1gC1CPdQxEJsXdBDJUaJ6bDnmYLO1CoM3n7o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ubuntu.localdomain (unknown [124.89.2.83]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id 7A84BAC010B; Fri, 1 Dec 2023 17:07:59 +0800 (CST) From: changjiachen To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, cailulu@loongson.cn, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, Lazy_Linux@126.com, changjiachen Subject: [PATCH v1 5/5] LoongArch: ld: Add support for tls le relax. Date: Fri, 1 Dec 2023 17:07:30 +0800 Message-Id: <20231201090730.20521-6-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231201090730.20521-1-changjiachen@stu.xupt.edu.cn> References: <20231201090730.20521-1-changjiachen@stu.xupt.edu.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZTUNPVkNIHkkeQkJOQkkfQ1UTARMWGhIXJBQOD1 lXWRgSC1lBWUpJT1VDQlVJVUNIWVdZFhoPEhUdFFlBWU9LSFVKSktISkNVSktLVUtZBg++ X-HM-Tid: 0a8c24a28589b039kuuu7a84bac010b X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OQw6MCo4UTw4ChUoQlYIIioM GB9PFB9VSlVKTEtKT0lKTUNLQ0pCVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSU9VQ0JVSVVDSFlXWQgBWUFKSU5CTDcG X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, 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: 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: 1784069967734105268 X-GMAIL-MSGID: 1784069967734105268 Add tls le relax related testsuites in ld. The new test cases are mainly tested in three aspects: 1. tls le relax function correctness test. 2. tls le relax boundary check test. 3. tls le relax function compatibility test. ld/testsuite/ChangeLog: * ld/testsuite/ld-loongarch-elf/relax.exp: Modify test. * ld/testsuite/ld-loongarch-elf/old-tls-le.s: New test. * ld/testsuite/ld-loongarch-elf/relax-bound-check-tls-le.s: Likewise. * ld/testsuite/ld-loongarch-elf/relax-check-tls-le.s: Likewise. * ld/testsuite/ld-loongarch-elf/relax-tls-le.s: Likewise. * ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-old.s: Likewise. --- ld/testsuite/ld-loongarch-elf/old-tls-le.s | 19 +++ .../relax-bound-check-tls-le.s | 48 ++++++ .../ld-loongarch-elf/relax-check-tls-le.s | 43 ++++++ ld/testsuite/ld-loongarch-elf/relax-tls-le.s | 17 ++ ld/testsuite/ld-loongarch-elf/relax.exp | 146 +++++++++++++++++- .../tls-relax-compatible-check-old.s | 39 +++++ 6 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-loongarch-elf/old-tls-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/relax-bound-check-tls-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/relax-check-tls-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/relax-tls-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-old.s diff --git a/ld/testsuite/ld-loongarch-elf/old-tls-le.s b/ld/testsuite/ld-loongarch-elf/old-tls-le.s new file mode 100644 index 00000000000..290c4c61c18 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/old-tls-le.s @@ -0,0 +1,19 @@ + .text + .globl aa + .section .tbss,"awT",@nobits + .align 2 + .type aa, @object + .size aa, 4 +aa: + .space 4 + .text + .align 2 + .globl main + .type main, @function +main: + lu12i.w $r12,%le_hi20(aa) + ori $r12,$r12,%le_lo12(aa) + add.d $r12,$r12,$r2 + addi.w $r13,$r0,2 # 0x2 + stptr.w $r13,$r12,0 + diff --git a/ld/testsuite/ld-loongarch-elf/relax-bound-check-tls-le.s b/ld/testsuite/ld-loongarch-elf/relax-bound-check-tls-le.s new file mode 100644 index 00000000000..55e05fe12c2 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-bound-check-tls-le.s @@ -0,0 +1,48 @@ + .text + .globl count1 + .section .tbss,"awT",@nobits + .align 2 + .type count1, @object + .size count1, 4 +count1: + .space 0x400 + .globl count2 + .align 2 + .type count2, @object + .size count2, 4 +count2: + .space 0x400 + .globl count3 + .align 2 + .type count3, @object + .size count3, 4 +count3: + .space 0x400 + .globl count4 + .align 2 + .type count4, @object + .size count4, 4 +count4: + .space 4 + .text + .align 2 + .globl main + .type main, @function +main: + lu12i.w $r12,%tls_le_hi20(count1) + add.d $r12,$r12,$r2,%tprel_add(count1) + addi.w $r13,$r0,1 # 0x1 + st.w $r13,$r12,%tls_le_lo12(count1) + lu12i.w $r12,%tls_le_hi20(count2) + add.d $r12,$r12,$r2,%tprel_add(count2) + addi.w $r13,$r0,2 # 0x2 + st.w $r13,$r12,%tls_le_lo12(count2) + lu12i.w $r12,%tls_le_hi20(count3) + add.d $r12,$r12,$r2,%tprel_add(count3) + addi.w $r13,$r0,3 # 0x3 + st.w $r13,$r12,%tls_le_lo12(count3) + lu12i.w $r12,%tls_le_hi20(count4) + add.d $r12,$r12,$r2,%tprel_add(count4) + addi.w $r13,$r0,4 # 0x4 + st.w $r13,$r12,%tls_le_lo12(count4) + diff --git a/ld/testsuite/ld-loongarch-elf/relax-check-tls-le.s b/ld/testsuite/ld-loongarch-elf/relax-check-tls-le.s new file mode 100644 index 00000000000..fe564dd49e0 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-check-tls-le.s @@ -0,0 +1,43 @@ + .file "tls_relax_compatible_check_new.c" + .text + .globl new + .section .tbss,"awT",@nobits + .align 2 + .type new, @object + .size new, 4 +new: + .space 4 + .text + .align 2 + .globl main + .type main, @function +main: +.LFB0 = . + .cfi_startproc + addi.d $r3,$r3,-16 + .cfi_def_cfa_offset 16 + st.d $r1,$r3,8 + stptr.d $r22,$r3,0 + .cfi_offset 1, -8 + .cfi_offset 22, -16 + addi.d $r22,$r3,16 + .cfi_def_cfa 22, 0 + bl %plt(old) + lu12i.w $r12,%tls_le_hi20(new) + add.d $r12,$r12,$r2,%tprel_add(new) + addi.w $r13,$r0,2 # 0x2 + st.w $r13,$r12,%tls_le_lo12(new) + or $r12,$r0,$r0 + or $r4,$r12,$r0 + ld.d $r1,$r3,8 + .cfi_restore 1 + ldptr.d $r22,$r3,0 + .cfi_restore 22 + addi.d $r3,$r3,16 + .cfi_def_cfa_register 3 + jr $r1 + .cfi_endproc +.LFE0: + .size main, .-main + .ident "GCC: (GNU) 14.0.0 20230526 (experimental)" + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-loongarch-elf/relax-tls-le.s b/ld/testsuite/ld-loongarch-elf/relax-tls-le.s new file mode 100644 index 00000000000..1f8dcc3edda --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-tls-le.s @@ -0,0 +1,17 @@ + .text + .globl a + .section .tbss,"awT",@nobits + .align 2 + .type a, @object + .size a, 4 +a: + .space 4 + .text + .align 2 + .globl main + .type main, @function +main: + lu12i.w $r12,%tls_le_hi20(a) + add.d $r12,$r12,$r2,%tprel_add(a) + addi.w $r13,$r0,1 # 0x1 + st.w $r13,$r12,%tls_le_lo12(a) diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp index 7ff876d7914..1520cfc0dba 100644 --- a/ld/testsuite/ld-loongarch-elf/relax.exp +++ b/ld/testsuite/ld-loongarch-elf/relax.exp @@ -33,8 +33,90 @@ if [istarget loongarch64-*-*] { "relax" \ ] \ ] + set tls_relax_builds [list \ + [list \ + "tls_relax_builds" \ + "" \ + "" \ + {relax-tls-le.s} \ + {} \ + "relax-tls-le" \ + ] \ + ] + set tls_no_relax_builds [list \ + [list \ + "tls_no_relax_builds" \ + "-Wl,--no-relax" \ + "" \ + {relax-tls-le.s} \ + {} \ + "no-relax-tls-le" \ + ] \ + ] + + set relax_bound_check [list \ + [list \ + "relax_bound_check" \ + "" \ + "" \ + {relax-bound-check-tls-le.s} \ + {} \ + "relax-bound-check-tls-le" \ + ] \ + ] + set no_relax_bound_check [list \ + [list \ + "no_relax_bound_check" \ + "-Wl,--no-relax" \ + "" \ + {relax-bound-check-tls-le.s} \ + {} \ + "no-relax-bound-check-tls-le" \ + ] \ + ] + + set old_tls_le [list \ + [list \ + "old_tls_le" \ + "" \ + "" \ + {old-tls-le.s} \ + {} \ + "old-tls-le" \ + ] \ + ] + + set relax_compatible [list \ + [list \ + "relax_compatible" \ + "" \ + "" \ + {relax-check-tls-le.s tls-relax-compatible-check-old.s} \ + {} \ + "realx-compatible" \ + ] \ + ] + + set no_relax_compatible [list \ + [list \ + "no_relax_compatible" \ + "-Wl,--no-relax" \ + "" \ + {relax-check-tls-le.s tls-relax-compatible-check-old.s} \ + {} \ + "no-realx-compatible" \ + ] \ + ] + run_cc_link_tests $pre_builds + run_cc_link_tests $tls_relax_builds + run_cc_link_tests $tls_no_relax_builds + run_cc_link_tests $relax_bound_check + run_cc_link_tests $no_relax_bound_check + run_cc_link_tests $old_tls_le + run_cc_link_tests $relax_compatible + run_cc_link_tests $no_relax_compatible if [file exist "tmpdir/relax"] { set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax"] @@ -44,8 +126,70 @@ if [istarget loongarch64-*-*] { fail "loongarch relax" } } - } + if [file exist "tmpdir/relax-tls-le"] { + set objdump_output1 [run_host_cmd "objdump" "-d tmpdir/relax-tls-le"] + if { [ regexp ".addi.*st.*" $objdump_output1] } { + pass "loongarch relax success" + } { + fail "loongarch relax fail" + } + } + if [file exist "tmpdir/no-relax-tls-le"] { + set objdump_output2 [run_host_cmd "objdump" "-d tmpdir/no-relax-tls-le"] + if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output2] } { + pass "loongarch no-relax success" + } { + fail "loongarch no-relax fail" + } + } + if [file exist "tmpdir/old-tls-le"] { + set objdump_output3 [run_host_cmd "objdump" "-d tmpdir/old-tls-le"] + if { [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output3] } { + pass "loongarch old tls le success" + } { + fail "loongarch old tls le fail" + } + + } + + if [file exist "tmpdir/realx-compatible"] { + if { [catch {exec tmpdir/realx-compatible} number]} { + fail "loongarch tls le relax compatible check fail" + } { + pass "loongarch tls le relax compatible check success" + } + } + + if [file exist "tmpdir/no-realx-compatible"] { + if { [catch {exec tmpdir/no-realx-compatible} number] } { + fail "loongarch tls le no-relax compatible check fail" + } { + pass "loongarch tls le no-relax compatible check success" + } + } + + + if [file exist "tmpdir/relax-bound-check-tls-le"] { + set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/relax-bound-check-tls-le"] + if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output4] && \ + [ regexp ".addi.*st.*" $objdump_output4] } { + pass "loongarch no-relax success" + } { + fail "loongarch no-relax fail" + } + + } + if [file exist "tmpdir/no-relax-bound-check-tls-le"] { + set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/no-relax-bound-check-tls-le"] + if { [ regexp ".*addi.*st.*" $objdump_output4] } { + pass "loongarch no-relax success" + } { + fail "loongarch no-relax fail" + } + } + + } run_ld_link_tests \ [list \ [list \ diff --git a/ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-old.s b/ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-old.s new file mode 100644 index 00000000000..9adb657a87d --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-old.s @@ -0,0 +1,39 @@ + .file "tls_relax_compatible_check_old.c" + .text + .globl older + .section .tbss,"awT",@nobits + .align 2 + .type older, @object + .size older, 4 +older: + .space 4 + .text + .align 2 + .globl old + .type old, @function +old: +.LFB0 = . + .cfi_startproc + addi.d $r3,$r3,-16 + .cfi_def_cfa_offset 16 + st.d $r22,$r3,8 + .cfi_offset 22, -8 + addi.d $r22,$r3,16 + .cfi_def_cfa 22, 0 + lu12i.w $r12,%le_hi20(older) + ori $r12,$r12,%le_lo12(older) + add.d $r12,$r12,$r2 + addi.w $r13,$r0,1 # 0x1 + stptr.w $r13,$r12,0 + nop + or $r4,$r12,$r0 + ld.d $r22,$r3,8 + .cfi_restore 22 + addi.d $r3,$r3,16 + .cfi_def_cfa_register 3 + jr $r1 + .cfi_endproc +.LFE0: + .size old, .-old + .ident "GCC: (GNU) 13.0.1 20230316 (experimental)" + .section .note.GNU-stack,"",@progbits