Message ID | 20231201090730.20521-1-changjiachen@stu.xupt.edu.cn |
---|---|
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp983330vqy; Fri, 1 Dec 2023 01:08:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IExBiB+0THDELG5Afm0Q7DpvRAZf7Rk4syXcMYKbw1uVmNlpiEoesA+e6o1MxkEYG0QoOoo X-Received: by 2002:a05:620a:1646:b0:77d:72b8:ef23 with SMTP id c6-20020a05620a164600b0077d72b8ef23mr25083118qko.28.1701421694406; Fri, 01 Dec 2023 01:08:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701421694; cv=pass; d=google.com; s=arc-20160816; b=wHqYL4OZ27Bx3tuJC4Konwd0e5jHYDYluNjQbf5pkU7yP7SJZcyVXXl3t7xKHHSGWz 90WT3OCJJPsyIFtlvfNR5QmEE2KCmnHgItECMrKlLJEtV9+t30cIxc6I1v9yWdkAZ8tX hnAg5rDHrrVjVWpLoUxKQTj+mnP7zBLc2oyRmf0Ap4O22H2Ae9hfEkVVQmOY2DIVxldC 6c99wtPLZHnsDEVBBo24ES0Owxz/omchiHPjjVfh7mArrbwwHyyBORdpcMQMcVQHHkhZ 1aKMrcLjkO2R8AnRpivszz7+60c8LRl69Gt6OJAUTDkf+ld6J6C/0wkRIbm4NOOU0w6q asPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=Kd2/6LXMFpdX8a5/DhwHUEXqJRKhBLP9bTuSbVD/o/c=; fh=W1lXzvrBv/RFWlDbqsdKVtGlKtndxGWKzaE/S+FMPJw=; b=yNkxeyyfNCO2WWsSq9dTsIksbh7FzQnwST8RXralFFL55v/IOtct9nIlD2xpkVeMqZ uKjHZMB27WUiCZLi9lMoGVPuU8GEO44J9sKg/7ws+MFpBs0e2cM7uvMa53n8VOalvMrR Rch5UvosJJvHXM66xWJwvQ7d9n6gVtClySfW1hK0mRK0saOY/nR4xSmdV187eNnJMrLV +8QcJS6MiOTfE7XAwUKGobVW2Lmv96sTExXWB3CE/ALAwCo8uIw9FLCXEG1iJZL7vE0j 8qV9nbXrnT4DYOEmm+BnRTRIiLKSnWNGTP9VAi1rAFAqZ324EpdIJ+0g1IFo/4l6/+0T 4k9w== 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 dz15-20020a05620a2b8f00b0077bbddecaafsi2873979qkb.487.2023.12.01.01.08.14 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:08:14 -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 1F117385C6D6 for <ouuuleilei@gmail.com>; Fri, 1 Dec 2023 09:08:14 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) by sourceware.org (Postfix) with ESMTPS id 907C73858415 for <binutils@sourceware.org>; Fri, 1 Dec 2023 09:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 907C73858415 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 907C73858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=101.71.155.101 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701421675; cv=none; b=u1mtZvGbPmLAUrB21MbN/T7OIkSqwK8FfIh7f92KFSTL828gpmATadpOReRp+OK5WPUaFIBlD/7oNN9oJTmGFfWDx/br8FGPSVNbsi+xNPgvFKqv1W5Kx9mNsdFIbF13pWzbj5g1nqOSlW3CxvSztNDQruX6JsGonzZ3iMUVmKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701421675; c=relaxed/simple; bh=AD9HpujqdCpF5qjpZ+38DD/wH4NeQ1CF4JhAzw3SeWs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=JKPe1vg7qqk2vgTqA5whSEwI4Y5eZF1zGuRV5Y8RAUbz7oKl+V8a2+7bLJRv0fqP4vd40JqNO7gP1QflUs+aDNS59z9kHudgJoVQL9+jJ/ulwYOzsvT2Mh9Me/tdHcPAlgAcViejbEp1wppJkWycdHTIEy5gtOWpaB7NXVqyMYw= 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 43C76AC00A8; Fri, 1 Dec 2023 17:07:33 +0800 (CST) From: changjiachen <changjiachen@stu.xupt.edu.cn> 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 <changjiachen@stu.xupt.edu.cn> Subject: [PATCH v1 0/5] LoongArch tls le model linker relaxation support. Date: Fri, 1 Dec 2023 17:07:25 +0800 Message-Id: <20231201090730.20521-1-changjiachen@stu.xupt.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCTx9OVkhLGhpJTkMYHUwYSlUTARMWGhIXJBQOD1 lXWRgSC1lBWUpJT1VDQlVJVUNIWVdZFhoPEhUdFFlBWU9LSFVKTEpMSEhVSktLVUpCS0tZBg++ X-HM-Tid: 0a8c24a21f32b039kuuu43c76ac00a8 X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MyI6Pgw4Azw9ChUBQksdIj4K SxIwFA5VSlVKTEtKT0lKTU5PT0JIVTMWGhIXVRgTGhUcERIaGBMeFTsIDw5VAw4LD1UeHw5VGBVF WVdZEgtZQVlKSU9VQ0JVSVVDSFlXWQgBWUFPSEJLNwY+ X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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 <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784069954336158951 X-GMAIL-MSGID: 1784069954336158951 |
Series |
LoongArch tls le model linker relaxation support.
|
|
Message
changjiachen
Dec. 1, 2023, 9:07 a.m. UTC
This is the v1 version of patches to support loongarch linker tls le model relax. This support does three main things: 1. Modify LoongArch tls le model assembly instruction sequence. This change is mainly implemented in gcc. Due to the characteristics of st.w instruction in Loongarch and the unique addressing mode of tls le model, in order to implement tls le model linker relax, it is decided to change the tls le model instruction sequence. The specific changes are as follows: example: __thread int a = 1; old insn sequence: lu12i.w $r12,%le_hi20_r(a) ori $r12,$r12,%le_lo12_r(a) add.d $r12,$r12,$r2,%le_add_r(a) li.w $r13,$r0,1 stptr.w $r13,$r12,0 new insn sequence: lu12i.w $r12,%le_hi20_r(a) add.d $r12,$r12,$r2,%le_add_r(a) li.w $r13,$r0,1 st.w $r13,$r12,%le_lo12_r(a) 2. Added LoongArch three relocations related to tls le model relax. In order to ensure forward compatibility of binutils versions and implement tls le model relax, it was decided to add three relocation items. The relocation items are as follows: R_LARCH_TLS_LE_HI20_R R_LARCH_TLS_LE_LO12_R R_LARCH_TLS_LE_ADD_R 3. Implement Loongarch tls le model relax in ld. This change will add a loongarch_relax_tls_le function to relax tls le model. The instructions before and after relax change as follows: example: __thread int a = 1; before relax insn: lu12i.w $t0, 0 add.d $t0, $t0, $tp li.w $t1, 1 st.w $t1, $t0, 0 after relax insn: li.w $t1, 1 st.w $t1, $tp, 0 changjiachen (5): LoongArch: bfd: Add support for tls le relax. LoongArch: include: Add support for tls le relax. LoongArch: opcodes: Add support for tls le relax. LoongArch: gas: Add support for tls le relax. LoongArch: ld: Add support for tls le relax. bfd/bfd-in2.h | 4 + bfd/elfnn-loongarch.c | 74 +++++++++ bfd/elfxx-loongarch.c | 50 ++++++ bfd/libbfd.h | 3 + bfd/reloc.c | 6 + gas/config/tc-loongarch.c | 12 +- gas/testsuite/gas/loongarch/reloc.d | 18 +++ gas/testsuite/gas/loongarch/reloc.s | 11 ++ include/elf/loongarch.h | 13 ++ 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 +++++ opcodes/loongarch-opc.c | 1 + 16 files changed, 501 insertions(+), 3 deletions(-) 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
Comments
On Fri, 2023-12-01 at 17:07 +0800, changjiachen wrote: > R_LARCH_TLS_LE_HI20_R > R_LARCH_TLS_LE_LO12_R > R_LARCH_TLS_LE_ADD_R Why do we need them? Why not just use a combination of R_LARCH_RELAX and R_LARCH_TLS_LE_HI20/LO12?
On 2023-12-01 17:07, changjiachen wrote: > This is the v1 version of patches to support loongarch linker tls le model relax. > > This support does three main things: > > 1. Modify LoongArch tls le model assembly instruction sequence. > > This change is mainly implemented in gcc. Due to the characteristics > of st.w instruction in Loongarch and the unique addressing mode of > tls le model, in order to implement tls le model linker relax, it is > decided to change the tls le model instruction sequence. > > The specific changes are as follows: > > example: __thread int a = 1; > > old insn sequence: > > lu12i.w $r12,%le_hi20_r(a) > ori $r12,$r12,%le_lo12_r(a) > add.d $r12,$r12,$r2,%le_add_r(a) > li.w $r13,$r0,1 > stptr.w $r13,$r12,0 Hi, It's more complex than I thought as you said it is mainly implemented in gcc. Now I compile it, in archlinux, by gcc 13.2.1, and insn sequence like follows, lu12i.w $r12,%le_hi20(a) ori $r12,$r12,%le_lo12(a) addi.w $r13,$r0,1 stx.w $r13,$r12,$r2 It use `stx.w` rather than `st.w` or `stptr.w`. Will the gcc implementation change this sequence? > > new insn sequence: > > lu12i.w $r12,%le_hi20_r(a) > add.d $r12,$r12,$r2,%le_add_r(a) > li.w $r13,$r0,1 > st.w $r13,$r12,%le_lo12_r(a) In old sequence, $r12 is the real address of "a". In new sequence, $r12 is not the real address of "a". How about we use $r12 after this sequence? > 2. Added LoongArch three relocations related to tls le model relax. > > In order to ensure forward compatibility of binutils versions and > implement tls le model relax, it was decided to add three relocation items. > > The relocation items are as follows: > > R_LARCH_TLS_LE_HI20_R > R_LARCH_TLS_LE_LO12_R > R_LARCH_TLS_LE_ADD_R > > 3. Implement Loongarch tls le model relax in ld. > > This change will add a loongarch_relax_tls_le function to relax tls le model. > > The instructions before and after relax change as follows: > > example: __thread int a = 1; > > before relax insn: > > lu12i.w $t0, 0 > add.d $t0, $t0, $tp > li.w $t1, 1 > st.w $t1, $t0, 0 > > after relax insn: > > li.w $t1, 1 > st.w $t1, $tp, 0 > > changjiachen (5): > LoongArch: bfd: Add support for tls le relax. > LoongArch: include: Add support for tls le relax. > LoongArch: opcodes: Add support for tls le relax. > LoongArch: gas: Add support for tls le relax. > LoongArch: ld: Add support for tls le relax. > > bfd/bfd-in2.h | 4 + > bfd/elfnn-loongarch.c | 74 +++++++++ > bfd/elfxx-loongarch.c | 50 ++++++ > bfd/libbfd.h | 3 + > bfd/reloc.c | 6 + > gas/config/tc-loongarch.c | 12 +- > gas/testsuite/gas/loongarch/reloc.d | 18 +++ > gas/testsuite/gas/loongarch/reloc.s | 11 ++ > include/elf/loongarch.h | 13 ++ > 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 +++++ > opcodes/loongarch-opc.c | 1 + > 16 files changed, 501 insertions(+), 3 deletions(-) > 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 >
在 2023/12/2 上午9:55, Jinyang He 写道: > On 2023-12-01 17:07, changjiachen wrote: > >> This is the v1 version of patches to support loongarch linker tls le >> model relax. >> >> This support does three main things: >> >> 1. Modify LoongArch tls le model assembly instruction sequence. >> >> This change is mainly implemented in gcc. Due to the characteristics >> of st.w instruction in Loongarch and the unique addressing mode of >> tls le model, in order to implement tls le model linker relax, it is >> decided to change the tls le model instruction sequence. >> >> The specific changes are as follows: >> >> example: __thread int a = 1; >> >> old insn sequence: >> >> lu12i.w $r12,%le_hi20_r(a) >> ori $r12,$r12,%le_lo12_r(a) >> add.d $r12,$r12,$r2,%le_add_r(a) >> li.w $r13,$r0,1 >> stptr.w $r13,$r12,0 > > Hi, > > > It's more complex than I thought as you said it is mainly implemented > in gcc. Now I compile it, in archlinux, by gcc 13.2.1, and insn sequence > like follows, > > lu12i.w $r12,%le_hi20(a) > ori $r12,$r12,%le_lo12(a) > addi.w $r13,$r0,1 > stx.w $r13,$r12,$r2 > > It use `stx.w` rather than `st.w` or `stptr.w`. Will the gcc > implementation > change this sequence? > First, the compilation generated in this scenario should be as follows (at the O0 optimization level): lu12i.w $r12,%le_hi20(a) ori $r12,$r12,%le_lo12(a) add.d $r12,$r12,$r2 addi.w $r13,$r0,1 # 0x1 stptr.w $r13,$r12,0 After adding optimizations, this sequence may be optimized, e.g. O2 will generate the following: lu12i.w $r12,%le_hi20(.LANCHOR0) addi.w $r13,$r0,1 # 0x1 ori $r12,$r12,%le_lo12(.LANCHOR0) stx.w $r13,$r12,$r2 At the same time, the instruction sequence may also change. Lulu > >> >> new insn sequence: >> >> lu12i.w $r12,%le_hi20_r(a) >> add.d $r12,$r12,$r2,%le_add_r(a) >> li.w $r13,$r0,1 >> st.w $r13,$r12,%le_lo12_r(a) > > In old sequence, $r12 is the real address of "a". In new sequence, > $r12 is > not the real address of "a". How about we use $r12 after this sequence? > > >> 2. Added LoongArch three relocations related to tls le model relax. >> >> In order to ensure forward compatibility of binutils versions and >> implement tls le model relax, it was decided to add three relocation >> items. >> >> The relocation items are as follows: >> >> R_LARCH_TLS_LE_HI20_R >> R_LARCH_TLS_LE_LO12_R >> R_LARCH_TLS_LE_ADD_R >> >> 3. Implement Loongarch tls le model relax in ld. >> >> This change will add a loongarch_relax_tls_le function to relax tls >> le model. >> >> The instructions before and after relax change as follows: >> >> example: __thread int a = 1; >> >> before relax insn: >> >> lu12i.w $t0, 0 >> add.d $t0, $t0, $tp >> li.w $t1, 1 >> st.w $t1, $t0, 0 >> >> after relax insn: >> >> li.w $t1, 1 >> st.w $t1, $tp, 0 >> >> changjiachen (5): >> LoongArch: bfd: Add support for tls le relax. >> LoongArch: include: Add support for tls le relax. >> LoongArch: opcodes: Add support for tls le relax. >> LoongArch: gas: Add support for tls le relax. >> LoongArch: ld: Add support for tls le relax. >> >> bfd/bfd-in2.h | 4 + >> bfd/elfnn-loongarch.c | 74 +++++++++ >> bfd/elfxx-loongarch.c | 50 ++++++ >> bfd/libbfd.h | 3 + >> bfd/reloc.c | 6 + >> gas/config/tc-loongarch.c | 12 +- >> gas/testsuite/gas/loongarch/reloc.d | 18 +++ >> gas/testsuite/gas/loongarch/reloc.s | 11 ++ >> include/elf/loongarch.h | 13 ++ >> 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 +++++ >> opcodes/loongarch-opc.c | 1 + >> 16 files changed, 501 insertions(+), 3 deletions(-) >> 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 >>
From: Jinyang He <hejinyang@loongson.cn> Date: 2023-12-02 09:55:14 To: changjiachen <changjiachen@stu.xupt.edu.cn>,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,Lazy_Linux@126.com Subject: Re: [PATCH v1 0/5] LoongArch tls le model linker relaxation support.>On 2023-12-01 17:07, changjiachen wrote: > >> This is the v1 version of patches to support loongarch linker tls le model relax. >> >> This support does three main things: >> >> 1. Modify LoongArch tls le model assembly instruction sequence. >> >> This change is mainly implemented in gcc. Due to the characteristics >> of st.w instruction in Loongarch and the unique addressing mode of >> tls le model, in order to implement tls le model linker relax, it is >> decided to change the tls le model instruction sequence. >> >> The specific changes are as follows: >> >> example: __thread int a = 1; >> >> old insn sequence: >> >> lu12i.w $r12,%le_hi20_r(a) >> ori $r12,$r12,%le_lo12_r(a) >> add.d $r12,$r12,$r2,%le_add_r(a) >> li.w $r13,$r0,1 >> stptr.w $r13,$r12,0 > >Hi, > > >It's more complex than I thought as you said it is mainly implemented >in gcc. Now I compile it, in archlinux, by gcc 13.2.1, and insn sequence >like follows, > >lu12i.w $r12,%le_hi20(a) >ori $r12,$r12,%le_lo12(a) >addi.w $r13,$r0,1 >stx.w $r13,$r12,$r2 > >It use `stx.w` rather than `st.w` or `stptr.w`. Will the gcc implementation >change this sequence? > >> >> new insn sequence: >> >> lu12i.w $r12,%le_hi20_r(a) >> add.d $r12,$r12,$r2,%le_add_r(a) >> li.w $r13,$r0,1 >> st.w $r13,$r12,%le_lo12_r(a) > >In old sequence, $r12 is the real address of "a". In new sequence, $r12 is >not the real address of "a". How about we use $r12 after this sequence? > >To solve this problem, I will give you the following explanation > In the new and old sequences, the final r12 value is different, > and there are some small changes in the address calculation of the tls variable. > > The address calculation of the tls variable is of the form tp+offset. > > In the old sequence: > In the old sequence, the hi20 and lo12 parts of the offset of the tls variable > were computed first, then the entire offet and tp were added together, and > the result was stored in r12. > > In the new sequence: > In the new sequence, the hi20 part of the offset of the tls variable is computed, > the hi20 part and tp are added together, and the result is stored in r12. The immediate > portion of the st.w instruction stores the lo12 portion of the tls variable, and finally the st.w > instruction stores the value in the address r12+offset(lo12). > > To sum up, in the old sequence, r12 stores the real address of tls variable (tp+offset(hi20)+offset(lo12)), > while in the new sequence r12 does not store the real address of tls variable (tp+offset(hi20)), > but takes advantage of the instruction characteristics of st.w. So the new sequence and the old > sequence actually point to the same address. > > Note: st.w rd, rj, s12 > The memory address of this instruction is the sum of the value in the universal register rj > and the 12-bit immediate number si12 after the symbol extension. > >> 2. Added LoongArch three relocations related to tls le model relax. >> >> In order to ensure forward compatibility of binutils versions and >> implement tls le model relax, it was decided to add three relocation items. >> >> The relocation items are as follows: >> >> R_LARCH_TLS_LE_HI20_R >> R_LARCH_TLS_LE_LO12_R >> R_LARCH_TLS_LE_ADD_R >> >> 3. Implement Loongarch tls le model relax in ld. >> >> This change will add a loongarch_relax_tls_le function to relax tls le model. >> >> The instructions before and after relax change as follows: >> >> example: __thread int a = 1; >> >> before relax insn: >> >> lu12i.w $t0, 0 >> add.d $t0, $t0, $tp >> li.w $t1, 1 >> st.w $t1, $t0, 0 >> >> after relax insn: >> >> li.w $t1, 1 >> st.w $t1, $tp, 0 >> >> changjiachen (5): >> LoongArch: bfd: Add support for tls le relax. >> LoongArch: include: Add support for tls le relax. >> LoongArch: opcodes: Add support for tls le relax. >> LoongArch: gas: Add support for tls le relax. >> LoongArch: ld: Add support for tls le relax. >> >> bfd/bfd-in2.h | 4 + >> bfd/elfnn-loongarch.c | 74 +++++++++ >> bfd/elfxx-loongarch.c | 50 ++++++ >> bfd/libbfd.h | 3 + >> bfd/reloc.c | 6 + >> gas/config/tc-loongarch.c | 12 +- >> gas/testsuite/gas/loongarch/reloc.d | 18 +++ >> gas/testsuite/gas/loongarch/reloc.s | 11 ++ >> include/elf/loongarch.h | 13 ++ >> 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 +++++ >> opcodes/loongarch-opc.c | 1 + >> 16 files changed, 501 insertions(+), 3 deletions(-) >> 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 >> >