Skip to content

[llvm][lld] Pre-commit tests for RISCV TLSDESC symbols #85816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lld/test/ELF/riscv-tlsdesc.s
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
# RUN: ld.lld -e 0 -z now a.32.o c.32.so -o a.32.ie
# RUN: llvm-objdump --no-show-raw-insn -M no-aliases -h -d a.32.ie | FileCheck %s --check-prefix=IE32

# RUN: llvm-mc -triple=riscv64 -filetype=obj d.s -o d.64.o
# RUN: not ld.lld -shared -soname=d.64.so -o d.64.so d.64.o 2>&1 | FileCheck %s --check-prefix=BADTLSLABEL

# RUN: llvm-mc -triple=riscv32 -filetype=obj d.s -o d.32.o --defsym ELF32=1
# RUN: not ld.lld -shared -soname=d.32.so -o d.32.so d.32.o 2>&1 | FileCheck %s --check-prefix=BADTLSLABEL

# GD64-RELA: .rela.dyn {
# GD64-RELA-NEXT: 0x2408 R_RISCV_TLSDESC - 0x7FF
# GD64-RELA-NEXT: 0x23E8 R_RISCV_TLSDESC a 0x0
Expand Down Expand Up @@ -150,6 +156,9 @@
# IE32-NEXT: lw a0, 0x80(a0)
# IE32-NEXT: add a0, a0, tp

## FIXME This should not pass, but the code MC layer needs a fix to prevent this.
# BADTLSLABEL: error: d.{{.*}}.o has an STT_TLS symbol but doesn't have an SHF_TLS section

#--- a.s
.macro load dst, src
.ifdef ELF32
Expand Down Expand Up @@ -192,3 +201,19 @@ b:
.tbss
.globl c
c: .zero 4

#--- d.s
.macro load dst, src
.ifdef ELF32
lw \dst, \src
.else
ld \dst, \src
.endif
.endm

.Ltlsdesc_hi0:
auipc a0, %tlsdesc_hi(foo)
load a1, %tlsdesc_load_lo(.Ltlsdesc_hi0)(a0)
addi a0, a0, %tlsdesc_add_lo(.Ltlsdesc_hi0)
jalr t0, 0(a1), %tlsdesc_call(.Ltlsdesc_hi0)
add a1, a0, tp
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/RISCV/tlsdesc-symbol.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;; The test in this file do not appear in tls-models.ll because
;; they are not auto-generated.
; RUN: llc -mtriple=riscv64 -relocation-model=pic -enable-tlsdesc < %s \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this extra file is file.

Best to reference tls-models.ll

; RUN: | llvm-mc -triple=riscv64 -filetype=obj -o - \
; RUN: | llvm-readelf --symbols - \
; RUN: | FileCheck %s

; RUN: llc -mtriple=riscv32 -relocation-model=pic -enable-tlsdesc < %s \
; RUN: | llvm-mc -triple=riscv32 -filetype=obj -o - \
; RUN: | llvm-readelf --symbols - \
; RUN: | FileCheck %s

; Check that TLS symbols are lowered correctly based on the specified
; model. Make sure they're external to avoid them all being optimised to Local
; Exec for the executable.

@unspecified = external thread_local global i32

define ptr @f1() nounwind {
entry:
ret ptr @unspecified
; CHECK: Symbol table '.symtab' contains 7 entries:
; CHECK: TLS {{.*}} unspecified
}