[lld] r244640 - Add support for weak undefined symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 10:57:05 PDT 2015


Author: rafael
Date: Tue Aug 11 12:57:05 2015
New Revision: 244640

URL: http://llvm.org/viewvc/llvm-project?rev=244640&view=rev
Log:
Add support for weak undefined symbols.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/test/elf2/resolution.s

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=244640&r1=244639&r2=244640&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Aug 11 12:57:05 2015
@@ -83,7 +83,8 @@ SymbolBody *elf2::ObjectFile<ELFT>::crea
       return new (Alloc) Undefined(Name);
     return new (Alloc) DefinedRegular(Name);
   case STB_WEAK:
-    // FIXME: add support for weak undefined
+    if (Sym->isUndefined())
+      return new (Alloc) UndefinedWeak(Name);
     return new (Alloc) DefinedWeak(Name);
   }
 }

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=244640&r1=244639&r2=244640&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Aug 11 12:57:05 2015
@@ -42,6 +42,7 @@ int SymbolBody::compare(SymbolBody *Othe
     return 0;
   case DefinedWeakKind:
   case UndefinedKind:
+  case UndefinedWeakKind:
     return 1;
   }
   llvm_unreachable("unknown symbol kind");

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=244640&r1=244639&r2=244640&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Aug 11 12:57:05 2015
@@ -39,7 +39,8 @@ public:
     DefinedRegularKind = 0,
     DefinedWeakKind = 1,
     DefinedLast = 1,
-    UndefinedKind = 2
+    UndefinedWeakKind = 2,
+    UndefinedKind = 3
   };
 
   Kind kind() const { return static_cast<Kind>(SymbolKind); }
@@ -112,6 +113,15 @@ public:
   }
 };
 
+class UndefinedWeak : public SymbolBody {
+public:
+  explicit UndefinedWeak(StringRef N) : SymbolBody(UndefinedWeakKind, N) {}
+
+  static bool classof(const SymbolBody *S) {
+    return S->kind() == UndefinedWeakKind;
+  }
+};
+
 } // namespace elf2
 } // namespace lld
 

Modified: lld/trunk/test/elf2/resolution.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/resolution.s?rev=244640&r1=244639&r2=244640&view=diff
==============================================================================
--- lld/trunk/test/elf2/resolution.s (original)
+++ lld/trunk/test/elf2/resolution.s Tue Aug 11 12:57:05 2015
@@ -13,3 +13,6 @@ local:
 foo:
 
 .long bar
+
+.weak zed
+.long zed




More information about the llvm-commits mailing list