[llvm-branch-commits] [lld] [llvm] [RISCV] Support RISC-V TLSDESC in LLD (PR #77516)

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 9 14:50:39 PST 2024


https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/77516

>From ed9f0c9de1e8f75acdae90ef714323147539d215 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Tue, 9 Jan 2024 22:50:19 +0000
Subject: [PATCH] Add checks for both local and global accesses

Created using spr 1.3.4
---
 lld/test/ELF/riscv-tlsdesc-le.s | 45 +++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/lld/test/ELF/riscv-tlsdesc-le.s b/lld/test/ELF/riscv-tlsdesc-le.s
index 6aa670cffb59b8..21541ee5977019 100644
--- a/lld/test/ELF/riscv-tlsdesc-le.s
+++ b/lld/test/ELF/riscv-tlsdesc-le.s
@@ -3,17 +3,23 @@
 // RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t.so | FileCheck %s
 // RUN: llvm-readelf -r %t.so | FileCheck --check-prefix=REL %s
 
-//      CHECK: 00000000000012d8 <_start>:
-// CHECK-NEXT:    12d8:       auipc   a0, 1
-// CHECK-NEXT:    12dc:       ld      a1, 920(a0)
-// CHECK-NEXT:    12e0:       addi    a0, a0, 920
-// CHECK-NEXT:    12e4:       jalr    t0, a1
-// CHECK-NEXT:    12e8:       add     a0, a0, tp
-// CHECK-NEXT:    12ec:       ret
+//      CHECK: 0000000000001318 <_start>:
+// CHECK-NEXT:    1318:       auipc   a0, 1
+// CHECK-NEXT:    131c:       ld      a1, 1008(a0)
+// CHECK-NEXT:    1320:       addi    a0, a0, 1008
+// CHECK-NEXT:    1324:       jalr    t0, a1
+// CHECK-NEXT:    1328:       add     a0, a0, tp
+// CHECK-NEXT:    132c:       auipc   a0, 1
+// CHECK-NEXT:    1330:       ld      a1, 1040(a0)
+// CHECK-NEXT:    1334:       addi    a0, a0, 1040
+// CHECK-NEXT:    1338:       jalr    t0, a1
+// CHECK-NEXT:    133c:       add     a0, a0, tp
+// CHECK-NEXT:    1340:       ret
 
-//      REL: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 2 entries
-//      REL: R_RISCV_TLSDESC_CALL ffffffffffffffe8
-// REL-NEXT: R_RISCV_TLSDESC_CALL 0
+//      REL: Relocation section '.rela.dyn' at offset 0x{{[0-9a-f]+}} contains 3 entries
+//      REL: R_RISCV_TLSDESC_CALL              ffffffffffffffd4
+// REL-NEXT: R_RISCV_TLSDESC_CALL              4
+// REL-NEXT: R_RISCV_TLSDESC_CALL              ffffffffffffffe8
 
 	.text
 	.attribute	4, 16
@@ -23,21 +29,32 @@
 	.p2align	2
 	.type	_start, at function
 _start:                                     # @_start
-# %bb.0:                                # %entry
+// access local variable
 .Ltlsdesc_hi0:
 	auipc	a0, %tlsdesc_hi(unspecified)
 	ld	a1, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a0)
 	addi	a0, a0, %tlsdesc_add_lo(.Ltlsdesc_hi0)
 	jalr	t0, 0(a1), %tlsdesc_call(.Ltlsdesc_hi0)
 	add	a0, a0, tp
+
+// access global variable
+.Ltlsdesc_hi1:
+	auipc	a0, %tlsdesc_hi(unspecified)
+	ld	a1, %tlsdesc_load_lo(.Ltlsdesc_hi1)(a0)
+	addi	a0, a0, %tlsdesc_add_lo(.Ltlsdesc_hi1)
+	jalr	t0, 0(a1), %tlsdesc_call(.Ltlsdesc_hi1)
+	add	a0, a0, tp
 	ret
 .Lfunc_end0:
 	.size	_start, .Lfunc_end0-_start
                                         # -- End function
 	.section	".note.GNU-stack","", at progbits
 
-        .section .tbss,"awT", at nobits
-        .p2align 2
+	.section .tbss,"awT", at nobits
+	.p2align 2
+	.global v1
+v1:
+	.zero    4
 
 unspecified:
-        .zero    4
+	.zero    4



More information about the llvm-branch-commits mailing list