[PECOFF] Handle weak external symbols.
Used the fallback mechanism to implement COFF weak external symbols.
llvm-svn: 190633
diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp
index 716f0d4..2a763c5 100644
--- a/lld/lib/Core/Resolver.cpp
+++ b/lld/lib/Core/Resolver.cpp
@@ -211,9 +211,11 @@
// If the undefined symbol has an alternative name, try to resolve the
// symbol with the name to give it a second chance. This feature is used
// for COFF "weak external" symbol.
- if (const UndefinedAtom *fallbackUndefAtom = undefAtom->fallback()) {
- _symbolTable.addReplacement(undefAtom, fallbackUndefAtom);
- _symbolTable.add(*fallbackUndefAtom);
+ if (!_symbolTable.isDefined(undefName)) {
+ if (const UndefinedAtom *fallbackUndefAtom = undefAtom->fallback()) {
+ _symbolTable.addReplacement(undefAtom, fallbackUndefAtom);
+ _symbolTable.add(*fallbackUndefAtom);
+ }
}
}
// search libraries for overrides of common symbols
@@ -351,6 +353,10 @@
if (isa<SharedLibraryFile>(f) && _context.allowShlibUndefines())
continue;
+ // If the undefine is coalesced away, skip over it.
+ if (_symbolTable.replacement(undefAtom) != undefAtom)
+ continue;
+
// Seems like this symbol is undefined. Warn that.
foundUndefines = true;
if (_context.printRemainingUndefines()) {