[PATCH] D91611: [PowerPC][LLD] Detecting and fixing missing TLS relocation on __tls_get_addr
Stefan Pintilie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 17 03:35:29 PST 2020
stefanp created this revision.
stefanp added reviewers: nemanjai, MaskRay, NeHuang, sfertile.
Herald added subscribers: dang, shchenz, kbarton, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
stefanp requested review of this revision.
This is a replacement and extension for this patch:
https://reviews.llvm.org/D85994
The standard representation of Thread Local Storage (TLS) is as follows:
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
The above is specified in the Power PC ELFv2 ABI in section:
3.7.3.1. General Dynamic TLS Model
However, there are two deviations form the above that have been seen in actual
code.
1. A direct call to __tls_get_addr.
bl __tls_get_addr
nop
2. Missing R_PPC64_TLSGD relocation.
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_REL24
nop
Both forms are technically not valid according to the ABI. No new code should
be producing either of the two forms.
However, a direct call does not cause lld to produce incorrect code gen. If
the user is careful enough to correctly setup the inputs to the function the
code will work. Also, it appears that some implementations of ld.so do this
direct call. Therefore, this patch silently allows for the simple direct call.
The second situation where the R_PPC64_TLSGD relocation is missing is a
different story. Generating the second code sequence will cause lld to produce
incorrect code gen when relaxing the sequence to Local Exec. The first two
relocations (R_PPC64_GOT_TLSGD16_HA and R_PPC64_GOT_TLSGD16_LO) will be relaxed
correctly but since the call is missing a relocation it will be left as-is
which will ultimately result in an incorrect TLS address being computed. This
patch tries to address the problem of the missing R_PPC64_TLSGD relocaiton.
An option has been added --add-missing-tls-reloc.
By default if the option is not specified lld will report an error or a warning
when the missing relocation is encountered. If the option is specified then lld
will try to add the missing relocation to the __tls_get_addr call.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91611
Files:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/ELF/Relocations.cpp
lld/test/ELF/ppc64-call-tls-get-addr-exec.s
lld/test/ELF/ppc64-call-tls-get-addr-missing.s
lld/test/ELF/ppc64-call-tls-get-addr.s
lld/test/ELF/ppc64-tls-add-missing-gdld.s
lld/test/ELF/ppc64-tls-missing-gdld.s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91611.305722.patch
Type: text/x-patch
Size: 11318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201117/8c671e09/attachment.bin>
More information about the llvm-commits
mailing list