Skip to content

Commit 57b98e6

Browse files
ilovepillvmbot
authored andcommitted
[llvm][lld] Pre-commit tests for RISCV TLSDESC symbols
Currently, we mistakenly mark the local labels used in RISC-V TLSDESC as TLS symbols, when they should not be. This patch adds tests with the current incorrect behavior, and subsequent patches will address the issue. Reviewers: MaskRay, topperc Reviewed By: MaskRay Pull Request: #85816 (cherry picked from commit f6f474c)
1 parent bce9393 commit 57b98e6

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lld/test/ELF/riscv-tlsdesc.s

+25
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
# RUN: ld.lld -e 0 -z now a.32.o c.32.so -o a.32.ie
3030
# RUN: llvm-objdump --no-show-raw-insn -M no-aliases -h -d a.32.ie | FileCheck %s --check-prefix=IE32
3131

32+
# RUN: llvm-mc -triple=riscv64 -filetype=obj d.s -o d.64.o
33+
# RUN: not ld.lld -shared -soname=d.64.so -o d.64.so d.64.o 2>&1 | FileCheck %s --check-prefix=BADTLSLABEL
34+
35+
# RUN: llvm-mc -triple=riscv32 -filetype=obj d.s -o d.32.o --defsym ELF32=1
36+
# RUN: not ld.lld -shared -soname=d.32.so -o d.32.so d.32.o 2>&1 | FileCheck %s --check-prefix=BADTLSLABEL
37+
3238
# GD64-RELA: .rela.dyn {
3339
# GD64-RELA-NEXT: 0x2408 R_RISCV_TLSDESC - 0x7FF
3440
# GD64-RELA-NEXT: 0x23E8 R_RISCV_TLSDESC a 0x0
@@ -150,6 +156,9 @@
150156
# IE32-NEXT: lw a0, 0x80(a0)
151157
# IE32-NEXT: add a0, a0, tp
152158

159+
## FIXME This should not pass, but the code MC layer needs a fix to prevent this.
160+
# BADTLSLABEL: error: d.{{.*}}.o has an STT_TLS symbol but doesn't have an SHF_TLS section
161+
153162
#--- a.s
154163
.macro load dst, src
155164
.ifdef ELF32
@@ -192,3 +201,19 @@ b:
192201
.tbss
193202
.globl c
194203
c: .zero 4
204+
205+
#--- d.s
206+
.macro load dst, src
207+
.ifdef ELF32
208+
lw \dst, \src
209+
.else
210+
ld \dst, \src
211+
.endif
212+
.endm
213+
214+
.Ltlsdesc_hi0:
215+
auipc a0, %tlsdesc_hi(foo)
216+
load a1, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a0)
217+
addi a0, a0, %tlsdesc_add_lo(.Ltlsdesc_hi0)
218+
jalr t0, 0(a1), %tlsdesc_call(.Ltlsdesc_hi0)
219+
add a1, a0, tp
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
;; The test in this file do not appear in tls-models.ll because
2+
;; they are not auto-generated.
3+
; RUN: llc -mtriple=riscv64 -relocation-model=pic -enable-tlsdesc < %s \
4+
; RUN: | llvm-mc -triple=riscv64 -filetype=obj -o - \
5+
; RUN: | llvm-readelf --symbols - \
6+
; RUN: | FileCheck %s
7+
8+
; RUN: llc -mtriple=riscv32 -relocation-model=pic -enable-tlsdesc < %s \
9+
; RUN: | llvm-mc -triple=riscv32 -filetype=obj -o - \
10+
; RUN: | llvm-readelf --symbols - \
11+
; RUN: | FileCheck %s
12+
13+
; Check that TLS symbols are lowered correctly based on the specified
14+
; model. Make sure they're external to avoid them all being optimised to Local
15+
; Exec for the executable.
16+
17+
@unspecified = external thread_local global i32
18+
19+
define ptr @f1() nounwind {
20+
entry:
21+
ret ptr @unspecified
22+
; CHECK: Symbol table '.symtab' contains 7 entries:
23+
; CHECK: TLS {{.*}} unspecified
24+
}

0 commit comments

Comments
 (0)