llvm-project/lld/test/ELF/debug-dead-reloc-tls.s

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
950 B
ArmAsm
Raw Normal View History

[ELF] Resolve R_DTPREL in .debug_* referencing discarded symbols to -1 The location of a TLS variable is encoded as a DW_OP_const4u/DW_OP_const8u followed by a DW_OP_push_tls_address (or DW_OP_GNU_push_tls_address https://sourceware.org/bugzilla/show_bug.cgi?id=11616 ). This change follows up to D81784 and makes relocations types generalized as R_DTPREL (e.g. R_X86_64_DTPOFF{32,64}, R_PPC64_DTPREL64) use -1 as the tombstone value as well. This works for both TLS Variant I and Variant II architectures. * arm: .long tls(tlsldo) # not working currently (R_ARM_TLS_LDO32 is R_ABS) * mips64: .dtpreldword tls+32768 * ppc64: .quad tls@DTPREL+0x8000 * riscv: neither GCC nor clang has implemented DW_AT_location. It is likely .long/.quad tls@dtprel+0x800 * x86-32: .long tls@DTPOFF * x86-64: .long tls@DTPOFF; .quad tls@DTPOFF tls has a non-negative st_value, so such relocations (st_value+addend) never resolve to -1 in a normal (not discarded) case. ``` // clang -fuse-ld=lld -g -ffunction-sections a.c -Wl,--gc-sections // foo and tls will be discarded by --gc-sections. // DW_AT_location [DW_FORM_exprloc] (DW_OP_const8u 0xffffffffffffffff, DW_OP_GNU_push_tls_address) thread_local int tls; int foo() { return ++tls; } int main() {} ``` Also, drop logic added in D26201 intended to address PR30793. It added a test (gc-debuginfo-tls.s) using a non-SHF_ALLOC section and a local symbol, which does not reflect the intended scenario: a relocation in a SHF_ALLOC section referencing a discarded non-local symbol. For such a non .debug_* section, just emit an error. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D82899
2020-07-04 00:50:30 +08:00
# REQUIRES: x86
## Test we resolve relocations referencing TLS symbols in .debug_* sections to
## a tombstone value if the referenced TLS symbol is discarded.
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: ld.lld --gc-sections %t.o -o %t
# RUN: llvm-objdump -s %t | FileCheck %s
# CHECK: Contents of section .debug_info:
# CHECK-NEXT: 0000 ffffffff ffffffff ffffffff ffffffff
# CHECK-NEXT: 0010 ffffffff ffffffff
.globl _start
_start:
ret
.section .tbss,"awT",@nobits
.globl global
local:
global:
.quad 0
.section .debug_info
## On ppc64, .quad local@dtprel+0x8000 (st_value 0 is supposed to point to
## 0x8000 bytes past the start of ## the dynamic TLS vector. References usually
## have an addend of 0x8000). MIPS is similar. RISC-V uses 0x800.
.quad local@dtpoff+0x8000
.quad global@dtpoff+0x8000
## Many other architectures don't use an offset. GCC x86-64 uses a 32-bit value.
.long global@dtpoff
.long -1