[llvm-dev] Relocations used for PPC32 in non-PIC mode

vit9696 via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 4 09:03:00 PDT 2017


Hello,

I am currently facing an issue at linking stage when compiling basic C code for an embedded PPC32 platform and linking with LLD. For external symbol linkage LLVM appears to use PLT which results in generating a R_PPC_PLTREL24 relocation, that is not support by LDD. Therefore even such a basic example cannot be built:

/* s.c */
int f() { return 0; }

/* t.c */
int f();
int _start() { return f(); }

$ clang -c -target ppc32-gnu-linux-eabi t.c -o t.o
$ clang -c -target ppc32-gnu-linux-eabi s.c -o s.o
$ ld.lld t.o s.o -o t
ld.lld: error: t.c:(function _start): unrecognized reloc 18

When I tried ld.bfd the objects linked fine, so I initially thought that it was a lld issue. Yet, after I checked the source code, I started to feel that PLT use on PPC32 is not even desired, and it is likely just an overlooked regression. If you check the original code, PLT was only meant to be used with PIC code: https://reviews.llvm.org/rL213427#C65598OL3360. Note, that there are two places covering the PPCII::MO_PLT_OR_STUB assignment, which are both guarded with getRelocationModel check.

Now let's look at https://reviews.llvm.org/rL273499#C65598OL4294 and https://reviews.llvm.org/rL273595#C65598OL4316. For some unknown reason these two commits silently removed -fno-pic handling, and effectively enforced PLT use. As a result they broke the compatibility with linkers not implementing PLT-relative relocations.

While it might be good for LLD to support R_PPC_PLTREL24, in my opinion there still is no reason for LLVM to emit this in non-PIC mode. If my understanding is correct, I can submit a patch that will replace

bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64;

with

bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64 &&
              DAG.getTarget().getRelocationModel() == Reloc::PIC_;

Vit

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171004/a23f3dbd/attachment.sig>


More information about the llvm-dev mailing list