From patchwork Thu Dec 28 03:39:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: changjiachen X-Patchwork-Id: 183629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1790276dyb; Wed, 27 Dec 2023 19:41:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvOwV3Zz7442UZBYrpyn9WGAfu5JMQUnOXeU/rk/m1YCaavPWSn4OZ1K5XiH8QAZ1Szdp8 X-Received: by 2002:a0c:d7cd:0:b0:67f:f29f:93d6 with SMTP id g13-20020a0cd7cd000000b0067ff29f93d6mr5642813qvj.129.1703734891999; Wed, 27 Dec 2023 19:41:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703734891; cv=pass; d=google.com; s=arc-20160816; b=GwaeHaPi60gqJ8doSLprbySt1T9TQyohxeeYu6fAfnBeqLg9q+PBIQBg4FnQm/ifQS 4nVYF/ZDfGk6cb+o62OfQ6D3YoMZmfpLrLtgIyBpZZ55/m30/husMbrOtAyaXgr+QFh4 cf1uTDXmWeRd8AkswMp/aY3WY8aEoyaqcffQZOibLl0/ZTFCXIWb5+j0QHP84RKR/ZFj /NcUoBbLZDtN918KWgrs3m0J62Lpi1AMwyNQlUb7RFC8fegW5Cb8AzvEvZI8IJDzgCOF 5zbysHx5I8EuOVIlPZIGhbmfQ8hwhBEZxpiA178ofvhDcfuWlWHP/w0ukm+1t548vbiR WGTg== 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=I8FzS5tWhErLkxD5lRKbFaiPsmW0wvY38ZiH3+5tJbc=; fh=uTF/VfpCAq2GtcL5NdCKul3VKQPlBSDYmUlZE/0CcYM=; b=G5Kcl7XJZU1s8YcR7uQOzyFq50LqH4mDXWwgtx5U7oCS2hegFrAno2o/bBLHDD18z0 fdPoGgQRoPG3skVqknSFTEysp7gF2zlceMy+xj8oWlZ4BJLfKYgztRz6qwCEBU6o7BMR 6rZJALdiByvWlMjqiEdw1FkIl88HnqGLBCz3HYCzP6p7gC2Dc9Pu7eJxzVtUh4mGUGCi 9veHyrM3RjkAxrcJCo2CpHtl1U1n2mk5PH4whgsgMyrx4rhY7sdUx4V8qgvqypgwjJ0H C59efpN/A7S4cFk4Un3Hc5yBBean44oh1g6rXbI/Nj3z9Y3N4ahPBh/pc+ia3Qdevepd MHzA== 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 q5-20020a0ce205000000b0067f3a5e6af6si16351165qvl.267.2023.12.27.19.41.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 19:41:31 -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 AD8F53858296 for ; Thu, 28 Dec 2023 03:41:31 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m6030.netease.com (mail-m6030.netease.com [210.79.60.30]) by sourceware.org (Postfix) with ESMTPS id 7FEAE3858D32 for ; Thu, 28 Dec 2023 03:40:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FEAE3858D32 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 7FEAE3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=210.79.60.30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734817; cv=none; b=EJJo69O4DTHcArErSaVnTpUFdFR4kQfYEE67BOGHDclitoFo+lFQoxXDC0VD6rckuOUNHi8WqQ7cBr4C5VDBeToDs18H9trVAGmaaI+PYYPtV1bXhdpCzZsCby4MQjLdVAFtSGodGpybqgy8oMN78Iz2CMdciYNkOoa0crvsMs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734817; c=relaxed/simple; bh=Y3HbNwP039RSMz6fFktWensQVCQMRh5TZy/DR4MIWYY=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=fuvW+YtqZlW1F7I65gzNKVh2RTs1oY8cA5KAAWaMDsciL0klgnnE3+pZ8B9Y5yhbOZPXN9Wg8V6bu4AMM61B723VohpnsC/xBIKNGWq0asgybHLF7OcDsnHdYrtXIxbR8IvjS1/sl9aiufwQ9FA/1I4a7BlRlXQ/E8paVBWEyyQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ubuntu.localdomain (unknown [111.18.37.154]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id 7A3B1AC0095; Thu, 28 Dec 2023 11:40:01 +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 v5 1/5] LoongArch: bfd: Add support for tls le relax. Date: Thu, 28 Dec 2023 11:39:53 +0800 Message-Id: <20231228033957.108449-2-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> References: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkaSUtPVhoeQk5LTUtLHR4YH1UTARMWGhIXJBQOD1 lXWRgSC1lBWUpKSlVKQ1VITFVKTk9ZV1kWGg8SFR0UWUFZT0tIVUpNQ0xDS1VKS0tVSkJLS1kG X-HM-Tid: 0a8cae81f667b039kuuu7a3b1ac0095 X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PU06Kww4PDwwLw9RDTgoAkJL STZPCR5VSlVKTEtITEhPQ0tJQ09MVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSkpVSkNVSExVSk5PWVdZCAFZQUpJSUhCNwY+ X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: 1786495517650557629 X-GMAIL-MSGID: 1786495517650557629 Add tls le relax support and related relocs in bfd. New relocation related explanation can refer to the following url: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc This support does two main things: 1. Implement support for three new relocation items in bfd. The three new relocation items are shown below: R_LARCH_TLS_LE_ADD_R R_LARCH_TLS_LE_HI20_R R_LARCH_TLS_LE_LO12_R 2. ADD a new macro RELOCATE_TLS_TP32_HI20 Handle problems caused by symbol extensions in TLS LE, The processing is similar to the macro RELOCATE_CALC_PC32_HI20 method. 3. Implement the tls le relax function. bfd/ChangeLog: * bfd-in2.h: Add relocs related to tls le relax. * elfnn-loongarch.c: (loongarch_relax_tls_le): New function. (RELOCATE_TLS_TP32_HI20): New macro. (loongarch_elf_check_relocs): Add new reloc support. (perform_relocation): Likewise. (loongarch_elf_relocate_section): Handle new relocs related to relax. (loongarch_elf_relax_section): Likewise. * elfxx-loongarch.c: (LOONGARCH_HOWTO (R_LARCH_TLS_LE_ADD_R)): New reloc how to type. (LOONGARCH_HOWTO (R_LARCH_TLS_LE_HI20_R)): Likewise. (LOONGARCH_HOWTO (R_LARCH_TLS_LE_LO12_R)): Likewise. * libbfd.h: Add relocs related to tls le relax. * reloc.c: Likewise. --- bfd/bfd-in2.h | 4 +++ bfd/elfnn-loongarch.c | 75 +++++++++++++++++++++++++++++++++++++++++++ bfd/elfxx-loongarch.c | 55 ++++++++++++++++++++++++++++--- bfd/libbfd.h | 3 ++ bfd/reloc.c | 7 ++++ 5 files changed, 139 insertions(+), 5 deletions(-) diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 782845926ea..c522fef5641 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7473,11 +7473,15 @@ enum bfd_reloc_code_real BFD_RELOC_LARCH_TLS_DESC64_HI12, BFD_RELOC_LARCH_TLS_DESC_LD, BFD_RELOC_LARCH_TLS_DESC_CALL, + BFD_RELOC_LARCH_TLS_LE_HI20_R, + BFD_RELOC_LARCH_TLS_LE_ADD_R, + BFD_RELOC_LARCH_TLS_LE_LO12_R, BFD_RELOC_LARCH_TLS_LD_PCREL20_S2, BFD_RELOC_LARCH_TLS_GD_PCREL20_S2, BFD_RELOC_LARCH_TLS_DESC_PCREL20_S2, BFD_RELOC_UNUSED }; + typedef enum bfd_reloc_code_real bfd_reloc_code_real_type; reloc_howto_type *bfd_reloc_type_lookup diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index bd448cda453..9a0bcb011ac 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -858,6 +858,7 @@ loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, break; case R_LARCH_TLS_LE_HI20: + case R_LARCH_TLS_LE_HI20_R: case R_LARCH_SOP_PUSH_TLS_TPREL: if (!bfd_link_executable (info)) return false; @@ -2261,6 +2262,8 @@ perform_relocation (const Elf_Internal_Rela *rel, asection *input_section, case R_LARCH_GOT64_HI12: case R_LARCH_TLS_LE_HI20: case R_LARCH_TLS_LE_LO12: + case R_LARCH_TLS_LE_HI20_R: + case R_LARCH_TLS_LE_LO12_R: case R_LARCH_TLS_LE64_LO20: case R_LARCH_TLS_LE64_HI12: case R_LARCH_TLS_IE_PC_HI20: @@ -2303,6 +2306,7 @@ perform_relocation (const Elf_Internal_Rela *rel, asection *input_section, break; case R_LARCH_RELAX: + case R_LARCH_TLS_LE_ADD_R: break; default: @@ -2483,6 +2487,16 @@ loongarch_reloc_is_fatal (struct bfd_link_info *info, relocation += 0x1000; \ }) +/* Handle problems caused by symbol extensions in TLS LE, The processing + is similar to the macro RELOCATE_CALC_PC32_HI20 method. */ +#define RELOCATE_TLS_TP32_HI20(relocation) \ + ({ \ + bfd_vma __lo = (relocation) & ((bfd_vma)0xfff); \ + if (__lo > 0x7ff) \ + relocation += 0x800; \ + relocation = relocation & ~(bfd_vma)0xfff; \ + }) + /* For example: pc is 0x11000010000100, symbol is 0x1812348ffff812 offset = (0x1812348ffff812 & ~0xfff) - (0x11000010000100 & ~0xfff) = 0x712347ffff000 @@ -3481,6 +3495,13 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, break; + case R_LARCH_TLS_LE_HI20_R: + relocation -= elf_hash_table (info)->tls_sec->vma; + + RELOCATE_TLS_TP32_HI20 (relocation); + + break; + case R_LARCH_PCALA_LO12: /* Not support if sym_addr in 2k page edge. pcalau12i pc_hi20 (sym_addr) @@ -3651,6 +3672,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, case R_LARCH_TLS_LE_HI20: case R_LARCH_TLS_LE_LO12: + case R_LARCH_TLS_LE_LO12_R: case R_LARCH_TLS_LE64_LO20: case R_LARCH_TLS_LE64_HI12: BFD_ASSERT (resolved_local && elf_hash_table (info)->tls_sec); @@ -4089,6 +4111,52 @@ loongarch_relax_delete_bytes (bfd *abfd, return true; } +/* Relax tls le, mainly relax the process of getting TLS le symbolic addresses. + +before relax: after relax: + +lu12i.w $r12,%le_hi20_r (sym) ==> (instruction deleted). +add.d $r12,$r12,$r2,%le_add_r (sym) ==> (instruction deleted). +st/addi/ld.w $r13,$r12,%le_lo12_r (sym) ==> st/addi/ld.w $r13,$r2,%le_lo12_r (sym). */ +static bool +loongarch_relax_tls_le (bfd *abfd, asection *sec, + Elf_Internal_Rela *rel, + struct bfd_link_info *link_info, + bfd_vma symval) +{ + bfd_byte *contents = elf_section_data (sec)->this_hdr.contents; + uint32_t insn = bfd_get (32, abfd, contents + rel->r_offset); + static uint32_t insn_rj,insn_rd; + symval = symval - elf_hash_table (link_info)->tls_sec->vma; + /* Whether the symbol offset is in the interval (offset < 0x800). */ + if (ELFNN_R_TYPE ((rel + 1)->r_info == R_LARCH_RELAX) && (symval < 0x800)) + { + switch (ELFNN_R_TYPE (rel->r_info)) + { + case R_LARCH_TLS_LE_HI20_R: + case R_LARCH_TLS_LE_ADD_R: + /* delete insn. */ + rel->r_info = ELFNN_R_INFO (0, R_LARCH_NONE); + loongarch_relax_delete_bytes (abfd, sec, rel->r_offset, 4, link_info); + break; + case R_LARCH_TLS_LE_LO12_R: + /* Change rj to $tp. */ + insn_rj = 0x2 << 5; + /* Get rd register. */ + insn_rd = insn & 0x1f; + /* Write symbol offset. */ + symval <<= 10; + /* Writes the modified instruction. */ + insn = insn & 0xffc00000; + insn = insn | symval | insn_rj | insn_rd; + bfd_put (32, abfd, insn, contents + rel->r_offset); + break; + default: + break; + } + } + return true; +} /* Relax pcalau12i,addi.d => pcaddi. */ static bool @@ -4518,6 +4586,13 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec, rel->r_info = ELFNN_R_INFO (0, R_LARCH_NONE); } break; + case R_LARCH_TLS_LE_HI20_R: + case R_LARCH_TLS_LE_LO12_R: + case R_LARCH_TLS_LE_ADD_R: + if (0 == info->relax_pass && (i + 2) <= sec->reloc_count) + loongarch_relax_tls_le (abfd, sec, rel, info, symval); + break; + case R_LARCH_PCALA_HI20: if (0 == info->relax_pass && (i + 4) <= sec->reloc_count) loongarch_relax_pcala_addi (abfd, sec, sym_sec, rel, symval, diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c index 4fe8cbff14c..2c40fb02872 100644 --- a/bfd/elfxx-loongarch.c +++ b/bfd/elfxx-loongarch.c @@ -1776,9 +1776,56 @@ static loongarch_reloc_howto_type loongarch_howto_table[] = NULL, /* adjust_reloc_bits. */ "desc_call"), /* larch_reloc_type_name. */ - LOONGARCH_EMPTY_HOWTO (121), - LOONGARCH_EMPTY_HOWTO (122), - LOONGARCH_EMPTY_HOWTO (123), + LOONGARCH_HOWTO (R_LARCH_TLS_LE_HI20_R, /* type (121). */ + 12, /* rightshift. */ + 4, /* size. */ + 20, /* bitsize. */ + false, /* pc_relative. */ + 5, /* bitpos. */ + complain_overflow_signed, /* complain_on_overflow. */ + bfd_elf_generic_reloc, /* special_function. */ + "R_LARCH_TLS_LE_HI20_R", /* name. */ + false, /* partial_inplace. */ + 0, /* src_mask. */ + 0x1ffffe0, /* dst_mask. */ + false, /* pcrel_offset. */ + BFD_RELOC_LARCH_TLS_LE_HI20_R, /* bfd_reloc_code_real_type. */ + reloc_bits, /* adjust_reloc_bits. */ + "le_hi20_r"), /* larch_reloc_type_name. */ + + LOONGARCH_HOWTO (R_LARCH_TLS_LE_ADD_R, /* type (122). */ + 0, /* rightshift. */ + 0, /* size. */ + 0, /* bitsize. */ + false, /* pc_relative. */ + 0, /* bitpos. */ + complain_overflow_dont, /* complain_on_overflow. */ + bfd_elf_generic_reloc, /* special_function. */ + "R_LARCH_TLS_LE_ADD_R", /* name. */ + false, /* partial_inplace. */ + 0, /* src_mask. */ + 0, /* dst_mask. */ + false, /* pcrel_offset. */ + BFD_RELOC_LARCH_TLS_LE_ADD_R, /* bfd_reloc_code_real_type. */ + NULL, /* adjust_reloc_bits. */ + "le_add_r"), /* larch_reloc_type_name. */ + + LOONGARCH_HOWTO (R_LARCH_TLS_LE_LO12_R, /* type (123). */ + 0, /* rightshift. */ + 4, /* size. */ + 12, /* bitsize. */ + false, /* pc_relative. */ + 10, /* bitpos. */ + complain_overflow_signed, /* complain_on_overflow. */ + bfd_elf_generic_reloc, /* special_function. */ + "R_LARCH_TLS_LE_LO12_R", /* name. */ + false, /* partial_inplace. */ + 0, /* src_mask. */ + 0x3ffc00, /* dst_mask. */ + false, /* pcrel_offset. */ + BFD_RELOC_LARCH_TLS_LE_LO12_R, /* bfd_reloc_code_real_type. */ + reloc_bits, /* adjust_reloc_bits. */ + "le_lo12_r"), /* larch_reloc_type_name. */ /* For pcaddi, ld_pc_hi20 + ld_pc_lo12 can relax to ld_pcrel20_s2. */ LOONGARCH_HOWTO (R_LARCH_TLS_LD_PCREL20_S2, /* type (124). */ @@ -1870,9 +1917,7 @@ reloc_howto_type * loongarch_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code) { - /* BFD_ASSERT (ARRAY_SIZE (loongarch_howto_table) == R_LARCH_count); - */ /* Fast search for new reloc types. */ if (BFD_RELOC_LARCH_B16 <= code && code < BFD_RELOC_LARCH_RELAX) diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 8dab44110a6..82ffd773513 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -3612,6 +3612,9 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_LARCH_TLS_DESC64_HI12", "BFD_RELOC_LARCH_TLS_DESC_LD", "BFD_RELOC_LARCH_TLS_DESC_CALL", + "BFD_RELOC_LARCH_TLS_LE_HI20_R", + "BFD_RELOC_LARCH_TLS_LE_ADD_R", + "BFD_RELOC_LARCH_TLS_LE_LO12_R", "BFD_RELOC_LARCH_TLS_LD_PCREL20_S2", "BFD_RELOC_LARCH_TLS_GD_PCREL20_S2", "BFD_RELOC_LARCH_TLS_DESC_PCREL20_S2", diff --git a/bfd/reloc.c b/bfd/reloc.c index 6fd0f1fb547..1030bc37647 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -8324,6 +8324,13 @@ ENUMX ENUMX BFD_RELOC_LARCH_TLS_DESC_CALL +ENUMX + BFD_RELOC_LARCH_TLS_LE_HI20_R +ENUMX + BFD_RELOC_LARCH_TLS_LE_ADD_R +ENUMX + BFD_RELOC_LARCH_TLS_LE_LO12_R + ENUMX BFD_RELOC_LARCH_TLS_LD_PCREL20_S2 ENUMX From patchwork Thu Dec 28 03:39:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: changjiachen X-Patchwork-Id: 183627 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1790033dyb; Wed, 27 Dec 2023 19:40:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8MVMHZcbLPou+mRnY42TqW02sZE5YaA+1a0NozOSwMCW0zs8KoZl79fdoJOGp/QPMJa22 X-Received: by 2002:a05:6214:5017:b0:67a:bb37:d9b5 with SMTP id jo23-20020a056214501700b0067abb37d9b5mr17564743qvb.21.1703734827484; Wed, 27 Dec 2023 19:40:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703734827; cv=pass; d=google.com; s=arc-20160816; b=nADBsC9HO32L4NblQF/LSIMStY0QhRNRKJZkrdAyZftdRZcQRvy/ugBhJ7eL/14sek i8dTRzID7Ls1XXBykdtG+rLt2X725OZb4/OQI9ZedbZzJSg4KHmev+/9PH+eBdOF05JL aBk5Ux5hED36x2W7s9Rnq3swD12agq6BKM/znwlaBSNJlWx6DezzehK8QPdJzbMXRj1w sYpx3JY/JvhthwnoEozJFgmiMNxsh10sP3/EzLGTAgCuhtOIZW2aY5KnJcg7MoCX4wBp 9bwUVdogPObhR/QxIihF9G7rtMNZhO+/cQtpiwNVAHwxWvYEHRkY1NMGw8TNmVIlAMDI XSjQ== 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=xCqUephYev1cHBwbrac+pwRlQj8Ks3ELLyA89UgGU3U=; fh=uTF/VfpCAq2GtcL5NdCKul3VKQPlBSDYmUlZE/0CcYM=; b=e3FFDy2n2eVw9VWkHQ7lK0xtthDidPrW0KteTbOdfADAUGnNSDmWXQ45TA/bx6nghV ZB3QXv49rc4r/IlIgfd4H7L0JGF5MP/TJ4u7n/MfPCJBzNPYQMFJW7HHBgqeIAFeH9WD dHLWOZPv0zMcRSeyUV3EFin33bH/xoIxFLKjPuhaRERshQTxsA9hJbX28B3JYuNEgYSY O23R7/h2wtqdR+0GFPtQmgauJuWRT3vBPXh1UtkWEvZ0EQ+6x0bYzZOeepnRtz7ns3XN 8Q4gpIbR4l1WxI8c8mRpy7K4yLGvxLqdyvTAksPKI3aYUHCSKIYUgWzUKER1ZPn4l4q4 kLmg== 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 jp8-20020ad45f88000000b006804878839bsi4542259qvb.358.2023.12.27.19.40.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 19:40: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 2E0A73858C41 for ; Thu, 28 Dec 2023 03:40:27 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m6030.netease.com (mail-m6030.netease.com [210.79.60.30]) by sourceware.org (Postfix) with ESMTPS id 7D4873858D28 for ; Thu, 28 Dec 2023 03:40:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D4873858D28 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 7D4873858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=210.79.60.30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734816; cv=none; b=UDvtwtvBeubRfBYE3x7Rkarot+65z6cLzI3HasWzW2QwXcB38YwXBNPiTD9A2gEypl4foXyJD3C6tWId6VP29FljEm1AWinEUGYMnJoVHODbNwONZmJ74Ce9DFcmqFTcmr+9CjptuxXwlJnuHg2GfZJsBMaDq6dv0/J9LXlyUWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734816; c=relaxed/simple; bh=B9aKAOAdsp51IH/MHqSGWL1duEGOHAi4K/xsO7k6pQ4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=OhxqEgdFMtE5BzYL2l//JhyegdGo3p3UbPMu5gPWcW0OYEjzGbWAliy01ifs3oE3EIltpmkks+UC3w7TXlF6KlyXdY48EPYAS3MqTpyt55ABIDGl0fSmj91jsKFbUnjWY+IxuMGSity7TBAj7ILg972eWxWcKPv/V34Ig8p75dw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ubuntu.localdomain (unknown [111.18.37.154]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id 64B53AC00AD; Thu, 28 Dec 2023 11:40:03 +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 v5 2/5] LoongArch: include: Add support for tls le relax. Date: Thu, 28 Dec 2023 11:39:54 +0800 Message-Id: <20231228033957.108449-3-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> References: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlDTh1OVkhLTxodQxlOSEhNT1UTARMWGhIXJBQOD1 lXWRgSC1lBWUpKSlVKQ1VITFVKTk9ZV1kWGg8SFR0UWUFZT0tIVUpNQ0xDS1VKS0tVSkJLS1kG X-HM-Tid: 0a8cae81fdd8b039kuuu64b53ac00ad X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OlE6Ayo5LTw#Mw8LQjpWAktD Q08wC0xVSlVKTEtITEhPQ0tPTUJCVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSkpVSkNVSExVSk5PWVdZCAFZQUlNSEw3Bg++ X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: 1786495450296428579 X-GMAIL-MSGID: 1786495450296428579 Add new relocs number for tls le relax. include/ChangeLog: * elf/loongarch.h: (RELOC_NUMBER (R_LARCH_TLS_LE_HI20_R, 121)): New relocs number. (RELOC_NUMBER (R_LARCH_TLS_LE_ADD_R, 122)): Likewise. (RELOC_NUMBER (R_LARCH_TLS_LE_LO12_R, 123)): Likewise. --- include/elf/loongarch.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/elf/loongarch.h b/include/elf/loongarch.h index 6cfee164312..1deb6ba11cf 100644 --- a/include/elf/loongarch.h +++ b/include/elf/loongarch.h @@ -273,6 +273,18 @@ RELOC_NUMBER (R_LARCH_TLS_DESC64_HI12, 118) RELOC_NUMBER (R_LARCH_TLS_DESC_LD, 119) RELOC_NUMBER (R_LARCH_TLS_DESC_CALL, 120) +/* TLS-LE-LUI + lu12i.w rd,%le_hi20_r (sym). */ +RELOC_NUMBER (R_LARCH_TLS_LE_HI20_R, 121) + +/* TLS-LE-ADD + add.d rd,rj,rk,%le_add_r (sym). */ +RELOC_NUMBER (R_LARCH_TLS_LE_ADD_R, 122) + +/* TLS-LE-ST + st.w/addi.w/ld.w rd,rj,%le_lo12_r (sym). */ +RELOC_NUMBER (R_LARCH_TLS_LE_LO12_R, 123) + RELOC_NUMBER (R_LARCH_TLS_LD_PCREL20_S2, 124) RELOC_NUMBER (R_LARCH_TLS_GD_PCREL20_S2, 125) RELOC_NUMBER (R_LARCH_TLS_DESC_PCREL20_S2, 126) From patchwork Thu Dec 28 03:39:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: changjiachen X-Patchwork-Id: 183628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1790108dyb; Wed, 27 Dec 2023 19:40:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbHIZniFxzwepnhHnpL4BmJ4aJXs05AWL09IGnCvO+OLse36Uuuk/A7NHlmLwPMmyvDWjI X-Received: by 2002:a05:622a:3ce:b0:423:9d2a:bc51 with SMTP id k14-20020a05622a03ce00b004239d2abc51mr16207865qtx.28.1703734848884; Wed, 27 Dec 2023 19:40:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703734848; cv=pass; d=google.com; s=arc-20160816; b=kYO7BmfrqQvfCT+SojFmpP3vutJYZyrUYTg7oLzHfNsizPkl1LoqT8RjD+eyLEF2Uc 9tTdauSKLe+JHFowiO+wo15IpgrtSB7+fuwK2JpkNvMD72F8pq9ruPKclBzcdX4L+CXA 8Psh5VV95kraEf18a2QMg9UexGLIEDlxClzzNlLa4Hk/BwoXk9/sjEYEFkEXo0cnvMz8 SsGSH0ngRKDJKna4DwP5IAkJ8IhA1sOC3ZZu9E3zAWjZluz2z7Q7ZAyz5LTGWJTmmG1t 8AspnTRZNUsRhibfganj3AUiyWzENem2snu61lERfYFhesRzpVOo0COb0m8ghUyNfh3B Z68g== 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=eiU064kRi4+L+bgJMG5bobLL3gF9hoz8+koV4k1nYf4=; fh=uTF/VfpCAq2GtcL5NdCKul3VKQPlBSDYmUlZE/0CcYM=; b=yx5YWbtAXLSJKWJwnUOp3yUiReUFA3+EZkk2ykTAdLCkQZCyiMAtU4jZoW5FIfqk14 IRh4w1bCJ2hxD9TBRehcMr97GEDLOGPMWDMEhJtcyd1eHHbdtKxkvHazW3qFq0q1DBjN uhnfj/gXKMnN2+ogvNPAmCyBn5+hkLeLKCEpmCrvHrE5bfZEao32FEf6nQsdObri8d5r 97e7BFH7f40B6dRmM6WJXbOz+e/6sQwKHTZFKLYXnucSCs3S+nH16vpp7i5830AdYo3G fYUaUZzRy/4rsm9ASqZR90rajvmJ4kM9GrtXZoyK0uZyL5g3D/coEw2m63RjDKFaea7d Q4BA== 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 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x19-20020ac85f13000000b00425497dcb86si16182237qta.387.2023.12.27.19.40.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 19:40:48 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 469B13858C41 for ; Thu, 28 Dec 2023 03:40:48 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m1287.netease.com (mail-m1287.netease.com [103.209.128.7]) by sourceware.org (Postfix) with ESMTPS id C5FFD3858D38 for ; Thu, 28 Dec 2023 03:40:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5FFD3858D38 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 C5FFD3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=103.209.128.7 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734816; cv=none; b=ZaEUZ2lytxvX/48lAE10hf4YQvhg1EVeDQwrrRRVtDutKDZJMJENk1ucGOMmpmO+QgZ6yD8Trxn9HNgn0becSCluP7cM3hvm/RPg50z1MCcNxkGV3QNde3LTMwEvpsTAA2TezrCXGcCLzsrZXCbhoHM36QB0Z6crZ5ub7YMj/4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734816; c=relaxed/simple; bh=qokLuTahjeCmKX2jxfz/KEnX4b2UaiBOsrwEZHRZ4wc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=rkkK+h2BAv0zwcQTeoXiV5vHMWIMvfwQp+ZF9DE6WPwNsB5QvZXtG5xJtAHxTn43M8pzK7SnRgeMQ32cYQGhh9ioNXzchUt3XdK3w9sl55UYLcCwP1ANmt1A7Wj8eHqFACw2k3wF9vWeBI7N94hNv7CSglg26WdWsOVCUSFrbXo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ubuntu.localdomain (unknown [111.18.37.154]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id 38943AC00AE; Thu, 28 Dec 2023 11:40:05 +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 v5 3/5] LoongArch: opcodes: Add support for tls le relax. Date: Thu, 28 Dec 2023 11:39:55 +0800 Message-Id: <20231228033957.108449-4-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> References: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCThpJVkwZTEtOTxlIThkdHVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKSlVKQ1VITFVKTk9ZV1kWGg8SFR0UWUFZS1VLVUtVS1kG X-HM-Tid: 0a8cae8204f5b039kuuu38943ac00ae X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Ni46GRw6MDwwGQ8hQjgXAk4j ORYaFC5VSlVKTEtITEhPQ0tNTkxCVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSkpVSkNVSExVSk5PWVdZCAFZQUlPTkM3Bg++ X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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: 1786495472772040059 X-GMAIL-MSGID: 1786495472772040059 Add new opcode for tls le relax. opcode/ChangeLog: * loongarch-opc.c: Add new loongarch opcode. --- opcodes/loongarch-opc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c index a632373f5ed..44b5f612896 100644 --- a/opcodes/loongarch-opc.c +++ b/opcodes/loongarch-opc.c @@ -464,6 +464,7 @@ static struct loongarch_opcode loongarch_fix_opcodes[] = { 0x000c0000, 0xfffc0000, "bytepick.d", "r0:5,r5:5,r10:5,u15:3", 0, 0, 0, 0 }, { 0x00100000, 0xffff8000, "add.w", "r0:5,r5:5,r10:5", 0, 0, 0, 0 }, { 0x00108000, 0xffff8000, "add.d", "r0:5,r5:5,r10:5", 0, 0, 0, 0 }, + { 0x00108000, 0xffff8000, "add.d", "r0:5,r5:5,r10:5,t", 0, 0, 0, 0 }, { 0x00110000, 0xffff8000, "sub.w", "r0:5,r5:5,r10:5", 0, 0, 0, 0 }, { 0x00118000, 0xffff8000, "sub.d", "r0:5,r5:5,r10:5", 0, 0, 0, 0 }, { 0x00120000, 0xffff8000, "slt", "r0:5,r5:5,r10:5", 0, 0, 0, 0 }, From patchwork Thu Dec 28 03:39:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: changjiachen X-Patchwork-Id: 183630 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1790336dyb; Wed, 27 Dec 2023 19:41:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvoO77vwV2h0ihjj8L3KqAsxWnhb/2VQ1EFWmazfo4xALVzbkNCijKd5VDb6k5FXwfowL7 X-Received: by 2002:a05:622a:94:b0:403:2877:bc52 with SMTP id o20-20020a05622a009400b004032877bc52mr10998394qtw.0.1703734908654; Wed, 27 Dec 2023 19:41:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703734908; cv=pass; d=google.com; s=arc-20160816; b=O4/2hxMs44xInlGFQIvHsOJWxuCGhjefIBt7jHfeHHHd4tgc+4lI55fZWxTQo4EvlK /Gx6td68gX5f3mZ5xTjkq9URXv7/rZUMr+GLdt1bb6RjuMW3+VntkaE+JNe50Pt0PdLI EvzO9vMnLWWRAF7o0z6ky1rFngitZFdO4mF3rNGlleQN9v2o3W3ByUIQYofuc3G1Qx6N LZOi9SaBzepBdnYMNdS2gmZ+tP3ldPhruRKPtRL7W4sUve50qgGXfQu+KfYinAL1n794 X2dyZorTZtAR8hsSSQgS9EAkG2iwJIV48nE6lDZIjeDpU1Ye/AlzJe95bk9j57hqEAmt mwig== 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=Hb92blLnOiYvmNz2AHlCqZolPUKUdyqQxoM5ZMi+/aI=; fh=uTF/VfpCAq2GtcL5NdCKul3VKQPlBSDYmUlZE/0CcYM=; b=fkAxDmsKQ5Mh8XJ0kRiRjLgb304QDOsPBcdYpGO/wsiRYjq71tL4GqjmpL8kA8vZA9 1dPGqJG6zAdJi5N2HpAFoduMRdiS2YNCuqjmCvUbXJ3D1/z2fP5b1588YAHh82aCL1DF 7kVleN3rJ0DG6aqljn/LjdfQdYf+h3rB+2QEfPgs8XF2pBH1564T2+9NeorPawACIOTB tC7vzJzWGZgg4T+9wiu7iF060pVBlmtMVsiOEv6zk/ht3Dv3gwZ2rsG6sp6bnuhYpJPS RiWj2bYts9QZtbfHvRmqydUw65HCcunHGM5QGo9vfXT6itJ/Tm+vF2yILfnB3VNSvZBH 2vAw== 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 y13-20020a05622a164d00b00423a15081f0si15460519qtj.682.2023.12.27.19.41.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 19:41:48 -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 5C0433858403 for ; Thu, 28 Dec 2023 03:41:48 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m6030.netease.com (mail-m6030.netease.com [210.79.60.30]) by sourceware.org (Postfix) with ESMTPS id 593D23858D39 for ; Thu, 28 Dec 2023 03:40:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 593D23858D39 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 593D23858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=210.79.60.30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734817; cv=none; b=rcR3/kbVN1KG/MLWipCEFEhM7A58oYr/RADkmCAw9P6D2N8PpXDZfs6C4wI3z628Qxf86x28HPl6YzvZB/a2nTjGDEibXCkkxAbsrCb5E862JxpEgd8Grz616yFg0QHgZFJjPZgMoTfaDuXHkQ7JswfG+EyU7MvWlxrakip5BNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734817; c=relaxed/simple; bh=jPd6sIHXUhJTzpXI7+Fd0jYHrfCOXUqT2CPVgatwWjM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=alo54qY93oNwc3HHUYHtULvoORgL5Ik7UypX7XroMM9XbBTrxErQPyJwV2wk4KZvwou1klvsw8f4vQ1CCuI5FFlsaMmSEDpKqASJ1BE3O9D43wLiMEq+TMv8iEtyrgA/piCRTNl7jp+u6BJqpjDcYxr3dif8ys/oiEQ3xfnRDVc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ubuntu.localdomain (unknown [111.18.37.154]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id 0EDD0AC00B7; Thu, 28 Dec 2023 11:40:07 +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 v5 4/5] LoongArch: gas: Add support for tls le relax. Date: Thu, 28 Dec 2023 11:39:56 +0800 Message-Id: <20231228033957.108449-5-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> References: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZGkofVh8aSxhIS0JIQh4dHlUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKSlVKQ1VITFVKTk9ZV1kWGg8SFR0UWUFZT0tIVUpISkJIT1VKS0tVS1kG X-HM-Tid: 0a8cae820c1bb039kuuu0edd0ac00b7 X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MlE6Myo*Azw6GQ8QKzkUAkMZ ITowCzlVSlVKTEtITEhPQ0tDSE5OVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSkpVSkNVSExVSk5PWVdZCAFZQUNLS0g3Bg++ X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: 1786495535475755650 X-GMAIL-MSGID: 1786495535475755650 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 | 31 +++++++++++++++++++ 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 | 15 +++++++++ 5 files changed, 84 insertions(+) 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 def26daf634..ebd89461d2c 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -636,6 +636,29 @@ 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 = @@ -690,6 +713,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..1b3c9d18b59 --- /dev/null +++ b/gas/testsuite/gas/loongarch/tls_le_insn_format_check.s @@ -0,0 +1,15 @@ +/* Assemble the following assembly statements using as. + + The test case is mainly to check the format of tls le type + symbolic address fetch instruction.Because in tls le symbolic + address acquisition, there will be a special add.d instruction, + which has four operands (add.d op1,op2,op3,op4),the first three + operands are registers, and the last operand is a relocation, + we need to format check the fourth operand.If it is not a correct + relocation type operand, we need to throw the relevant exception + message. + + if a "no match insn" exception is thrown, the test passes; + otherwise, the test fails. */ + +add.d $a0,$a0,$a0,8 From patchwork Thu Dec 28 03:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: changjiachen X-Patchwork-Id: 183631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1790475dyb; Wed, 27 Dec 2023 19:42:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXBAkxKznzrEtpMnnAJvX8avnUwaNNNJhbg6vnSIli+X+60wXAe56+kuhzMb0WXLwnRjpH X-Received: by 2002:a05:6214:4205:b0:680:235a:1e4d with SMTP id nd5-20020a056214420500b00680235a1e4dmr4574241qvb.76.1703734944754; Wed, 27 Dec 2023 19:42:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703734944; cv=pass; d=google.com; s=arc-20160816; b=P5QdMOb5h/F5+uPy3Q7opdf3vXRJoi3MC0kDrW8+actRwQXAVjg81eayxg1c2BJBjU hEU3i1xKSvdjdlfIq+LljafDXZ+Vpf0Ua/ZfFFe+TUIgnQ9ImAwyZaFQuTic3vuiZviG zDRqCSiaSWRWYn2la2OmB6SyX49Cq+K+Um4f+HYscOObBds78T9Z7nOrG7H6/qcZuhth xNPg9z1DJAM5mOedZ6Xnwrs7Dn2pZ43jMHJdQ6OtvLOPQ+h3pavjUabPMKVxJh0z/2lQ +QGBxhp97obfvQ37NOYgJRwa7dn/IQb1r7VH3TLlGgEd1Ix8OFGm7VZCGnJ0rYbpUBt5 ffug== 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=yLAV+IGBuES2wLZxu8DdcWZv9aYWdP245VPuIhCPoaw=; fh=uTF/VfpCAq2GtcL5NdCKul3VKQPlBSDYmUlZE/0CcYM=; b=GEGFqT/C0puXwRwp8GVeg3alhxAz7XE0c9zFV5YlHJISRGeHJPs7h4/+4wKGcxroO+ NBsETOPYv5TV7L+ARujZJTLGSEdxMkhhqebF1OGo+JV3jf4GBX4LRA/aoYzQaMrV5M2J HsBJRwyT3bJUZmVQJQZk6FbqPmWSEBzpLvN6B0y8mobuFJ9VXKdVqJIBfw8C68whL+TX vskbAdM1ojzB14nfhf8ZswbqflBrpyLzZo9WhgHFkyjeQ4rrYqFBZRHItL13NDUuSpsX T2yIDrLk62qV648XkvrE6zGftFVLzeu3Jz4jRIFJZERpofzT/q4HZs6z1V0+9wmHmTde zDsg== 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 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j14-20020a05621419ce00b0068028d3a037si6163141qvc.154.2023.12.27.19.42.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 19:42:24 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 66BE5385840A for ; Thu, 28 Dec 2023 03:42:24 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m25471.xmail.ntesmail.com (mail-m25471.xmail.ntesmail.com [103.129.254.71]) by sourceware.org (Postfix) with ESMTPS id 7123E3858CD1 for ; Thu, 28 Dec 2023 03:40:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7123E3858CD1 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 7123E3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=103.129.254.71 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734818; cv=none; b=hVNqtYKLzz9aXmC/u6Ll4XhYjWLV3AiblLQOKCDE24D+OLL43/8xyhZkxszo60qsVPaWlsZ3HXpfmFgoTbNnwPYxN836/f/1pML66E0K1gsjvJK0GzU4Dz91hjoTp3Y7Vf0NzuS/z5DGyDJnBe83BAE0KL/f3Fy0FwA4XOzj0ew= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703734818; c=relaxed/simple; bh=UzyppQPyI+0xydRILNAXL1EQXnp9g8va8cEug7rL+Ew=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ZBN3JtSZqf3e9HvzpW0x5rb5xKljhboUrar0mKTo1kcpyVIENPWbA4zd7FlyhLIwAcbtGVyo0geXtRLd2+FZt5piLTGhyCooC92pcfw+LJ/LV2I1E5CBC58mBiexZyR9fXlCbcsSVke0aIpcVSIMPPEyiokmst7D7Xzohnx1q1I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from ubuntu.localdomain (unknown [111.18.37.154]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id E86C7AC00BE; Thu, 28 Dec 2023 11:40:08 +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 v5 5/5] LoongArch: ld: Add support for tls le relax. Date: Thu, 28 Dec 2023 11:39:57 +0800 Message-Id: <20231228033957.108449-6-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> References: <20231228033957.108449-1-changjiachen@stu.xupt.edu.cn> MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCQk1PVk9DQ01ITR9NShlPGVUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKSlVKQ1VITFVKTk9ZV1kWGg8SFR0UWUFZT0tIVUpMSk9MQ1VKS0tVSkJLS1kG X-HM-Tid: 0a8cae82137eb039kuuue86c7ac00be X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6N006Tyo5EzwwCQ8WDTk6AkMR HhYKFCxVSlVKTEtITEhPQ0pLSEtDVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSkpVSkNVSExVSk5PWVdZCAFZQUpITkNPNwY+ X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: 1786495573184820303 X-GMAIL-MSGID: 1786495573184820303 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/tls-relax-compatible-check-new.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 | 23 +++ .../relax-bound-check-tls-le.s | 53 ++++++ ld/testsuite/ld-loongarch-elf/relax-tls-le.s | 26 +++ ld/testsuite/ld-loongarch-elf/relax.exp | 151 +++++++++++++++++- .../tls-relax-compatible-check-new.s | 35 ++++ .../tls-relax-compatible-check-old.s | 33 ++++ 6 files changed, 320 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-tls-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-new.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..be3d2b9c5c6 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/old-tls-le.s @@ -0,0 +1,23 @@ +/* This test case mainly tests whether the original + tls le assembly instruction can be linked normally + after tls le relax is added to the current ld. */ + + .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..b2a64b5d154 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-bound-check-tls-le.s @@ -0,0 +1,53 @@ +/* This test case mainly tests whether the address of the + tls le symbol can be resolved normally when the offset + of the symbol is greater than 0x800. (When the symbol + offset is greater than 0x800, relax is not performed). */ + + .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,%le_hi20_r(count1) + add.d $r12,$r12,$r2,%le_add_r(count1) + addi.w $r13,$r0,1 + st.w $r13,$r12,%le_lo12_r(count1) + lu12i.w $r12,%le_hi20_r(count2) + add.d $r12,$r12,$r2,%le_add_r(count2) + addi.w $r13,$r0,2 + st.w $r13,$r12,%le_lo12_r(count2) + lu12i.w $r12,%le_hi20(count3) + add.d $r12,$r12,$r2,%le_add_r(count3) + addi.w $r13,$r0,3 + st.w $r13,$r12,%le_lo12_r(count3) + lu12i.w $r12,%le_hi20(count4) + add.d $r12,$r12,$r2,%le_add_r(count4) + addi.w $r13,$r0,4 + st.w $r13,$r12,%le_lo12_r(count4) + 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..1ea53baf8f7 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-tls-le.s @@ -0,0 +1,26 @@ +/* This test case mainly tests whether the tls le variable + address acquisition can be relax normally. + + before relax: after relax: + + lu12i.w $r12,%le_hi20_r(sym) ====> (instruction deleted). + add.d $r12,$r12,$r2,%le_add_r(sym) ====> (instruction deleted). + st.w $r13,$r12,%le_lo12_r(sym) ====> st.w $r13,$r2,%le_lo12_r(sym). */ + + .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,%le_hi20_r(a) + add.d $r12,$r12,$r2,%le_add_r(a) + addi.w $r13,$r0,1 # 0x1 + st.w $r13,$r12,%le_lo12_r(a) diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp index 77323d8d7a3..b697d01563c 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" \ + "" \ + "" \ + {tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \ + {} \ + "realx-compatible" \ + ] \ + ] + + set no_relax_compatible [list \ + [list \ + "no_relax_compatible" \ + "-Wl,--no-relax" \ + "" \ + {tls-relax-compatible-check-new.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"] @@ -114,8 +196,75 @@ if [istarget loongarch64-*-*] { "relax-segment-max" \ ] \ ] - } + 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"] { + set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/realx-compatible"] + if { [ regexp ".addi.*st.*" $objdump_output4] && \ + [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } { + pass "loongarch tls le relax compatible check success" + } { + fail "loongarch tls le relax compatible check fail" + } + } + + if [file exist "tmpdir/no-realx-compatible"] { + set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/realx-compatible"] + if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output4] && \ + [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } { + pass "loongarch tls le no-relax compatible check success" + } { + fail "loongarch tls le no-relax compatible check fail" + } + } + + + if [file exist "tmpdir/relax-bound-check-tls-le"] { + set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/relax-bound-check-tls-le"] + if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output5] && \ + [ regexp ".addi.*st.*" $objdump_output5] } { + 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_output5] } { + 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-new.s b/ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-new.s new file mode 100644 index 00000000000..059ca0b97ae --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-new.s @@ -0,0 +1,35 @@ +/* This test case mainly carries out ld compatibility test. + This test case is the new tls le instruction sequence, + which will be linked with tls-relax-compatible-check-old.s. + If the link is normal, it indicates that there is no + compatibility problem. */ + + .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 = . + addi.d $r3,$r3,-16 + st.d $r1,$r3,8 + stptr.d $r22,$r3,0 + addi.d $r22,$r3,16 + bl %plt(old) + lu12i.w $r12,%le_hi20_r(new) + add.d $r12,$r12,$r2,%le_add_r(new) + addi.w $r13,$r0,2 # 0x2 + st.w $r13,$r12,%le_lo12_r(new) + or $r12,$r0,$r0 + or $r4,$r12,$r0 + ld.d $r1,$r3,8 + ldptr.d $r22,$r3,0 + addi.d $r3,$r3,16 + jr $r1 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..083a26887e5 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/tls-relax-compatible-check-old.s @@ -0,0 +1,33 @@ +/* This test case mainly carries out ld compatibility test. + This test case is the old tls le instruction sequence, + which will be linked with tls-relax-compatible-check-new.s. + If the link is normal, it indicates that there is no + compatibility problem. */ + + .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 = . + addi.d $r3,$r3,-16 + st.d $r22,$r3,8 + addi.d $r22,$r3,16 + 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 + addi.d $r3,$r3,16 + jr $r1