[lld] r195594 - [Gnu] -L paths is not positional.

Shankar Easwaran shankare at codeaurora.org
Sun Nov 24 19:55:34 PST 2013


Author: shankare
Date: Sun Nov 24 21:55:34 2013
New Revision: 195594

URL: http://llvm.org/viewvc/llvm-project?rev=195594&view=rev
Log:
[Gnu] -L paths is not positional.

Looks like -L paths are not positional. They need to be added to a list of
search paths and those needs to be searched when lld looks for a library.

Modified:
    lld/trunk/include/lld/Driver/GnuLdInputGraph.h
    lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
    lld/trunk/lib/Driver/GnuLdDriver.cpp
    lld/trunk/lib/Driver/GnuLdInputGraph.cpp
    lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
    lld/trunk/test/Driver/lib-search.test
    lld/trunk/test/Driver/libsearch-inputGraph.test

Modified: lld/trunk/include/lld/Driver/GnuLdInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/GnuLdInputGraph.h?rev=195594&r1=195593&r2=195594&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/GnuLdInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/GnuLdInputGraph.h Sun Nov 24 21:55:34 2013
@@ -28,16 +28,12 @@ namespace lld {
 /// \brief Represents a ELF File
 class ELFFileNode : public FileNode {
 public:
-  ELFFileNode(ELFLinkingContext &ctx, StringRef path,
-              std::vector<StringRef> searchPath, int64_t ordinal = -1,
+  ELFFileNode(ELFLinkingContext &ctx, StringRef path, int64_t ordinal = -1,
               bool isWholeArchive = false, bool asNeeded = false,
               bool dashlPrefix = false)
       : FileNode(path, ordinal), _elfLinkingContext(ctx),
         _isWholeArchive(isWholeArchive), _asNeeded(asNeeded),
-        _isDashlPrefix(dashlPrefix) {
-    std::copy(searchPath.begin(), searchPath.end(),
-              std::back_inserter(_libraryPaths));
-  }
+        _isDashlPrefix(dashlPrefix) {}
 
   static inline bool classof(const InputElement *a) {
     return a->kind() == InputElement::Kind::File;
@@ -64,10 +60,6 @@ public:
                 << ((_isWholeArchive) ? "true" : "false") << "\n";
     diagnostics << "  - asNeeded : " << ((_asNeeded) ? "true" : "false")
                 << "\n";
-    diagnostics << "  contextPath : " << ((_libraryPaths.size()) ? "" : "None")
-                << "\n";
-    for (auto path : _libraryPaths)
-      diagnostics << "    - " << path << "\n";
     return true;
   }
 
@@ -103,7 +95,6 @@ private:
   bool _isWholeArchive;
   bool _asNeeded;
   bool _isDashlPrefix;
-  std::vector<StringRef> _libraryPaths;
   std::unique_ptr<FileArchive> _archiveFile;
 };
 

Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=195594&r1=195593&r2=195594&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Sun Nov 24 21:55:34 2013
@@ -155,9 +155,7 @@ public:
   virtual void setNoAllowDynamicLibraries() { _noAllowDynamicLibraries = true; }
 
   /// Searches directories for a match on the input File
-  ErrorOr<StringRef>
-  searchLibrary(StringRef libName,
-                const std::vector<StringRef> &searchPath) const;
+  ErrorOr<StringRef> searchLibrary(StringRef libName) const;
 
   /// Get the entry symbol name
   virtual StringRef entrySymbolName() const;
@@ -220,6 +218,12 @@ public:
     return x;
   }
 
+  // add search path to list.
+  virtual bool addSearchPath(StringRef ref) {
+    _inputSearchPaths.push_back(ref);
+    return true;
+  }
+
 private:
   ELFLinkingContext() LLVM_DELETED_FUNCTION;
 

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=195594&r1=195593&r2=195594&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Sun Nov 24 21:55:34 2013
@@ -69,7 +69,6 @@ public:
 
 // Get the Input file magic for creating appropriate InputGraph nodes.
 error_code getFileMagic(ELFLinkingContext &ctx, StringRef path,
-                        std::vector<StringRef> &searchPaths,
                         llvm::sys::fs::file_magic &magic) {
   error_code ec = llvm::sys::fs::identify_magic(path, magic);
   if (ec)
@@ -91,7 +90,7 @@ error_code getFileMagic(ELFLinkingContex
 llvm::ErrorOr<StringRef> ELFFileNode::getPath(const LinkingContext &) const {
   if (!_isDashlPrefix)
     return _path;
-  return _elfLinkingContext.searchLibrary(_path, _libraryPaths);
+  return _elfLinkingContext.searchLibrary(_path);
 }
 
 std::string ELFFileNode::errStr(error_code errc) {
@@ -155,7 +154,6 @@ bool GnuLdDriver::parse(int argc, const
   std::stack<InputElement *> controlNodeStack;
 
   // Positional options for an Input File
-  std::vector<StringRef> searchPath;
   bool isWholeArchive = false;
   bool asNeeded = false;
   bool _outputOptionSet = false;
@@ -168,6 +166,16 @@ bool GnuLdDriver::parse(int argc, const
 
   int index = 0;
 
+  // Set sys root path.
+  if (llvm::opt::Arg *sysRootPath = parsedArgs->getLastArg(OPT_sysroot))
+    ctx->setSysroot(sysRootPath->getValue());
+
+  // Add all search paths.
+  for (auto it = parsedArgs->filtered_begin(OPT_L),
+            ie = parsedArgs->filtered_end();
+       it != ie; ++it)
+    ctx->addSearchPath((*it)->getValue());
+
   // Process all the arguments and create Input Elements
   for (auto inputArg : *parsedArgs) {
     switch (inputArg->getOption().getID()) {
@@ -259,18 +267,18 @@ bool GnuLdDriver::parse(int argc, const
     case OPT_no_whole_archive:
       isWholeArchive = false;
       break;
+
     case OPT_whole_archive:
       isWholeArchive = true;
       break;
+
     case OPT_as_needed:
       asNeeded = true;
       break;
+
     case OPT_no_as_needed:
       asNeeded = false;
       break;
-    case OPT_L:
-      searchPath.push_back(inputArg->getValue());
-      break;
 
     case OPT_start_group: {
       std::unique_ptr<InputElement> controlStart(new ELFGroup(*ctx, index++));
@@ -295,8 +303,7 @@ bool GnuLdDriver::parse(int argc, const
       // If the path was referred to by using a -l argument, lets search
       // for the file in the search path.
       if (isDashlPrefix) {
-        ErrorOr<StringRef> resolvedPath =
-            ctx->searchLibrary(userPath, searchPath);
+        ErrorOr<StringRef> resolvedPath = ctx->searchLibrary(userPath);
         if (!resolvedPath) {
           diagnostics << " Unable to find library -l" << userPath << "\n";
           return false;
@@ -304,7 +311,7 @@ bool GnuLdDriver::parse(int argc, const
         resolvedInputPath = resolvedPath->str();
       }
       llvm::sys::fs::file_magic magic = llvm::sys::fs::file_magic::unknown;
-      error_code ec = getFileMagic(*ctx, resolvedInputPath, searchPath, magic);
+      error_code ec = getFileMagic(*ctx, resolvedInputPath, magic);
       if (ec) {
         diagnostics << "lld: unknown input file format for file " << userPath
                     << "\n";
@@ -316,8 +323,8 @@ bool GnuLdDriver::parse(int argc, const
 
       FileNode *inputNode = nullptr;
       if (isELFFileNode)
-        inputNode = new ELFFileNode(*ctx, userPath, searchPath, index++,
-                                    isWholeArchive, asNeeded, isDashlPrefix);
+        inputNode = new ELFFileNode(*ctx, userPath, index++, isWholeArchive,
+                                    asNeeded, isDashlPrefix);
       else {
         inputNode = new ELFGNULdScript(*ctx, resolvedInputPath, index++);
         ec = inputNode->parse(*ctx, diagnostics);
@@ -352,10 +359,6 @@ bool GnuLdDriver::parse(int argc, const
       break;
     }
 
-    case OPT_sysroot:
-      ctx->setSysroot(inputArg->getValue());
-      break;
-
     case OPT_soname:
       ctx->setSharedObjectName(inputArg->getValue());
       break;

Modified: lld/trunk/lib/Driver/GnuLdInputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdInputGraph.cpp?rev=195594&r1=195593&r2=195594&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdInputGraph.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdInputGraph.cpp Sun Nov 24 21:55:34 2013
@@ -87,7 +87,6 @@ error_code GNULdScript::parse(const Link
 error_code ELFGNULdScript::parse(const LinkingContext &ctx,
                                  raw_ostream &diagnostics) {
   int64_t index = 0;
-  std::vector<StringRef> searchPath;
   if (error_code ec = GNULdScript::parse(ctx, diagnostics))
     return ec;
   for (const auto &c : _linkerScript->_commands) {
@@ -95,10 +94,10 @@ error_code ELFGNULdScript::parse(const L
       std::unique_ptr<InputElement> controlStart(
           new ELFGroup(_elfLinkingContext, index++));
       for (auto &path : group->getPaths()) {
-        // TODO : Propagate SearchPath, Set WholeArchive/dashlPrefix
+        // TODO : Propagate Set WholeArchive/dashlPrefix
         auto inputNode = new ELFFileNode(
             _elfLinkingContext, _elfLinkingContext.allocateString(path._path),
-            searchPath, index++, false, path._asNeeded, false);
+            index++, false, path._asNeeded, false);
         std::unique_ptr<InputElement> inputFile(inputNode);
         dyn_cast<ControlNode>(controlStart.get())
             ->processInputElement(std::move(inputFile));

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=195594&r1=195593&r2=195594&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Sun Nov 24 21:55:34 2013
@@ -132,12 +132,11 @@ ELFLinkingContext::create(llvm::Triple t
   }
 }
 
-ErrorOr<StringRef> ELFLinkingContext::searchLibrary(
-    StringRef libName, const std::vector<StringRef> &searchPath) const {
+ErrorOr<StringRef> ELFLinkingContext::searchLibrary(StringRef libName) const {
   bool foundFile = false;
   StringRef pathref;
   SmallString<128> path;
-  for (StringRef dir : searchPath) {
+  for (StringRef dir : _inputSearchPaths) {
     // Search for dynamic library
     if (!_isStaticExecutable) {
       path.clear();

Modified: lld/trunk/test/Driver/lib-search.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/Driver/lib-search.test?rev=195594&r1=195593&r2=195594&view=diff
==============================================================================
--- lld/trunk/test/Driver/lib-search.test (original)
+++ lld/trunk/test/Driver/lib-search.test Sun Nov 24 21:55:34 2013
@@ -1,4 +1,4 @@
-RUN: not lld -flavor gnu -t -L%p/../elf/Inputs -lfnarchive  2> %t.err
+RUN: not lld -flavor gnu -t -lfnarchive -L%p/../elf/Inputs 2> %t.err
 RUN: FileCheck %s < %t.err
 
 # run linker with -t mode to dump full paths to input files

Modified: lld/trunk/test/Driver/libsearch-inputGraph.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/Driver/libsearch-inputGraph.test?rev=195594&r1=195593&r2=195594&view=diff
==============================================================================
--- lld/trunk/test/Driver/libsearch-inputGraph.test (original)
+++ lld/trunk/test/Driver/libsearch-inputGraph.test Sun Nov 24 21:55:34 2013
@@ -13,8 +13,6 @@ CHECK: Ordinal : 0
 CHECK: Attributes :
 CHECK:   - wholeArchive : false
 CHECK:   - asNeeded : false
-CHECK:   contextPath :
-CHECK:     - {{[^ ]+}}elf/Inputs
 
 WHOLEARCHIVE: Name    : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a
 WHOLEARCHIVE: Type    : ELF File
@@ -22,8 +20,6 @@ WHOLEARCHIVE: Ordinal : 0
 WHOLEARCHIVE: Attributes :
 WHOLEARCHIVE:   - wholeArchive : true
 WHOLEARCHIVE:   - asNeeded : false
-WHOLEARCHIVE:   contextPath :
-WHOLEARCHIVE:     - {{[^ ]+}}elf/Inputs
 
 ASNEEDED: Name    : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a
 ASNEEDED: Type    : ELF File
@@ -31,8 +27,6 @@ ASNEEDED: Ordinal : 0
 ASNEEDED: Attributes :
 ASNEEDED:   - wholeArchive : true
 ASNEEDED:   - asNeeded : true
-ASNEEDED:   contextPath :
-ASNEEDED:     - {{[^ ]+}}elf/Inputs
 
 SYSROOT: Name    : {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a
 SYSROOT: Type    : ELF File
@@ -40,5 +34,3 @@ SYSROOT: Ordinal : 0
 SYSROOT: Attributes :
 SYSROOT:   - wholeArchive : false
 SYSROOT:   - asNeeded : false
-SYSROOT:   contextPath :
-SYSROOT:     - =/Inputs





More information about the llvm-commits mailing list