[lld] r180209 - [Core] Allow weak symbols in shared library when linking.

Michael J. Spencer bigcheesegs at gmail.com
Wed Apr 24 12:00:27 PDT 2013


Author: mspencer
Date: Wed Apr 24 14:00:26 2013
New Revision: 180209

URL: http://llvm.org/viewvc/llvm-project?rev=180209&view=rev
Log:
[Core] Allow weak symbols in shared library when linking.

Patch by Rui Ueyama.

Modified:
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/test/elf/Inputs/shared.c
    lld/trunk/test/elf/dynamic-undef.test

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=180209&r1=180208&r2=180209&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Wed Apr 24 14:00:26 2013
@@ -315,17 +315,19 @@ bool Resolver::checkUndefines(bool final
     bool foundUndefines = false;
     for (const UndefinedAtom *undefAtom : undefinedAtoms) {
       const File &f = undefAtom->file();
-      bool isAtomUndefined = false;
-      if (isa<SharedLibraryFile>(f)) {
-        if (!_targetInfo.allowShlibUndefines()) {
-          foundUndefines = true;
-          isAtomUndefined = true;
-        }
-      } else if (undefAtom->canBeNull() == UndefinedAtom::canBeNullNever) {
-        foundUndefines = true;
-        isAtomUndefined = true;
-      }
-      if (isAtomUndefined && _targetInfo.printRemainingUndefines()) {
+
+      // Skip over a weak symbol.
+      if (undefAtom->canBeNull() != UndefinedAtom::canBeNullNever)
+        continue;
+
+      // If this is a library and undefined symbols are allowed on the
+      // target platform, skip over it.
+      if (isa<SharedLibraryFile>(f) && _targetInfo.allowShlibUndefines())
+        continue;
+
+      // Seems like this symbol is undefined. Warn that.
+      foundUndefines = true;
+      if (_targetInfo.printRemainingUndefines()) {
         llvm::errs() << "Undefined Symbol: " << undefAtom->file().path()
                      << " : " << undefAtom->name() << "\n";
       }

Modified: lld/trunk/test/elf/Inputs/shared.c
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/shared.c?rev=180209&r1=180208&r2=180209&view=diff
==============================================================================
--- lld/trunk/test/elf/Inputs/shared.c (original)
+++ lld/trunk/test/elf/Inputs/shared.c Wed Apr 24 14:00:26 2013
@@ -3,6 +3,14 @@
 extern int i;
 int i = 42;
 
+// Undefined weak function in a dynamic library.
+__attribute__((weak)) void weakfoo();
+
+// Regular funtion in a dynamic library.
 void foo() {
+  // Try to call weakfoo so that the reference to weekfoo will be included in
+  // the resulting .so file.
+  if (weakfoo)
+    weakfoo();
   puts("Fooo!!");
 }

Modified: lld/trunk/test/elf/dynamic-undef.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/dynamic-undef.test?rev=180209&r1=180208&r2=180209&view=diff
==============================================================================
--- lld/trunk/test/elf/dynamic-undef.test (original)
+++ lld/trunk/test/elf/dynamic-undef.test Wed Apr 24 14:00:26 2013
@@ -25,3 +25,5 @@ RUN: FileCheck -check-prefix=SHLIB %s <
 
 EXEC: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : puts
 SHLIB: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : puts
+EXEC-NOT: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : weakfoo
+SHLIB-NOT: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : weakfoo





More information about the llvm-commits mailing list