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

Hal Finkel via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 4 09:28:39 PDT 2017


Hi, Vit,

I'm not under the impression that ppc support in lld is anywhere near 
ready for use. I had it linking hello world on ppc64 some time ago, and 
it's not clear that ppc is even that far. I'd not adjust anything in 
LLVM based on ppc support in lld right now.

  -Hal

On 10/04/2017 11:03 AM, vit9696 via llvm-dev wrote:
> 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
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171004/f32363c3/attachment.html>


More information about the llvm-dev mailing list