diff options
| author | Hal Finkel <hfinkel@anl.gov> | 2015-10-16 22:11:05 +0000 |
|---|---|---|
| committer | Hal Finkel <hfinkel@anl.gov> | 2015-10-16 22:11:05 +0000 |
| commit | c91740616ae58b162ec35789c702deb1d2cdeaa5 (patch) | |
| tree | 4ef7ed9eedda7ec762b7bedefb5b1551f61ca5e7 | |
| parent | 0fdd572763a3fd1503c31ac9ac89b8bf04065040 (diff) | |
| download | bcm5719-llvm-c91740616ae58b162ec35789c702deb1d2cdeaa5.tar.gz bcm5719-llvm-c91740616ae58b162ec35789c702deb1d2cdeaa5.zip | |
[ELF2] Don't create RelativeReloc for weak undef symbols
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). In general, we should not be
creating RelativeReloc relocs for undef weak symbols.
llvm-svn: 250558
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 5 | ||||
| -rw-r--r-- | lld/test/elf2/ppc64-weak-undef-call-shared.s | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index a8545c301ed..a6122ed2fd1 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -477,7 +477,10 @@ bool lld::elf2::canBePreempted(const SymbolBody *Body, bool NeedsGot) { // the plt entry would have a non zero address. // Since we cannot do anything better, we just resolve the symbol to 0 and // don't produce a dynamic relocation. - return NeedsGot; + // + // As an extra hack, assume that if we are producing a shared library the + // user knows what he or she is doing and can handle a dynamic relocation. + return Config->Shared || NeedsGot; } if (!Config->Shared) return false; diff --git a/lld/test/elf2/ppc64-weak-undef-call-shared.s b/lld/test/elf2/ppc64-weak-undef-call-shared.s new file mode 100644 index 00000000000..6cc168c2379 --- /dev/null +++ b/lld/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 + |

