[all-commits] [llvm/llvm-project] e25afc: [ELF][PPC64] Detect missing R_PPC64_TLSGD/R_PPC64_...

Fangrui Song via All-commits all-commits at lists.llvm.org
Mon Dec 21 08:50:05 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: e25afcfa51abbd63ddbe943913af1ba61161ab28
      https://github.com/llvm/llvm-project/commit/e25afcfa51abbd63ddbe943913af1ba61161ab28
  Author: Fangrui Song <i at maskray.me>
  Date:   2020-12-21 (Mon, 21 Dec 2020)

  Changed paths:
    M lld/ELF/InputFiles.h
    M lld/ELF/Relocations.cpp
    M lld/test/ELF/ppc64-tls-missing-gdld.s

  Log Message:
  -----------
  [ELF][PPC64] Detect missing R_PPC64_TLSGD/R_PPC64_TLSLD and disable TLS relaxation

Alternative to D91611.

The TLS General Dynamic/Local Dynamic code sequences need to mark
`__tls_get_addr` with R_PPC64_TLSGD or R_PPC64_TLSLD, e.g.

```
addis r3, r2, x at got@tlsgd at ha # R_PPC64_GOT_TLSGD16_HA
addi r3, r3, x at got@tlsgd at l   # R_PPC64_GOT_TLSGD16_LO
bl __tls_get_addr(x at tlsgd)   # R_PPC64_TLSGD followed by R_PPC64_REL24
nop
```

However, there are two deviations form the above:

1. direct call to `__tls_get_addr`. This is essential to implement ld.so in glibc/musl/FreeBSD.

```
bl __tls_get_addr
nop
```

This is only used in a -shared link, and thus not subject to the GD/LD to IE/LE
relaxation issue below.

2. Missing R_PPC64_TLSGD/R_PPC64_TLSGD for compiler generated TLS references

According to Stefan Pintille, "In the early days of the transition from the
ELFv1 ABI that is used for big endian PowerPC Linux distributions to the ELFv2
ABI that is used for little endian PowerPC Linux distributions, there was some
ambiguity in the specification of the relocations for TLS. The GNU linker has
implemented support for correct handling of calls to __tls_get_addr with a
missing relocation.  Unfortunately, we didn't notice that the IBM XL compiler
did not handle TLS according to the updated ABI until we tried linking XL
compiled libraries with LLD."

In short, LLD needs to work around the old IBM XL compiler issue.
Otherwise, if the object file is linked in -no-pie or -pie mode,
the result will be incorrect because the 4 instructions are partially
rewritten (the latter 2 are not changed).

Work around the compiler bug by disable General Dynamic/Local Dynamic to
Initial Exec/Local Exec relaxation. Note, we also disable Initial Exec
to Local Exec relaxation for implementation simplicity, though technically it can be kept.

ppc64-tls-missing-gdld.s demonstrates the updated behavior.

Reviewed By: #powerpc, stefanp, grimar

Differential Revision: https://reviews.llvm.org/D92959




More information about the All-commits mailing list