[lld] r250101 - [ELF2] Add a base set of PPC64 relocations

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 16:12:16 PDT 2015


----- Original Message -----
> From: "Rafael EspĂ­ndola" <rafael.espindola at gmail.com>
> To: "Hal Finkel" <hfinkel at anl.gov>
> Cc: "llvm-commits" <llvm-commits at lists.llvm.org>
> Sent: Wednesday, October 14, 2015 1:47:56 PM
> Subject: Re: [lld] r250101 - [ELF2] Add a base set of PPC64 relocations
> 
> > It looks like gold and bfd have a funny logic as to when a weak
> > undefined shows up in dynamic revocations.
> >
> > Given
> >
> >         .globl _start
> > _start:
> >         .weak sym1
> >         .long sym1 at gotpcrel
> >         .weak sym2
> >         .long sym2 at plt
> >         .weak sym3
> >         .quad sym3
> >
> > There will be relocs for sym1 and sym2, but I cannot understand the
> > logic. If the dynamic linker must get a chance to look for sym1 and
> > sym2, it must also get one for sym3.
> 
> And it looks like the answer is that there is no reasonable way to
> solve it when a got is not used.
> 
> r250311 implements what I think is the correct behavior. With that
> you
> should be able to remove the extra "(S.isUndefined() && S.isWeak())"
> in the ppc code. Let me know if anything is missing.

Thanks for looking into this. With your change, I do indeed no longer need the '|| (S.isUndefined() && S.isWeak())' in order for hello-world to link. I'll remove it.

So, interestingly (at least to me), the behavior I was worried about with LD_PRELOAD does not seem to work on PPC64/Linux anyway (although it does work on x86_64). Specifically, this:

$ cat /tmp/weaktest/main.c 
#include <stdio.h>
void foo() __attribute__((weak));
int main() {
  if (foo)
    foo();
  else
    printf("no foo()\n");
}

$ cat /tmp/weaktest/foo.c
#include <stdio.h>
void foo() {
  printf("foo()\n");
}

On x86_64 we have:

$ gcc -O3 -o /tmp/weaktest/main /tmp/weaktest/main.c -fPIC
$ gcc -O3 -o /tmp/weaktest/foo.so -shared /tmp/weaktest/foo.c -fPIC

$ /tmp/weaktest/main 
no foo()

$ LD_PRELOAD=/tmp/weaktest/foo.so /tmp/weaktest/main 
foo()

But, on PPC64, we have:

$ gcc -O3 -o /tmp/weaktest/main /tmp/weaktest/main.c -fPIC
$ gcc -O3 -o /tmp/weaktest/foo.so -shared /tmp/weaktest/foo.c -fPIC

$ /tmp/weaktest/main
no foo()

$ LD_PRELOAD=/tmp/weaktest/foo.so /tmp/weaktest/main
no foo()

(and maybe this is related https://sourceware.org/ml/binutils/2008-08/msg00033.html)

Thanks again,
Hal

> 
> Thanks,
> Rafael
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory


More information about the llvm-commits mailing list