[lld] [lld][LoongArch] Precommit test for TLSDESC GD/LD to LE/IE. NFC (PR #121095)

Zhaoxin Yang via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 25 01:37:47 PST 2024


https://github.com/ylzsx updated https://github.com/llvm/llvm-project/pull/121095

>From d9acf0c43ae1c47d284356c266d9e1fd07625231 Mon Sep 17 00:00:00 2001
From: yangzhaoxin <yangzhaoxin at loongson.cn>
Date: Wed, 25 Dec 2024 14:11:30 +0800
Subject: [PATCH 1/2] [lld][LoongArch] Precommit test for TLSDESC GD/LD to
 LE/IE.

Add symbol `d` in loongarch-tlsdesc-extreme.s/loongarch-tlsdesc-pcrel20-s2.s,
which is placed at 0x1000. After optimization to LE, it will generate
two instructions.
---
 lld/test/ELF/loongarch-tlsdesc-extreme.s    | 194 ++++++++++++++++++++
 lld/test/ELF/loongarch-tlsdesc-pcrel20-s2.s |  99 ++++++----
 lld/test/ELF/loongarch-tlsdesc.s            | 104 ++++++-----
 3 files changed, 318 insertions(+), 79 deletions(-)
 create mode 100644 lld/test/ELF/loongarch-tlsdesc-extreme.s

diff --git a/lld/test/ELF/loongarch-tlsdesc-extreme.s b/lld/test/ELF/loongarch-tlsdesc-extreme.s
new file mode 100644
index 00000000000000..47b23b7987a389
--- /dev/null
+++ b/lld/test/ELF/loongarch-tlsdesc-extreme.s
@@ -0,0 +1,194 @@
+# REQUIRES: loongarch
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=loongarch64 a.s -o a.64.o
+# RUN: llvm-mc -filetype=obj -triple=loongarch64 c.s -o c.64.o
+# RUN: ld.lld -shared -soname=c.64.so c.64.o -o c.64.so
+
+# RUN: ld.lld -shared -z now a.64.o c.64.o -o a.64.so
+# RUN: llvm-readobj -r -x .got a.64.so | FileCheck --check-prefix=GD64-RELA %s
+# RUN: llvm-objdump --no-show-raw-insn -h -d a.64.so | FileCheck %s --check-prefix=GD64
+
+# RUN: ld.lld -shared -z now a.64.o c.64.o -o rel.64.so -z rel
+# RUN: llvm-readobj -r -x .got rel.64.so | FileCheck --check-prefix=GD64-REL %s
+
+## FIXME: The transition frome TLSDESC to IE/LE has not yet been implemented.
+## Keep the dynamic relocations and hand them over to dynamic linker.
+
+# RUN: ld.lld -e 0 -z now a.64.o c.64.o -o a.64.le
+# RUN: llvm-readobj -r -x .got a.64.le | FileCheck --check-prefix=LE64-RELA %s
+
+# RUN: ld.lld -e 0 -z now a.64.o c.64.so -o a.64.ie
+# RUN: llvm-readobj -r -x .got a.64.ie | FileCheck --check-prefix=IE64-RELA %s
+
+# GD64-RELA:      .rela.dyn {
+# GD64-RELA-NEXT:   0x20568 R_LARCH_TLS_DESC64 - 0x1000
+# GD64-RELA-NEXT:   0x20518 R_LARCH_TLS_DESC64 a 0x0
+# GD64-RELA-NEXT:   0x20528 R_LARCH_TLS_DESC64 c 0x0
+# GD64-RELA-NEXT:   0x20538 R_LARCH_TLS_DESC64 d 0x0
+# GD64-RELA-NEXT:   0x20548 R_LARCH_TLS_DESC64 e 0x0
+# GD64-RELA-NEXT:   0x20558 R_LARCH_TLS_DESC64 f 0x0
+# GD64-RELA-NEXT: }
+# GD64-RELA:      Hex dump of section '.got':
+# GD64-RELA-NEXT: 0x00020518 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020528 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020538 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020548 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020558 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020568 00000000 00000000 00000000 00000000 .
+
+# GD64-REL:      .rel.dyn {
+# GD64-REL-NEXT:   0x20538 R_LARCH_TLS_DESC64 -
+# GD64-REL-NEXT:   0x204E8 R_LARCH_TLS_DESC64 a
+# GD64-REL-NEXT:   0x204F8 R_LARCH_TLS_DESC64 c
+# GD64-REL-NEXT:   0x20508 R_LARCH_TLS_DESC64 d
+# GD64-REL-NEXT:   0x20518 R_LARCH_TLS_DESC64 e
+# GD64-REL-NEXT:   0x20528 R_LARCH_TLS_DESC64 f
+# GD64-REL-NEXT: }
+# GD64-REL:      Hex dump of section '.got':
+# GD64-REL-NEXT: 0x000204e8 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x000204f8 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020508 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020518 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020528 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020538 00000000 00000000 00100000 00000000 .
+
+# GD64:      .got     00000060 0000000000020518
+
+## &.got[a]-. = 0x20518 - 0x10398: 0x10 pages, page offset 0x518
+# GD64:        10398: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d $t0, $zero, 1304
+# GD64-NEXT:          lu32i.d	$t0, 0
+# GD64-NEXT:          lu52i.d	$t0, $t0, 0
+# GD64-NEXT:          add.d	$a0, $a0, $t0
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a1, $a0, $tp
+
+## &.got[b]-. = 0x20518+80 - 0x103b8: 0x10 pages, page offset 0x568
+# GD64:        103b8: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d $t0, $zero, 1384
+# GD64-NEXT:          lu32i.d	$t0, 0
+# GD64-NEXT:          lu52i.d	$t0, $t0, 0
+# GD64-NEXT:          add.d	$a0, $a0, $t0
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a2, $a0, $tp
+
+## &.got[c]-. = 0x20518+16 - 0x103d8: 0x10 pages, page offset 0x528
+# GD64:        103d8: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d  $t0, $zero, 1320
+# GD64-NEXT:          lu32i.d	$t0, 0
+# GD64-NEXT:          lu52i.d	$t0, $t0, 0
+# GD64-NEXT:          add.d	$a0, $a0, $t0
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a3, $a0, $tp
+
+## &.got[d]-. = 0x20518+32 - 0x103f8: 0x10 pages, page offset 0x538
+# GD64:        103f8: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d  $t0, $zero, 1336
+# GD64-NEXT:          lu32i.d	$t0, 0
+# GD64-NEXT:          lu52i.d	$t0, $t0, 0
+# GD64-NEXT:          add.d	$a0, $a0, $t0
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a4, $a0, $tp
+
+## &.got[e]-. = 0x20518+48 - 0x10418: 0x10 pages, page offset 0x548
+# GD64:        10418: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d  $t0, $zero, 1352
+# GD64-NEXT:          lu32i.d	$t0, 0
+# GD64-NEXT:          lu52i.d	$t0, $t0, 0
+# GD64-NEXT:          add.d	$a0, $a0, $t0
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a5, $a0, $tp
+
+## &.got[f]-. = 0x20518+64 - 0x10438: 0x10 pages, page offset 0x558
+# GD64:        10438: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d  $t0, $zero, 1368
+# GD64-NEXT:          lu32i.d	$t0, 0
+# GD64-NEXT:          lu52i.d	$t0, $t0, 0
+# GD64-NEXT:          add.d	$a0, $a0, $t0
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a6, $a0, $tp
+
+# LE64-RELA:      .rela.dyn {
+# LE64-RELA-NEXT:   0x30318 R_LARCH_TLS_DESC64 - 0x8
+# LE64-RELA-NEXT:   0x30328 R_LARCH_TLS_DESC64 - 0x7FFFFFFF
+# LE64-RELA-NEXT:   0x30338 R_LARCH_TLS_DESC64 - 0x80000000
+# LE64-RELA-NEXT:   0x30348 R_LARCH_TLS_DESC64 - 0x100000000
+# LE64-RELA-NEXT:   0x30358 R_LARCH_TLS_DESC64 - 0x10000000000000
+# LE64-RELA-NEXT:   0x30368 R_LARCH_TLS_DESC64 - 0x1000
+# LE64-RELA-NEXT: }
+# LE64-RELA:      Hex dump of section '.got':
+# LE64-RELA-NEXT: 0x00030318 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030328 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030338 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030348 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030358 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030368 00000000 00000000 00000000 00000000 .
+
+# IE64-RELA:      .rela.dyn {
+# IE64-RELA-NEXT:   0x30508 R_LARCH_TLS_DESC64 - 0x8
+# IE64-RELA-NEXT:   0x30558 R_LARCH_TLS_DESC64 - 0x1000
+# IE64-RELA-NEXT:   0x30518 R_LARCH_TLS_DESC64 c 0x0
+# IE64-RELA-NEXT:   0x30528 R_LARCH_TLS_DESC64 d 0x0
+# IE64-RELA-NEXT:   0x30538 R_LARCH_TLS_DESC64 e 0x0
+# IE64-RELA-NEXT:   0x30548 R_LARCH_TLS_DESC64 f 0x0
+# IE64-RELA-NEXT: }
+# IE64-RELA:      Hex dump of section '.got':
+# IE64-RELA-NEXT: 0x00030508 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030518 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030528 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030538 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030548 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030558 00000000 00000000 00000000 00000000 .
+
+#--- a.s
+.macro add dst, src1, src2
+.ifdef ELF32
+add.w \dst, \src1, \src2
+.else
+add.d \dst, \src1, \src2
+.endif
+.endm
+
+la.tls.desc $a0, $t0, a
+add $a1, $a0, $tp
+
+la.tls.desc $a0, $t0, b
+add $a2, $a0, $tp
+
+la.tls.desc $a0, $t0, c
+add $a3, $a0, $tp
+
+la.tls.desc $a0, $t0, d
+add $a4, $a0, $tp
+
+la.tls.desc $a0, $t0, e
+add $a5, $a0, $tp
+
+la.tls.desc $a0, $t0, f
+add $a6, $a0, $tp
+
+.section .tbss,"awT", at nobits
+.globl a
+.zero 8
+a:
+.zero 0x1000-8  ## Place b at 0x1000
+b:
+
+#--- c.s
+.section .tbss,"awT", at nobits
+.globl c, d, e, f
+.zero 0x80000000-0x1000-1  ## Place c at 0x7fffffff
+c:
+.zero 1  ## Place d at 0x8000,0000
+d:
+.zero 0x100000000-0x80000000  ## Place e at 0x1,0000,0000
+e:
+.zero 0x10000000000000-0x100000000  ## Place f at 0x10,0000,0000,0000
+f:
+
diff --git a/lld/test/ELF/loongarch-tlsdesc-pcrel20-s2.s b/lld/test/ELF/loongarch-tlsdesc-pcrel20-s2.s
index 99e21d9935197e..122cd9d042d91d 100644
--- a/lld/test/ELF/loongarch-tlsdesc-pcrel20-s2.s
+++ b/lld/test/ELF/loongarch-tlsdesc-pcrel20-s2.s
@@ -29,73 +29,88 @@
 # RUN: llvm-readobj -r -x .got rel.32.so | FileCheck --check-prefix=GD32-REL %s
 
 # GD64-RELA:      .rela.dyn {
-# GD64-RELA-NEXT:   0x203F0 R_LARCH_TLS_DESC64 - 0x7FF
-# GD64-RELA-NEXT:   0x203D0 R_LARCH_TLS_DESC64 a 0x0
-# GD64-RELA-NEXT:   0x203E0 R_LARCH_TLS_DESC64 c 0x0
+# GD64-RELA-NEXT:   0x20448 R_LARCH_TLS_DESC64 - 0x7FF
+# GD64-RELA-NEXT:   0x20418 R_LARCH_TLS_DESC64 a 0x0
+# GD64-RELA-NEXT:   0x20428 R_LARCH_TLS_DESC64 c 0x0
+# GD64-RELA-NEXT:   0x20438 R_LARCH_TLS_DESC64 d 0x0
 # GD64-RELA-NEXT: }
 # GD64-RELA:      Hex dump of section '.got':
-# GD64-RELA-NEXT: 0x000203d0 00000000 00000000 00000000 00000000 .
-# GD64-RELA-NEXT: 0x000203e0 00000000 00000000 00000000 00000000 .
-# GD64-RELA-NEXT: 0x000203f0 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020418 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020428 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020438 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020448 00000000 00000000 00000000 00000000 .
 
 # GD64-REL:      .rel.dyn {
-# GD64-REL-NEXT:   0x203D8 R_LARCH_TLS_DESC64 -
-# GD64-REL-NEXT:   0x203B8 R_LARCH_TLS_DESC64 a
-# GD64-REL-NEXT:   0x203C8 R_LARCH_TLS_DESC64 c
+# GD64-REL-NEXT:   0x20428 R_LARCH_TLS_DESC64 -
+# GD64-REL-NEXT:   0x203F8 R_LARCH_TLS_DESC64 a
+# GD64-REL-NEXT:   0x20408 R_LARCH_TLS_DESC64 c
+# GD64-REL-NEXT:   0x20418 R_LARCH_TLS_DESC64 d
 # GD64-REL-NEXT: }
 # GD64-REL:      Hex dump of section '.got':
-# GD64-REL-NEXT: 0x000203b8 00000000 00000000 00000000 00000000 .
-# GD64-REL-NEXT: 0x000203c8 00000000 00000000 00000000 00000000 .
-# GD64-REL-NEXT: 0x000203d8 00000000 00000000 ff070000 00000000 .
+# GD64-REL-NEXT: 0x000203f8 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020408 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020418 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020428 00000000 00000000 ff070000 00000000 .
 
-# GD64:      .got     00000030 00000000000203d0
+# GD64:      .got     00000040 0000000000020418
 
-## &.got[a]-. = 0x203d0 - 0x102e0 = 16444<<2
-# GD64:        102e0: pcaddi $a0, 16444
+## &.got[a]-. = 0x20418 - 0x10318 = 16448<<2
+# GD64:        10318: pcaddi $a0, 16448
 # GD64-NEXT:          ld.d $ra, $a0, 0
 # GD64-NEXT:          jirl $ra, $ra, 0
 # GD64-NEXT:          add.d $a1, $a0, $tp
 
-## &.got[b]-. = 0x203d0+32 - 0x102f0 = 16448<<2
-# GD64:        102f0: pcaddi $a0, 16448
+## &.got[b]-. = 0x20418+48 - 0x10328 = 16456<<2
+# GD64:        10328: pcaddi $a0, 16456
 # GD64-NEXT:          ld.d $ra, $a0, 0
 # GD64-NEXT:          jirl $ra, $ra, 0
 # GD64-NEXT:          add.d $a2, $a0, $tp
 
-## &.got[c]-. = 0x203d0+16 - 0x10300 = 16440<<2
-# GD64:        10300: pcaddi $a0, 16440
+## &.got[c]-. = 0x20418+16 - 0x10338 = 16444<<2
+# GD64:        10338: pcaddi $a0, 16444
 # GD64-NEXT:          ld.d $ra, $a0, 0
 # GD64-NEXT:          jirl $ra, $ra, 0
 # GD64-NEXT:          add.d $a3, $a0, $tp
 
+## &.got[d]-. = 0x20418+32 - 0x10348 = 16444<<2
+# GD64:        10348: pcaddi $a0, 16444
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a4, $a0, $tp
+
 # LE64-RELA:      .rela.dyn {
-# LE64-RELA-NEXT:   0x30240 R_LARCH_TLS_DESC64 - 0x8
-# LE64-RELA-NEXT:   0x30250 R_LARCH_TLS_DESC64 - 0x800
-# LE64-RELA-NEXT:   0x30260 R_LARCH_TLS_DESC64 - 0x7FF
+# LE64-RELA-NEXT:   0x30268 R_LARCH_TLS_DESC64 - 0x8
+# LE64-RELA-NEXT:   0x30278 R_LARCH_TLS_DESC64 - 0x800
+# LE64-RELA-NEXT:   0x30288 R_LARCH_TLS_DESC64 - 0x1000
+# LE64-RELA-NEXT:   0x30298 R_LARCH_TLS_DESC64 - 0x7FF
 # LE64-RELA-NEXT: }
 # LE64-RELA:      Hex dump of section '.got':
-# LE64-RELA-NEXT: 0x00030240 00000000 00000000 00000000 00000000 .
-# LE64-RELA-NEXT: 0x00030250 00000000 00000000 00000000 00000000 .
-# LE64-RELA-NEXT: 0x00030260 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030268 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030278 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030288 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030298 00000000 00000000 00000000 00000000 .
 
 # IE64-RELA:      .rela.dyn {
-# IE64-RELA-NEXT:   0x303C8 R_LARCH_TLS_DESC64 - 0x8
-# IE64-RELA-NEXT:   0x303E8 R_LARCH_TLS_DESC64 - 0x7FF
-# IE64-RELA-NEXT:   0x303D8 R_LARCH_TLS_DESC64 c 0x0
+# IE64-RELA-NEXT:   0x30418 R_LARCH_TLS_DESC64 - 0x8
+# IE64-RELA-NEXT:   0x30448 R_LARCH_TLS_DESC64 - 0x7FF
+# IE64-RELA-NEXT:   0x30428 R_LARCH_TLS_DESC64 c 0x0
+# IE64-RELA-NEXT:   0x30438 R_LARCH_TLS_DESC64 d 0x0
 # IE64-RELA-NEXT: }
 # IE64-RELA:      Hex dump of section '.got':
-# IE64-RELA-NEXT: 0x000303c8 00000000 00000000 00000000 00000000 .
-# IE64-RELA-NEXT: 0x000303d8 00000000 00000000 00000000 00000000 .
-# IE64-RELA-NEXT: 0x000303e8 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030418 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030428 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030438 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030448 00000000 00000000 00000000 00000000 .
 
 # GD32-REL:      .rel.dyn {
-# GD32-REL-NEXT:    0x20264 R_LARCH_TLS_DESC32 -
-# GD32-REL-NEXT:    0x20254 R_LARCH_TLS_DESC32 a
-# GD32-REL-NEXT:    0x2025C R_LARCH_TLS_DESC32 c
+# GD32-REL-NEXT:    0x202A4 R_LARCH_TLS_DESC32 -
+# GD32-REL-NEXT:    0x2028C R_LARCH_TLS_DESC32 a
+# GD32-REL-NEXT:    0x20294 R_LARCH_TLS_DESC32 c
+# GD32-REL-NEXT:    0x2029C R_LARCH_TLS_DESC32 d
 # GD32-REL-NEXT: }
 # GD32-REL:      Hex dump of section '.got':
-# GD32-REL-NEXT: 0x00020254 00000000 00000000 00000000 00000000 .
-# GD32-REL-NEXT: 0x00020264 00000000 ff070000                   .
+# GD32-REL-NEXT: 0x0002028c 00000000 00000000 00000000 00000000 .
+# GD32-REL-NEXT: 0x0002029c 00000000 00000000 00000000 ff070000 .
 
 #--- a.s
 .macro add dst, src1, src2
@@ -128,6 +143,11 @@ load $ra, $a0, %desc_ld(c)
 jirl $ra, $ra, %desc_call(c)
 add $a3, $a0, $tp
 
+pcaddi $a0, %desc_pcrel_20(d)
+load $ra, $a0, %desc_ld(d)
+jirl $ra, $ra, %desc_call(d)
+add $a4, $a0, $tp
+
 .section .tbss,"awT", at nobits
 .globl a
 .zero 8
@@ -138,5 +158,8 @@ b:
 
 #--- c.s
 .section .tbss,"awT", at nobits
-.globl c
-c: .zero 4
+.globl c, d
+c:
+.zero 2048  ## Place d at 0x1000
+d:
+.zero 4
diff --git a/lld/test/ELF/loongarch-tlsdesc.s b/lld/test/ELF/loongarch-tlsdesc.s
index bf09b1e4bbae92..8c49ab31320275 100644
--- a/lld/test/ELF/loongarch-tlsdesc.s
+++ b/lld/test/ELF/loongarch-tlsdesc.s
@@ -29,76 +29,92 @@
 # RUN: llvm-readobj -r -x .got rel.32.so | FileCheck --check-prefix=GD32-REL %s
 
 # GD64-RELA:      .rela.dyn {
-# GD64-RELA-NEXT:   0x20400 R_LARCH_TLS_DESC64 - 0x7FF
-# GD64-RELA-NEXT:   0x203E0 R_LARCH_TLS_DESC64 a 0x0
-# GD64-RELA-NEXT:   0x203F0 R_LARCH_TLS_DESC64 c 0x0
+# GD64-RELA-NEXT:   0x20458 R_LARCH_TLS_DESC64 - 0x7FF
+# GD64-RELA-NEXT:   0x20428 R_LARCH_TLS_DESC64 a 0x0
+# GD64-RELA-NEXT:   0x20438 R_LARCH_TLS_DESC64 c 0x0
+# GD64-RELA-NEXT:   0x20448 R_LARCH_TLS_DESC64 d 0x0
 # GD64-RELA-NEXT: }
 # GD64-RELA:      Hex dump of section '.got':
-# GD64-RELA-NEXT: 0x000203e0 00000000 00000000 00000000 00000000 .
-# GD64-RELA-NEXT: 0x000203f0 00000000 00000000 00000000 00000000 .
-# GD64-RELA-NEXT: 0x00020400 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020428 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020438 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020448 00000000 00000000 00000000 00000000 .
+# GD64-RELA-NEXT: 0x00020458 00000000 00000000 00000000 00000000 .
 
 # GD64-REL:      .rel.dyn {
-# GD64-REL-NEXT:   0x203E8 R_LARCH_TLS_DESC64 -
-# GD64-REL-NEXT:   0x203C8 R_LARCH_TLS_DESC64 a
-# GD64-REL-NEXT:   0x203D8 R_LARCH_TLS_DESC64 c
+# GD64-REL-NEXT:   0x20438 R_LARCH_TLS_DESC64 -
+# GD64-REL-NEXT:   0x20408 R_LARCH_TLS_DESC64 a
+# GD64-REL-NEXT:   0x20418 R_LARCH_TLS_DESC64 c
+# GD64-REL-NEXT:   0x20428 R_LARCH_TLS_DESC64 d
 # GD64-REL-NEXT: }
 # GD64-REL:      Hex dump of section '.got':
-# GD64-REL-NEXT: 0x000203c8 00000000 00000000 00000000 00000000 .
-# GD64-REL-NEXT: 0x000203d8 00000000 00000000 00000000 00000000 .
-# GD64-REL-NEXT: 0x000203e8 00000000 00000000 ff070000 00000000 .
+# GD64-REL-NEXT: 0x00020408 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020418 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020428 00000000 00000000 00000000 00000000 .
+# GD64-REL-NEXT: 0x00020438 00000000 00000000 ff070000 00000000 .
 
-# GD64:      .got     00000030 00000000000203e0
+# GD64:      .got     00000040 0000000000020428
 
-## &.got[a]-. = 0x203e0 - 0x102e0: 0x10 pages, page offset 0x3e0
-# GD64:        102e0: pcalau12i $a0, 16
-# GD64-NEXT:          addi.d $a0, $a0, 992
+## &.got[a]-. = 0x20428 - 0x10318: 0x10 pages, page offset 0x428
+# GD64:        10318: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d $a0, $a0, 1064
 # GD64-NEXT:          ld.d $ra, $a0, 0
 # GD64-NEXT:          jirl $ra, $ra, 0
 # GD64-NEXT:          add.d $a1, $a0, $tp
 
-## &.got[b]-. = 0x203e0+32 - 0x102f4: 0x10 pages, page offset 0x400
-# GD64:        102f4: pcalau12i $a0, 16
-# GD64-NEXT:          addi.d $a0, $a0, 1024
+## &.got[b]-. = 0x20428+48 - 0x1032c: 0x10 pages, page offset 0x458
+# GD64:        1032c: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d $a0, $a0, 1112
 # GD64-NEXT:          ld.d $ra, $a0, 0
 # GD64-NEXT:          jirl $ra, $ra, 0
 # GD64-NEXT:          add.d $a2, $a0, $tp
 
-## &.got[c]-. = 0x23e0+16 - 0x10308: 0x10 pages, page offset 0x3f0
-# GD64:        10308: pcalau12i $a0, 16
-# GD64-NEXT:          addi.d $a0, $a0, 1008
+## &.got[c]-. = 0x20428+16 - 0x10340: 0x10 pages, page offset 0x438
+# GD64:        10340: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d $a0, $a0, 1080
 # GD64-NEXT:          ld.d $ra, $a0, 0
 # GD64-NEXT:          jirl $ra, $ra, 0
 # GD64-NEXT:          add.d $a3, $a0, $tp
 
+## &.got[d]-. = 0x20428+32 - 0x10354: 0x10 pages, page offset 0x448
+# GD64:        10354: pcalau12i $a0, 16
+# GD64-NEXT:          addi.d $a0, $a0, 1096
+# GD64-NEXT:          ld.d $ra, $a0, 0
+# GD64-NEXT:          jirl $ra, $ra, 0
+# GD64-NEXT:          add.d $a4, $a0, $tp
+
 # LE64-RELA:      .rela.dyn {
-# LE64-RELA-NEXT:   0x30250 R_LARCH_TLS_DESC64 - 0x8
-# LE64-RELA-NEXT:   0x30260 R_LARCH_TLS_DESC64 - 0x800
-# LE64-RELA-NEXT:   0x30270 R_LARCH_TLS_DESC64 - 0x7FF
+# LE64-RELA-NEXT:   0x30278 R_LARCH_TLS_DESC64 - 0x8
+# LE64-RELA-NEXT:   0x30288 R_LARCH_TLS_DESC64 - 0x800
+# LE64-RELA-NEXT:   0x30298 R_LARCH_TLS_DESC64 - 0x1000
+# LE64-RELA-NEXT:   0x302A8 R_LARCH_TLS_DESC64 - 0x7FF
 # LE64-RELA-NEXT: }
 # LE64-RELA:      Hex dump of section '.got':
-# LE64-RELA-NEXT: 0x00030250 00000000 00000000 00000000 00000000 .
-# LE64-RELA-NEXT: 0x00030260 00000000 00000000 00000000 00000000 .
-# LE64-RELA-NEXT: 0x00030270 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030278 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030288 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x00030298 00000000 00000000 00000000 00000000 .
+# LE64-RELA-NEXT: 0x000302a8 00000000 00000000 00000000 00000000 .
 
 # IE64-RELA:      .rela.dyn {
-# IE64-RELA-NEXT:   0x303D8 R_LARCH_TLS_DESC64 - 0x8
-# IE64-RELA-NEXT:   0x303F8 R_LARCH_TLS_DESC64 - 0x7FF
-# IE64-RELA-NEXT:   0x303E8 R_LARCH_TLS_DESC64 c 0x0
+# IE64-RELA-NEXT:   0x30428 R_LARCH_TLS_DESC64 - 0x8
+# IE64-RELA-NEXT:   0x30458 R_LARCH_TLS_DESC64 - 0x7FF
+# IE64-RELA-NEXT:   0x30438 R_LARCH_TLS_DESC64 c 0x0
+# IE64-RELA-NEXT:   0x30448 R_LARCH_TLS_DESC64 d 0x0
 # IE64-RELA-NEXT: }
 # IE64-RELA:      Hex dump of section '.got':
-# IE64-RELA-NEXT: 0x000303d8 00000000 00000000 00000000 00000000 .
-# IE64-RELA-NEXT: 0x000303e8 00000000 00000000 00000000 00000000 .
-# IE64-RELA-NEXT: 0x000303f8 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030428 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030438 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030448 00000000 00000000 00000000 00000000 .
+# IE64-RELA-NEXT: 0x00030458 00000000 00000000 00000000 00000000 .
 
 # GD32-REL:      .rel.dyn {
-# GD32-REL-NEXT:    0x20270 R_LARCH_TLS_DESC32 -
-# GD32-REL-NEXT:    0x20260 R_LARCH_TLS_DESC32 a
-# GD32-REL-NEXT:    0x20268 R_LARCH_TLS_DESC32 c
+# GD32-REL-NEXT:    0x202B4 R_LARCH_TLS_DESC32 -
+# GD32-REL-NEXT:    0x2029C R_LARCH_TLS_DESC32 a
+# GD32-REL-NEXT:    0x202A4 R_LARCH_TLS_DESC32 c
+# GD32-REL-NEXT:    0x202AC R_LARCH_TLS_DESC32 d
 # GD32-REL-NEXT: }
 # GD32-REL:      Hex dump of section '.got':
-# GD32-REL-NEXT: 0x00020260 00000000 00000000 00000000 00000000 .
-# GD32-REL-NEXT: 0x00020270 00000000 ff070000                   .
+# GD32-REL-NEXT: 0x0002029c 00000000 00000000 00000000 00000000 .
+# GD32-REL-NEXT: 0x000202ac 00000000 00000000 00000000 ff070000 .
 
 #--- a.s
 .macro add dst, src1, src2
@@ -118,6 +134,9 @@ add $a2, $a0, $tp
 la.tls.desc $a0, c
 add $a3, $a0, $tp
 
+la.tls.desc $a0, d
+add $a4, $a0, $tp
+
 .section .tbss,"awT", at nobits
 .globl a
 .zero 8
@@ -128,5 +147,8 @@ b:
 
 #--- c.s
 .section .tbss,"awT", at nobits
-.globl c
-c: .zero 4
+.globl c, d
+c:
+.zero 2048  ## Place d at 0x1000
+d:
+.zero 4

>From afce9371c9e79518726491ad1a8d6e3ff1c4a6cb Mon Sep 17 00:00:00 2001
From: yangzhaoxin <yangzhaoxin at loongson.cn>
Date: Wed, 25 Dec 2024 17:32:24 +0800
Subject: [PATCH 2/2] Delete redundant macro.

---
 lld/test/ELF/loongarch-tlsdesc-extreme.s | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/lld/test/ELF/loongarch-tlsdesc-extreme.s b/lld/test/ELF/loongarch-tlsdesc-extreme.s
index 47b23b7987a389..84427152ba36da 100644
--- a/lld/test/ELF/loongarch-tlsdesc-extreme.s
+++ b/lld/test/ELF/loongarch-tlsdesc-extreme.s
@@ -147,31 +147,23 @@
 # IE64-RELA-NEXT: 0x00030558 00000000 00000000 00000000 00000000 .
 
 #--- a.s
-.macro add dst, src1, src2
-.ifdef ELF32
-add.w \dst, \src1, \src2
-.else
-add.d \dst, \src1, \src2
-.endif
-.endm
-
 la.tls.desc $a0, $t0, a
-add $a1, $a0, $tp
+add.d $a1, $a0, $tp
 
 la.tls.desc $a0, $t0, b
-add $a2, $a0, $tp
+add.d $a2, $a0, $tp
 
 la.tls.desc $a0, $t0, c
-add $a3, $a0, $tp
+add.d $a3, $a0, $tp
 
 la.tls.desc $a0, $t0, d
-add $a4, $a0, $tp
+add.d $a4, $a0, $tp
 
 la.tls.desc $a0, $t0, e
-add $a5, $a0, $tp
+add.d $a5, $a0, $tp
 
 la.tls.desc $a0, $t0, f
-add $a6, $a0, $tp
+add.d $a6, $a0, $tp
 
 .section .tbss,"awT", at nobits
 .globl a



More information about the llvm-commits mailing list