diff options
author | Fangrui Song <maskray@google.com> | 2020-01-09 15:53:52 -0800 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2020-01-09 16:24:02 -0800 |
commit | 375371cc8bff7ba02d0a2203f80de5e640fcadf1 (patch) | |
tree | 815fabfb0868197ed1544750a583f14c8eb74288 | |
parent | 02113918ed6b5e514afd7d1e007131d36ac13f1d (diff) | |
download | bcm5719-llvm-375371cc8bff7ba02d0a2203f80de5e640fcadf1.tar.gz bcm5719-llvm-375371cc8bff7ba02d0a2203f80de5e640fcadf1.zip |
[ELF] Fix includeInDynsym() when an undefined weak is merged with a lazy definition
An undefined weak does not fetch the lazy definition. A lazy weak symbol
should be considered undefined, and thus preemptible if .dynsym exists.
D71795 is not quite an NFC. It errors on an R_X86_64_PLT32 referencing
an undefined weak symbol. isPreemptible is false (incorrect) => R_PLT_PC
is optimized to R_PC => in isStaticLinkTimeConstant, an error is emitted
when an R_PC is applied on an undefined weak (considered absolute).
-rw-r--r-- | lld/ELF/Symbols.cpp | 4 | ||||
-rw-r--r-- | lld/test/ELF/weak-undef-lib.s | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index a9e3645043f..f0f6121009a 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -277,8 +277,10 @@ bool Symbol::includeInDynsym() const { return false; if (computeBinding() == STB_LOCAL) return false; + if (!isDefined() && !isCommon()) + return true; - return isUndefined() || isShared() || exportDynamic || inDynamicList; + return exportDynamic || inDynamicList; } // Print out a log message for --trace-symbol. diff --git a/lld/test/ELF/weak-undef-lib.s b/lld/test/ELF/weak-undef-lib.s index 0b4183e80e5..54e05dc7e98 100644 --- a/lld/test/ELF/weak-undef-lib.s +++ b/lld/test/ELF/weak-undef-lib.s @@ -6,6 +6,9 @@ # RUN: ld.lld -shared -o %t.so %t1.o --start-lib %t2.o # RUN: llvm-readobj --dyn-syms %t.so | FileCheck %s +# RUN: ld.lld -pie -o %t %t1.o --start-lib %t2.o +# RUN: llvm-readobj --dyn-syms %t | FileCheck %s + # CHECK: Name: foo # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: Size: 0 @@ -15,5 +18,7 @@ # CHECK-NEXT: Section: Undefined .weak foo +call foo@PLT + .data .quad foo |