[PATCH] D38554: Fixed ppc32 function relocations in non-pic mode

vit9696 via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 4 14:50:53 PDT 2017


vit9696 added a comment.

In https://reviews.llvm.org/D38554#888793, @joerg wrote:

> Let's start with the obvious: I have no idea why you need this code at all. NetBSD builds a mix of static, PIC and PIE code using GNU ld without hitting any unsupported relocations. As I said before, the normal ABI on PowerPC is mostly PIC by default. I wonder if the root of your problem is that you want EABI and not the SYSV ABI.


Just as mentioned on the lists this is needed for a custom embedded platform that indeed uses eabi (PIC executables are currently not compatible with the loader).
Let me make things clearer, especially since somebody mentioned PIE here, though I do not see this comment at the moment.

There is PIC and there is PIE. PIE just makes it possible to offset the whole image, and it is unrelated to this issue like at all. Both PIC and PIE are controlled by compiler arguments (-fpic, -fpie, -fno-pic, -fno-pie). Each target has its defaults as well, making LLVM assume which one should be used if no argument is provided. Indeed in System-V ABI PIC is normally the default one, thus effectively getRelocationModel() == Reloc::PIC_ will evaluate to true.

Now to what PLT has to do to it:

- PIC implies that all the function calls go through a PLT table, and thus the linker should implement PLT-relative relocations (e.g. R_PPC_PLTREL24).
- non-PIC implies that the functions may directly call each other (e.g. via absolute or relative relocations like R_PPC_REL24).

Nobody forbids the use of PLT in PIC mode, however that's not how things work. Neither gcc, nor llvm (until the mentioned regression) use a PLT table in non-PIC mode. There is simply no reason to add an extra address indirection layer. Yet starting with r273499 LLVM erroneously enforced PLT table addition in non-PIC mode. That means that now even when one specifies -fno-pic explicitly PLT table will be used.

This is wrong and undesired, and this bug is what the presented patch fixes. It does not change the defaults for your ABI: if your defaults are PIC, then you get your PIC/PLT. It only makes -fno-pic be actually non-PIC but not using a PLT table.

Hope that makes it clear and allows the reviewers to accept the patch in the nearest future :)


https://reviews.llvm.org/D38554





More information about the llvm-commits mailing list