[PATCH] D100624: [ELF] Don't set versionId on undefined weak lazy symbols
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 16 00:34:04 PDT 2021
MaskRay created this revision.
MaskRay added reviewers: grimar, peter.smith.
Herald added subscribers: arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
An unfetched lazy symbol (undefined weak) should be considered to have its
original versionId which is VER_NDX_GLOBAL, instead of the lazy symbol's
versionId. (The original versionId cannot be non-VER_NDX_GLOBAL because a
undefined versioned symbol is an error.)
The regression was introduced in D77280 <https://reviews.llvm.org/D77280> when making version scripts work
with lazy symbols fetched by LTO calls.
Fix PR49915
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100624
Files:
lld/ELF/SyntheticSections.cpp
lld/test/ELF/version-script-weak.s
Index: lld/test/ELF/version-script-weak.s
===================================================================
--- lld/test/ELF/version-script-weak.s
+++ lld/test/ELF/version-script-weak.s
@@ -24,6 +24,19 @@
# CHECK-NEXT: Section: Undefined
# CHECK-NEXT: }
+## The version of an unfetched lazy symbol is VER_NDX_GLOBAL. It is not affected by version scripts.
+# RUN: echo "v1 { *; };" > %t2.script
+# RUN: ld.lld -shared --version-script %t2.script %t.o --start-lib %t1.o --end-lib -o %t2.so
+# RUN: llvm-readelf -V %t2.so | FileCheck %s --check-prefix=CHECK2
+
+# CHECK2: 000: 0 (*local*) 1 (*global*)
+
+# RUN: ld.lld -shared --soname=tshared --version-script %t2.script %t1.o -o %tshared.so
+# RUN: ld.lld -shared --version-script %t2.script %t.o --start-lib %t1.o --end-lib %tshared.so -o %t3.so
+# RUN: llvm-readelf -V %t3.so | FileCheck %s --check-prefix=CHECK3
+
+# CHECK3: 000: 0 (*local*) 3 (v1)
+
.text
callq foo at PLT
.weak foo
Index: lld/ELF/SyntheticSections.cpp
===================================================================
--- lld/ELF/SyntheticSections.cpp
+++ lld/ELF/SyntheticSections.cpp
@@ -3123,7 +3123,7 @@
void VersionTableSection::writeTo(uint8_t *buf) {
buf += 2;
for (const SymbolTableEntry &s : getPartition().dynSymTab->getSymbols()) {
- write16(buf, s.sym->versionId);
+ write16(buf, s.sym->isLazy() ? VER_NDX_GLOBAL : s.sym->versionId);
buf += 2;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100624.338009.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210416/22f2c5dd/attachment.bin>
More information about the llvm-commits
mailing list