[PATCH] D76999: [ELF] Suggest VERSYM_HIDDEN shared definitions
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 28 16:40:15 PDT 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, psmith, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Uncovered by https://bugs.llvm.org/show_bug.cgi?id=45318 We currently have a
confusing diagnostic when a reference does not use versioning while a shared
object has a VERSYM_HIDDEN definition (this mechanism was designed to disallow
linking incompatible objects):
// See undef-suggest-version.s
ld.lld: error: undefined symbol: foo
>>> referenced by t1.o:(.text+0x1)
>>> did you mean: foo
>>> defined in: t.so
The symbol was inserted into `symtab` as `foo at v1`, but truncated to
`foo` by Symbol::parseSymbolVersion().
This patch detects the truncation and changes the suggestion to `did you mean: foo at v1`
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76999
Files:
lld/ELF/Relocations.cpp
lld/test/ELF/undef-suggest-version.s
Index: lld/test/ELF/undef-suggest-version.s
===================================================================
--- /dev/null
+++ lld/test/ELF/undef-suggest-version.s
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: echo 'v1 {};' > %t.ver
+# RUN: ld.lld -shared --version-script %t.ver %t.o -o %t.so
+
+# RUN: echo 'call foo; call _Z3fooi' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
+# RUN: not ld.lld %t.so %t1.o -o /dev/null 2>&1 | FileCheck %s
+
+# CHECK: error: undefined symbol: foo
+# CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x1)
+# CHECK-NEXT: >>> did you mean: foo at v1
+# CHECK-NEXT: >>> defined in: {{.*}}.so
+# CHECK-EMPTY:
+# CHECK-NEXT: error: undefined symbol: foo(int)
+# CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x6)
+# CHECK-NEXT: >>> did you mean: foo(int)@v1
+# CHECK-NEXT: >>> defined in: {{.*}}.so
+
+.globl foo.v1, _Z3fooi.v1
+.symver foo.v1,foo at v1
+.symver _Z3fooi.v1,_Z3fooi at v1
+foo.v1:
+_Z3fooi.v1:
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -894,7 +894,14 @@
std::string pre_hint = ": ", post_hint;
if (const Symbol *corrected = getAlternativeSpelling<ELFT>(
cast<Undefined>(sym), pre_hint, post_hint)) {
- msg += "\n>>> did you mean" + pre_hint + toString(*corrected) + post_hint;
+ msg += "\n>>> did you mean" + pre_hint + toString(*corrected);
+ StringRef name = corrected->getName();
+ // The symbol name may be truncated by Symbol::parseSymbolVersion(). In
+ // that case, it ends with. This check is safe because every symbol name
+ // in symtab ends with '\0'.
+ if (name.data()[name.size()] == '@')
+ msg += name.data() + name.size();
+ msg += post_hint;
if (corrected->file)
msg += "\n>>> defined in: " + toString(corrected->file);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76999.253384.patch
Type: text/x-patch
Size: 1945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200328/73ab4e9b/attachment-0001.bin>
More information about the llvm-commits
mailing list