[PATCH] D72681: [ELF] --exclude-libs: don't assign VER_NDX_LOCAL to undefined symbols

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 22:12:02 PST 2020


MaskRay created this revision.
MaskRay added reviewers: pcc, smeenai.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Suggested by Peter Collingbourne.

Non-VER_NDX_GLOBAL versions should not be assigned to defined symbols. --exclude-libs violates this and can cause a spurious error "cannot refer to absolute symbol" after D71795 <https://reviews.llvm.org/D71795>.

excludeLibs incorrectly assigns VER_NDX_LOCAL to an undefined weak symbol =>
isPreemptible is false =>
R_PLT_PC is optimized to R_PC =>
in isStaticLinkTimeConstant, an error is emitted.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72681

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/exclude-libs-undef.s


Index: lld/test/ELF/exclude-libs-undef.s
===================================================================
--- /dev/null
+++ lld/test/ELF/exclude-libs-undef.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: mkdir -p %t.dir
+# RUN: rm -f %t.dir/t.a
+# RUN: llvm-ar rc %t.dir/t.a %t.o
+# RUN: ld.lld -shared --whole-archive --exclude-libs=t.a %t.dir/t.a -o %t.so
+# RUN: llvm-readelf --dyn-syms %t.so | FileCheck %s
+
+# CHECK:     1: {{.*}} WEAK DEFAULT UND bar
+# CHECK-NOT: 2:
+
+.globl foo
+.weak bar
+foo:
+  call bar
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1374,7 +1374,7 @@
     if (!file->archiveName.empty())
       if (all || libs.count(path::filename(file->archiveName)))
         for (Symbol *sym : file->getSymbols())
-          if (!sym->isLocal() && sym->file == file)
+          if (!sym->isUndefined() && !sym->isLocal() && sym->file == file)
             sym->versionId = VER_NDX_LOCAL;
   };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72681.237850.patch
Type: text/x-patch
Size: 1067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200114/1520fe50/attachment.bin>


More information about the llvm-commits mailing list