[all-commits] [llvm/llvm-project] 6fa134: [ELF] Resolve R_DTPREL in .debug_* referencing dis...

Fangrui Song via All-commits all-commits at lists.llvm.org
Fri Jul 3 09:52:00 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 6fa1343bb3e8a59116cdafc4186c85d6c6ce12df
      https://github.com/llvm/llvm-project/commit/6fa1343bb3e8a59116cdafc4186c85d6c6ce12df
  Author: Fangrui Song <maskray at google.com>
  Date:   2020-07-03 (Fri, 03 Jul 2020)

  Changed paths:
    M lld/ELF/InputSection.cpp
    A lld/test/ELF/debug-dead-reloc-tls-arm.s
    A lld/test/ELF/debug-dead-reloc-tls.s
    R lld/test/ELF/gc-debuginfo-tls.s
    A lld/test/ELF/gc-sections-tls.s

  Log Message:
  -----------
  [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 at DTPREL+0x8000
* riscv: neither GCC nor clang has implemented DW_AT_location. It is likely .long/.quad tls at dtprel+0x800
* x86-32: .long tls at DTPOFF
* x86-64: .long tls at DTPOFF; .quad tls at 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




More information about the All-commits mailing list