This is an archive of the discontinued LLVM Phabricator instance.

[PPC32] Emit R_PPC_GOT_TPREL16 instead R_PPC_GOT_TPREL16_LO
ClosedPublic

Authored by MaskRay on Aug 28 2019, 11:39 PM.

Details

Summary

Unlike ppc64, which has ADDISgotTprelHA+LDgotTprelL pairs,
ppc32 just uses LDgotTprelL32, so it does not make lots of sense to use
_LO without a paired _HA.

Emit R_PPC_GOT_TPREL16 instead R_PPC_GOT_TPREL16_LO to match GCC, and
get better linker relocation check. Note, R_PPC_GOT_TPREL16_{HA,LO}
don't have good linker support:

(a) lld does not support R_PPC_GOT_TPREL16_{HA,LO}.
(b) Top of tree ld.bfd does not support R_PPC_GOT_REL16_HA Initial-Exec -> Local-Exec relaxation:

// a.o
addis 3, 3, tsd_tls@got@tprel@ha
lwz 3, tsd_tls@got@tprel@l(3)
add 3, 3, tsd_tls@tls
// b.o
.section .tdata,"awT"; .globl tsd_tls; tsd_tls:

// ld/ld-new a.o b.o
internal error, aborting at ../../bfd/elf32-ppc.c:7952 in ppc_elf_relocate_section

Diff Detail

Repository
rL LLVM

Event Timeline

MaskRay created this revision.Aug 28 2019, 11:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2019, 11:39 PM
MaskRay added a reviewer: Restricted Project.Aug 28 2019, 11:40 PM
adalava accepted this revision.Aug 29 2019, 6:20 AM

This solution works for me.
Validated it on FreeBSD13-CURRENT/powerpc64, with 32 bit compatibility libraries built using this patch over LLVM9.

This revision is now accepted and ready to land.Aug 29 2019, 6:20 AM
jsji added a subscriber: Ha.EditedAug 29 2019, 11:31 AM

The change looks fine to me, as LLVM currently doesn't generate relocation pairs.

However, I think in theory linker should support R_PPC_GOT_TPREL16_LO even with PPC32.

As they are well defined according to the PPC 32 Linux ABI here:
https://www.polyomino.org.uk/publications/2011/Power-Arch-32-bit-ABI-supp-1.0-Linux.pdf

Table 4-36. TLS Relocation Table

R_PPC_GOT_TPREL16 87 half16* tprelg
R_PPC_GOT_TPREL16_LO 88 half16 #lo(tprelg)
R_PPC_GOT_TPREL16_HI 89 half16 #hi(tprelg)
R_PPC_GOT_TPREL16_HA 90 half16 #ha(tprelg)

jsji removed a subscriber: Ha.Aug 29 2019, 1:42 PM

The change looks fine to me, as LLVM currently doesn't generate relocation pairs.

However, I think in theory linker should support R_PPC_GOT_TPREL16_LO even with PPC32.

As they are well defined according to the PPC 32 Linux ABI here:
https://www.polyomino.org.uk/publications/2011/Power-Arch-32-bit-ABI-supp-1.0-Linux.pdf

Table 4-36. TLS Relocation Table

R_PPC_GOT_TPREL16 87 half16* tprelg
R_PPC_GOT_TPREL16_LO 88 half16 #lo(tprelg)
R_PPC_GOT_TPREL16_HI 89 half16 #hi(tprelg)
R_PPC_GOT_TPREL16_HA 90 half16 #ha(tprelg)

I think it might be nice to use HA/HI pairs to support >32k TP offsets. I remember on a power64 ELFv2 slide it is mentioned that ELFv2 does "medium model" to solve these problems. Since there is not much interest to fix ELFv1 problems, I'll probably not add more stuff to lld/ELF/Arch/PPC.cpp

I'll take that you accepted the patch, and commit it, so that @adalava can quickly file a merge request to release_90.

This revision was automatically updated to reflect the committed changes.
jsji added a comment.Aug 29 2019, 7:31 PM

I'll take that you accepted the patch, and commit it, so that @adalava can quickly file a merge request to release_90.

Sure, OK for me. Thanks.

MaskRay added a subscriber: hans.Aug 30 2019, 3:47 AM

@hans This is a merge candidate:)

hans added a comment.Aug 30 2019, 4:41 AM

@hans This is a merge candidate:)

I've replied on https://bugs.llvm.org/show_bug.cgi?id=43178
I think it's too late to merge this for 9.0.0.