This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC]: Don't allow r0 as a target for LD_GOT_TPREL_L/32
ClosedPublic

Authored by jhibbits on Mar 23 2020, 6:14 PM.

Details

Summary

The linker is free to relax this (relocation R_PPC_GOT_TPREL16) against
R_PPC_TLS, if it sees fit (initial exec to local exec). If r0 is used,
this can generate execution-invalid code (converts to 'addi %rX, %r0,
FOO, which translates in PPC-lingo to li %rX, FOO). Forbid this
instead.

This fixes static binaries using locales on FreeBSD/powerpc
(tested on FreeBSD/powerpcspe).

Diff Detail

Event Timeline

jhibbits created this revision.Mar 23 2020, 6:14 PM

Ah, OK. This makes sense.
I realize that it is not really possible to write a test case to show the allocation of R0 previous to this patch. However, would you modify existing test cases that use regex matching for the target register such as [[REG:[0-9]+]] to something like [[REG:[1-9][0-9]*]] to demonstrate that R0 is not a valid candidate for the regex match?

jhibbits updated this revision to Diff 252405.Mar 24 2020, 12:31 PM

Update tests. Updated other tests in the same file that looked suspect as well.

nemanjai accepted this revision.Mar 26 2020, 8:51 AM

LGTM. Thanks.

This revision is now accepted and ready to land.Mar 26 2020, 8:51 AM
This revision was automatically updated to reflect the committed changes.

Thanks for this change. For PPC32 this helps GNU ld, gold and lld. The TLS Initial-Exec code sequence consists of 2 instructions.

For PPC64, the code sequence consists of 3 instructions. GNU ld and gold seem to special case r0 and use nop; nop; addi 0, 13, -28668 to avoid the issue.