diff options
author | Rui Ueyama <ruiu@google.com> | 2013-11-15 03:12:24 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2013-11-15 03:12:24 +0000 |
commit | b4dca7f0657da7926670a05479a52b9e347e9f81 (patch) | |
tree | d7780af0ea5d40761022d2f0a118f14c90594568 /lld/lib/Core/SymbolTable.cpp | |
parent | 014192dbdabb3f898a4e47894fa04269c056480f (diff) | |
download | bcm5719-llvm-b4dca7f0657da7926670a05479a52b9e347e9f81.tar.gz bcm5719-llvm-b4dca7f0657da7926670a05479a52b9e347e9f81.zip |
Select new undefined atom rather than old one if other conditions are the same.
We can add multiple undefined atoms having the same name to the symbol table.
If such atoms are added, the symbol table compares their canBeNull attributes,
and select one having a stronger constraint. If their canBeNulls are the same,
the choice is arbitrary. Currently it choose the existing one.
This patch changes the preference, so that the symbol table choose the new one
if the new atom has a greater canBeNull or a fallback atom. This shouldn't
change the behavior except the case described below.
A new undefined atom may have a new fallback atom attribute. By choosing the new
atom, we can update the fallback atom during Core Linking. PE/COFF actually need
that. For example, _lseek is an alias for __lseek on Windows. One of an object
file in OLDNAMES.LIB has an undefined atom for _lseek with the fallback to
__lseek. When the linker tries to resolve _read, it supposed to read the file
from OLDNAMES.LIB and use the new fallback from the file. Currently LLD cannot
handle such case because duplicate undefined atoms with the same attributes are
ignored.
Differential Revision: http://llvm-reviews.chandlerc.com/D2161
llvm-svn: 194777
Diffstat (limited to 'lld/lib/Core/SymbolTable.cpp')
-rw-r--r-- | lld/lib/Core/SymbolTable.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp index e7c12b8489b..c0405ddc973 100644 --- a/lld/lib/Core/SymbolTable.cpp +++ b/lld/lib/Core/SymbolTable.cpp @@ -172,28 +172,42 @@ void SymbolTable::addByName(const Atom & newAtom) { } break; case NCR_DupUndef: { - const UndefinedAtom* existingUndef = - dyn_cast<UndefinedAtom>(existing); - const UndefinedAtom* newUndef = - dyn_cast<UndefinedAtom>(&newAtom); - assert(existingUndef != nullptr); - assert(newUndef != nullptr); - if (existingUndef->canBeNull() == newUndef->canBeNull()) { - useNew = false; - } else { - if (_context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) { - // FIXME: need diagonstics interface for writing warning messages - llvm::errs() << "lld warning: undefined symbol " - << existingUndef->name() - << " has different weakness in " - << existingUndef->file().path() - << " and in " - << newUndef->file().path(); - } - useNew = (newUndef->canBeNull() < existingUndef->canBeNull()); - } + const UndefinedAtom* existingUndef = dyn_cast<UndefinedAtom>(existing); + const UndefinedAtom* newUndef = dyn_cast<UndefinedAtom>(&newAtom); + assert(existingUndef != nullptr); + assert(newUndef != nullptr); + + bool sameCanBeNull = (existingUndef->canBeNull() == newUndef->canBeNull()); + if (!sameCanBeNull && + _context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) { + llvm::errs() << "lld warning: undefined symbol " + << existingUndef->name() + << " has different weakness in " + << existingUndef->file().path() + << " and in " << newUndef->file().path() << "\n"; + } + + const UndefinedAtom *existingFallback = existingUndef->fallback(); + const UndefinedAtom *newFallback = newUndef->fallback(); + bool hasDifferentFallback = + (existingFallback && newFallback && + existingFallback->name() != newFallback->name()); + if (hasDifferentFallback) { + llvm::errs() << "lld warning: undefined symbol " + << existingUndef->name() << " has different fallback: " + << existingFallback->name() << " in " + << existingUndef->file().path() << " and " + << newFallback->name() << " in " + << newUndef->file().path() << "\n"; } + + bool hasNewFallback = newUndef->fallback(); + if (sameCanBeNull) + useNew = hasNewFallback; + else + useNew = (newUndef->canBeNull() < existingUndef->canBeNull()); break; + } case NCR_DupShLib: { const SharedLibraryAtom* curShLib = dyn_cast<SharedLibraryAtom>(existing); |