[lld] 40c5bd4 - [ELF] --exclude-libs: don't assign VER_NDX_LOCAL to undefined symbols

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 10:13:51 PST 2020


Author: Fangrui Song
Date: 2020-01-14T10:12:28-08:00
New Revision: 40c5bd4212a51216a489fdaaf59060921d677009

URL: https://github.com/llvm/llvm-project/commit/40c5bd4212a51216a489fdaaf59060921d677009
DIFF: https://github.com/llvm/llvm-project/commit/40c5bd4212a51216a489fdaaf59060921d677009.diff

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

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.

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.

Reviewed By: pcc, grimar

Differential Revision: https://reviews.llvm.org/D72681

Added: 
    lld/test/ELF/exclude-libs-undef.s

Modified: 
    lld/ELF/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index eadf06e8ef0a..23da749d3078 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1375,7 +1375,7 @@ static void excludeLibs(opt::InputArgList &args) {
     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;
   };
 

diff  --git a/lld/test/ELF/exclude-libs-undef.s b/lld/test/ELF/exclude-libs-undef.s
new file mode 100644
index 000000000000..712591e4f684
--- /dev/null
+++ b/lld/test/ELF/exclude-libs-undef.s
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+## Test we don't assign VER_NDX_LOCAL to an undefined symbol.
+## If we do, an undefined weak will become non-preemptible,
+## and we will report an error when an R_PLT_PC (optimized to R_PC)
+## references the undefined weak (considered absolute).
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: rm -f %t.a
+# RUN: llvm-ar rc %t.a %t.o
+# RUN: ld.lld -shared --whole-archive --exclude-libs=ALL %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


        


More information about the llvm-commits mailing list