[lld] r205566 - Fix ELFFileNode::resetNextIndex().

Rui Ueyama ruiu at google.com
Thu Apr 3 13:54:47 PDT 2014


Author: ruiu
Date: Thu Apr  3 15:54:47 2014
New Revision: 205566

URL: http://llvm.org/viewvc/llvm-project?rev=205566&view=rev
Log:
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

Modified:
    lld/trunk/include/lld/Core/LinkingContext.h
    lld/trunk/include/lld/Driver/GnuLdInputGraph.h
    lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
    lld/trunk/lib/Core/Resolver.cpp

Modified: lld/trunk/include/lld/Core/LinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkingContext.h?rev=205566&r1=205565&r2=205566&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkingContext.h (original)
+++ lld/trunk/include/lld/Core/LinkingContext.h Thu Apr  3 15:54:47 2014
@@ -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.

Modified: lld/trunk/include/lld/Driver/GnuLdInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/GnuLdInputGraph.h?rev=205566&r1=205565&r2=205566&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/GnuLdInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/GnuLdInputGraph.h Thu Apr  3 15:54:47 2014
@@ -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;
     }
   }

Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=205566&r1=205565&r2=205566&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Thu Apr  3 15:54:47 2014
@@ -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

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=205566&r1=205565&r2=205566&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Apr  3 15:54:47 2014
@@ -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();
   }





More information about the llvm-commits mailing list