[PATCH] D13825: [ELF2] Don't create RelativeReloc for weak undef symbols
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 13:24:36 PDT 2015
The test I think is correct. Give me a minute to see if there is a
better place in the code to put the check.
On 16 October 2015 at 15:30, hfinkel at anl.gov <hfinkel at anl.gov> wrote:
> hfinkel created this revision.
> hfinkel added reviewers: rafael, ruiu.
> hfinkel added a subscriber: llvm-commits.
> hfinkel added a project: lld.
>
> When we have a R_PPC64_ADDR64 for a weak undef symbol, which thus resolves to 0, and we're creating a shared library, we need to make sure that it stays 0 (because code that conditionally calls the weak function tests for this). Unfortunately, we were creating a R_PPC64_RELATIVE for these relocation targets, making the address of the undefined weak symbol equal to the base address of the shared library (which is non-zero). It seems like, in general, we should not be creating RelativeReloc relocs for undef weak symbols.
>
>
> http://reviews.llvm.org/D13825
>
> Files:
> ELF/Writer.cpp
> test/elf2/ppc64-weak-undef-call-shared.s
>
> Index: test/elf2/ppc64-weak-undef-call-shared.s
> ===================================================================
> --- /dev/null
> +++ test/elf2/ppc64-weak-undef-call-shared.s
> @@ -0,0 +1,11 @@
> +# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
> +# RUN: ld.lld2 -shared %t.o -o %t.so
> +# RUN: llvm-readobj -t -r -dyn-symbols %t.so | FileCheck %s
> +# REQUIRES: ppc
> +
> +.section ".toc","aw"
> +.quad weakfunc
> +// CHECK-NOT: R_PPC64_RELATIVE
> +
> +.weak weakfunc
> +
> Index: ELF/Writer.cpp
> ===================================================================
> --- ELF/Writer.cpp
> +++ ELF/Writer.cpp
> @@ -201,7 +201,8 @@
> }
>
> bool CBP = canBePreempted(Body, NeedsGot);
> - if (!CBP && (!Config->Shared || Target->isRelRelative(Type)))
> + if (!CBP && (!Config->Shared || Target->isRelRelative(Type) ||
> + (Body && Body->isWeak() && Body->isUndefined())))
> continue;
> if (CBP)
> Body->setUsedInDynamicReloc();
>
>
More information about the llvm-commits
mailing list