Fix ELFFileNode::resetNextIndex().

ELFLinkingContext has a method addUndefinedAtomsFromSharedLibrary().
The method is being used to skip a shared library within --start-group
and --end-group if it's not the first iteration of the group.

We have the same, incomplete mechanism to skip a shared library within
a group too. That's implemented in ELFFileNode. It's intended to not
return a shared library on the second or further iterations in the
first place. This mechanism is preferred over
addUndefinedAtomsFromSharedLibrary because the policy is implemented
in Input Graph -- that's what Input Graph is for.

This patch removes the dupluicate feature and fixes ELFFileNode.

Differential Revision: http://llvm-reviews.chandlerc.com/D3280

llvm-svn: 205566
This commit is contained in:
Rui Ueyama 2014-04-03 20:54:47 +00:00
parent cb74fa696b
commit 9457510abf
4 changed files with 19 additions and 43 deletions

View File

@ -158,11 +158,6 @@ public:
/// to be an error.
bool allowShlibUndefines() const { return _allowShlibUndefines; }
/// Add undefined symbols from shared libraries ?
virtual bool addUndefinedAtomsFromSharedLibrary(const SharedLibraryFile *) {
return true;
}
/// If true, core linking will write the path to each input file to stdout
/// (i.e. llvm::outs()) as it is used. This is used to implement the -t
/// linker option.

View File

@ -74,13 +74,11 @@ public:
/// \brief This is used by Group Nodes, when there is a need to reset the
/// the file to be processed next. When handling a group node that contains
/// Input elements, if the group node has to be reprocessed, the linker needs
/// to start processing files as part of the inputelement from beginning.
/// reset the next file index to 0 only if the node is an archive library or
/// a shared library
/// to start processing files as part of the input element from beginning.
/// Reset the next file index to 0 only if the node is an archive library.
void resetNextIndex() override {
if ((!_attributes._isWholeArchive &&
(_files[0]->kind() == File::kindArchiveLibrary)) ||
(_files[0]->kind() == File::kindSharedLibrary)) {
if (_files[0]->kind() == File::kindArchiveLibrary &&
!_attributes._isWholeArchive) {
_nextFileIndex = 0;
}
}

View File

@ -224,13 +224,6 @@ public:
return _rpathLinkList;
}
bool addUndefinedAtomsFromSharedLibrary(const SharedLibraryFile *s) override {
if (_undefinedAtomsFromFile.find(s) != _undefinedAtomsFromFile.end())
return false;
_undefinedAtomsFromFile[s] = true;
return true;
}
const std::map<std::string, uint64_t> &getAbsoluteSymbols() const {
return _absoluteSymbols;
}
@ -281,7 +274,6 @@ protected:
StringRef _soname;
StringRefVector _rpathList;
StringRefVector _rpathLinkList;
std::map<const SharedLibraryFile *, bool> _undefinedAtomsFromFile;
std::map<std::string, uint64_t> _absoluteSymbols;
};
} // end namespace lld

View File

@ -69,40 +69,31 @@ private:
} // namespace
void Resolver::handleFile(const File &file) {
const SharedLibraryFile *sharedLibraryFile =
dyn_cast<SharedLibraryFile>(&file);
for (const DefinedAtom *atom : file.defined())
doDefinedAtom(*atom);
bool progress = false;
if (!sharedLibraryFile ||
_context.addUndefinedAtomsFromSharedLibrary(sharedLibraryFile)) {
progress = !file.undefined().empty();
for (const UndefinedAtom *undefAtom : file.undefined()) {
doUndefinedAtom(*undefAtom);
// 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 (!_symbolTable.isDefined(undefAtom->name())) {
if (const UndefinedAtom *fallbackAtom = undefAtom->fallback()) {
doUndefinedAtom(*fallbackAtom);
_symbolTable.addReplacement(undefAtom, fallbackAtom);
}
for (const UndefinedAtom *undefAtom : file.undefined()) {
doUndefinedAtom(*undefAtom);
// 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 (!_symbolTable.isDefined(undefAtom->name())) {
if (const UndefinedAtom *fallbackAtom = undefAtom->fallback()) {
doUndefinedAtom(*fallbackAtom);
_symbolTable.addReplacement(undefAtom, fallbackAtom);
}
}
}
for (const SharedLibraryAtom *shlibAtom : file.sharedLibrary())
doSharedLibraryAtom(*shlibAtom);
for (const AbsoluteAtom *absAtom : file.absolute())
doAbsoluteAtom(*absAtom);
for (const SharedLibraryAtom *atom : file.sharedLibrary())
doSharedLibraryAtom(*atom);
for (const AbsoluteAtom *atom : file.absolute())
doAbsoluteAtom(*atom);
// If we make some progress on linking, notify that fact to the input file
// manager, because it may want to know that for --start-group/end-group.
progress = progress || !file.sharedLibrary().empty() ||
!file.absolute().empty() || !file.defined().empty();
bool progress = !file.defined().empty() || !file.sharedLibrary().empty() ||
!file.absolute().empty() || !file.undefined().empty();
if (progress) {
_context.inputGraph().notifyProgress();
}