From patchwork Tue Dec 19 06:40:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: changjiachen X-Patchwork-Id: 180778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1751400dyi; Mon, 18 Dec 2023 22:40:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFARZtZ7BrIbvdJ1aTUYC7BlnWyQKY36FNGjvYKOGh7EtTzDwH5K3LQ6XN0E262P+wulfG X-Received: by 2002:ac8:5d46:0:b0:423:a45a:e883 with SMTP id g6-20020ac85d46000000b00423a45ae883mr24881438qtx.51.1702968039771; Mon, 18 Dec 2023 22:40:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702968039; cv=pass; d=google.com; s=arc-20160816; b=0xCZPiKjMIiR0h3WPKHSvcx0lbx8B7gTsJTIuUafSYFE5d8Kux7+JXBLEjHesvELKg 1KAYNvy8w9K9YzP1BrAFXCmRjUjx1wV254f6NiWxHsgzicfiz7fGwz9GphBgIcjEaw3+ 26Tl7ceBRyfg9wd/Y1EvkIP/2eNGqPBuA1umT4VuSpL/aiKBjt+vJn+BIM8P8zpHqb0L OTp+Mq1iceCEpTbwOK051jS5WBXIrfnuu+GeUad5rRyb/zmULbT0NzfpqLaPXH3wdw4N D1/OAaq0WElIaok8eO10pKZtzkcCeO+qfsr8FSfuJU3eCtZfyxGdx3I41XYQstQ4IhwA JWbg== 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=11BS/kgty1n1mqnYT2mHVOebqd0dZ5jK4ooeEnbdDXk=; fh=uTF/VfpCAq2GtcL5NdCKul3VKQPlBSDYmUlZE/0CcYM=; b=mHpuJtYcESm19Nw5j4e+A5+2yiCLYpUGyKSOyujSrUAz6UdnqP6GDAyhTfPY7kY4XM y2ChqXijq+byjbnjjZU8Y+m80rR9lbGBat3tm1th+UYJNsvdGDjKoQtz2tysfLs/g3kH 8wZq+ACJ5MrfTC7Cl1HoQU30Rf6LO+8Y2T1SDUeRLCIgDjuMFVuwADV2ZgUTjRqhotoT h3E9JFdJt7i+y4HwgQ0QULDXeRVgtZ7zvsfAQkoufQJrTWg2GjpF4TS7afUR85GZpTFS opCtW83SKCEz4wSqm7C9/yyFGzf6NNUOikgIQcUBfj5k0B+cS4vfBcGdnGs265l3bwtI S90Q== 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 c11-20020ac8660b000000b00423804bda65si24465399qtp.13.2023.12.18.22.40.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 22:40:39 -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 E9F80385DC22 for ; Tue, 19 Dec 2023 06:40:37 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m49197.qiye.163.com (mail-m49197.qiye.163.com [45.254.49.197]) by sourceware.org (Postfix) with ESMTPS id AB6753858001 for ; Tue, 19 Dec 2023 06:40:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB6753858001 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 AB6753858001 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=45.254.49.197 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702968028; cv=none; b=IMZMaRu2PRyXukBy3vHJX4McDon2ql3L17hEKbOQw3ev+oNIj8kgItzcc5v29rUISi0y3RGJX/I2D6XcFQogfiit3By47LmMwGMwpWL3z0UQeFm4Qw3mQi0M5TlrTiQ3cExj5uF64OkoC3vB1MBjnhtjsTU3D6IJ+jMrDtVJ68U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702968028; c=relaxed/simple; bh=vKD9lgeJnd51CnKwe/wq7VwYAIedLQkWQmUJJ1ltYBA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=IrfCcmw9qu6IDHfGVImWG8lxKsugyzBwv4LfBIdhuJ8SITQE55k351cMK109evLEZwfJPZQTYnnNYnFJIRWishN+7Iy9ydZobS4/oRBBd709RY2ywEnLzbE71uvjltgsCcSwftRIPftB2U47/idC7lcY4RBrHLSL2wfDE/HrOz8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ubuntu.localdomain (unknown [111.18.37.203]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id D38B7AC00CA; Tue, 19 Dec 2023 14:40:20 +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, mengqinggang@loongson.cn, changjiachen Subject: [PATCH v4 4/5] oongArch: gas: Add support for tls le relax. Date: Tue, 19 Dec 2023 14:40:10 +0800 Message-Id: <20231219064011.90412-5-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231219064011.90412-1-changjiachen@stu.xupt.edu.cn> References: <20231219064011.90412-1-changjiachen@stu.xupt.edu.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlDTk4eVk0eGEJPQxpPGh0aTVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKSlVKQ1VITFVJS0hZV1kWGg8SFR0UWUFZT0tIVUpKS0hKQ1VKS0tVS1kG X-HM-Tid: 0a8c80cdd17fb039kuuud38b7ac00ca X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MEk6Kyo4Mjw*Ti83NAkTTU1J QwswCk5VSlVKTEtJQk1DS0lKQkNJVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSkpVSkNVSExVSUtIWVdZCAFZQUNLT043Bg++ X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: 1785691415405614709 X-GMAIL-MSGID: 1785691415405614709 Add tls le relax related relocs support and testsuites in gas. The main test is three new relocation items, R_LARCH_TLS_LE_ADD_R, R_LARCH_TLS_LE_HI20_R, R_LARCH_TLS_LE_LO12_R can be generated properly and tls le insn format check. gas/ChangeLog: * config/tc-loongarch.c: (loongarch_args_parser_can_match_arg_helper): Add support for relax. * gas/testsuite/gas/loongarch/reloc.d: Likewise. * gas/testsuite/gas/loongarch/reloc.s: Likewise. * gas/testsuite/gas/loongarch/loongarch.exp: Likewise. * gas/testsuite/gas/loongarch/tls_le_insn_format_check.s: New test. --- gas/config/tc-loongarch.c | 33 +++++++++++++++++-- gas/testsuite/gas/loongarch/loongarch.exp | 9 +++++ gas/testsuite/gas/loongarch/reloc.d | 18 ++++++++++ gas/testsuite/gas/loongarch/reloc.s | 11 +++++++ .../gas/loongarch/tls_le_insn_format_check.s | 5 +++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 gas/testsuite/gas/loongarch/tls_le_insn_format_check.s diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 59232832cf7..8a8e53ad3ce 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -636,6 +636,28 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, break; } break; + /* This is used for TLS, where the fourth operand is %le_add_r, + to get a relocation applied to an add instruction, for relaxation to use. + Two conditions, ip->match_now and reloc_num, are used to check tls insn + to prevent cases like add.d $a0,$a0,$a0,8. */ + case 't': + ip->match_now = + loongarch_parse_expr (arg, ip->reloc_info + ip->reloc_num, + reloc_num_we_have, &reloc_num, &imm) == 0; + + if (!ip->match_now) + break; + + if (reloc_num && + ip->reloc_info[ip->reloc_num].type == BFD_RELOC_LARCH_TLS_LE_ADD_R) + { + ip->reloc_num += reloc_num; + ip->reloc_info[ip->reloc_num].type = BFD_RELOC_LARCH_RELAX; + ip->reloc_info[ip->reloc_num].value = const_0; + ip->reloc_num++; + } + else ip->match_now = 0; + break; case 's': case 'u': ip->match_now = @@ -680,9 +702,8 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, as_fatal ( _("not support reloc bit-field\nfmt: %c%c %s\nargs: %s"), esc_ch1, esc_ch2, bit_field, arg); - if (ip->reloc_info[0].type >= BFD_RELOC_LARCH_B16 - && ip->reloc_info[0].type < BFD_RELOC_LARCH_64_PCREL) + && ip->reloc_info[0].type < BFD_RELOC_UNUSED) { /* As we compact stack-relocs, it is no need for pop operation. But break out until here in order to check the imm field. @@ -690,6 +711,14 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, ip->reloc_num += reloc_num; reloc_type = ip->reloc_info[0].type; + if (LARCH_opts.relax + && (BFD_RELOC_LARCH_TLS_LE_HI20_R == reloc_type + || BFD_RELOC_LARCH_TLS_LE_LO12_R == reloc_type)) + { + ip->reloc_info[ip->reloc_num].type = BFD_RELOC_LARCH_RELAX; + ip->reloc_info[ip->reloc_num].value = const_0; + ip->reloc_num++; + } if (LARCH_opts.relax && ip->macro_id && (BFD_RELOC_LARCH_PCALA_HI20 == reloc_type || BFD_RELOC_LARCH_PCALA_LO12 == reloc_type diff --git a/gas/testsuite/gas/loongarch/loongarch.exp b/gas/testsuite/gas/loongarch/loongarch.exp index 6d126fd4b0e..c0aa593d8a8 100644 --- a/gas/testsuite/gas/loongarch/loongarch.exp +++ b/gas/testsuite/gas/loongarch/loongarch.exp @@ -21,4 +21,13 @@ if [istarget loongarch*-*-*] { run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]] gas_test_old bfd_reloc_8.s "" "bfd_reloc_8" + if [file exist "tls_le_insn_format_check.s "] { + set format [run_host_cmd "as" "tls_le_insn_format_check.s"] + if { [ regexp ".*no match insn.*" $format] } { + pass "loongarch tls le insn format pass" + } { + pass "loongarch tls le insn format fail" + } + } + } diff --git a/gas/testsuite/gas/loongarch/reloc.d b/gas/testsuite/gas/loongarch/reloc.d index c3820c55f98..0458830f30b 100644 --- a/gas/testsuite/gas/loongarch/reloc.d +++ b/gas/testsuite/gas/loongarch/reloc.d @@ -165,3 +165,21 @@ Disassembly of section .text: [ ]+134:[ ]+R_LARCH_TLS_LE64_LO20[ ]+TLSL1\+0x8 [ ]+138:[ ]+03000085[ ]+lu52i.d[ ]+\$a1,[ ]+\$a0,[ ]+0 [ ]+138:[ ]+R_LARCH_TLS_LE64_HI12[ ]+TLSL1\+0x8 +[ ]+13c:[ ]+14000004[ ]+lu12i.w[ ]+\$a0,[ ]+0 +[ ]+13c:[ ]+R_LARCH_TLS_LE_HI20_R[ ]+TLSL1 +[ ]+13c:[ ]+R_LARCH_RELAX[ ]+\*ABS\* +[ ]+140:[ ]+001090a5[ ]+add.d[ ]+\$a1,[ ]+\$a1,[ ]+\$a0 +[ ]+140:[ ]+R_LARCH_TLS_LE_ADD_R[ ]+TLSL1 +[ ]+140:[ ]+R_LARCH_RELAX[ ]+\*ABS\* +[ ]+144:[ ]+29800085[ ]+st.w[ ]+\$a1,[ ]+\$a0,[ ]+0 +[ ]+144:[ ]+R_LARCH_TLS_LE_LO12_R[ ]+TLSL1 +[ ]+144:[ ]+R_LARCH_RELAX[ ]+\*ABS\* +[ ]+148:[ ]+14000004[ ]+lu12i.w[ ]+\$a0,[ ]+0 +[ ]+148:[ ]+R_LARCH_TLS_LE_HI20_R[ ]+TLSL1\+0x8 +[ ]+148:[ ]+R_LARCH_RELAX[ ]+\*ABS\* +[ ]+14c:[ ]+001090a5[ ]+add.d[ ]+\$a1,[ ]+\$a1,[ ]+\$a0 +[ ]+14c:[ ]+R_LARCH_TLS_LE_ADD_R[ ]+TLSL1\+0x8 +[ ]+14c:[ ]+R_LARCH_RELAX[ ]+\*ABS\* +[ ]+150:[ ]+29800085[ ]+st.w[ ]+\$a1,[ ]+\$a0,[ ]+0 +[ ]+150:[ ]+R_LARCH_TLS_LE_LO12_R[ ]+TLSL1\+0x8 +[ ]+150:[ ]+R_LARCH_RELAX[ ]+\*ABS\* diff --git a/gas/testsuite/gas/loongarch/reloc.s b/gas/testsuite/gas/loongarch/reloc.s index a67fecd9429..0a343c11225 100644 --- a/gas/testsuite/gas/loongarch/reloc.s +++ b/gas/testsuite/gas/loongarch/reloc.s @@ -142,3 +142,14 @@ lu12i.w $r4,%le_hi20(TLSL1 + 0x8) ori $r5,$r4,%le_lo12(TLSL1 + 0x8) lu32i.d $r4,%le64_lo20(TLSL1 + 0x8) lu52i.d $r5,$r4,%le64_hi12(TLSL1 + 0x8) + + +/* New TLS Insn. */ +lu12i.w $r4,%le_hi20_r(TLSL1) +add.d $r5,$r5,$r4,%le_add_r(TLSL1) +st.w $r5,$r4,%le_lo12_r(TLSL1) + +/* New TLS Insn with addend. */ +lu12i.w $r4,%le_hi20_r(TLSL1 + 0x8) +add.d $r5,$r5,$r4,%le_add_r(TLSL1 + 0x8) +st.w $r5,$r4,%le_lo12_r(TLSL1 + 0x8) diff --git a/gas/testsuite/gas/loongarch/tls_le_insn_format_check.s b/gas/testsuite/gas/loongarch/tls_le_insn_format_check.s new file mode 100644 index 00000000000..12b8b4769cc --- /dev/null +++ b/gas/testsuite/gas/loongarch/tls_le_insn_format_check.s @@ -0,0 +1,5 @@ +/* Assemble the following assembly statements using as. + If a "no match insn" exception is thrown, the test passes; + otherwise, the test fails. */ + +add.d $a0,$a0,$a0,8