[lld] r249966 - ELF: Move utility functions from Driver to DriverUtils.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 10 20:28:39 PDT 2015


Author: ruiu
Date: Sat Oct 10 22:28:39 2015
New Revision: 249966

URL: http://llvm.org/viewvc/llvm-project?rev=249966&view=rev
Log:
ELF: Move utility functions from Driver to DriverUtils.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Driver.h
    lld/trunk/ELF/DriverUtils.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=249966&r1=249965&r2=249966&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Oct 10 22:28:39 2015
@@ -16,8 +16,6 @@
 #include "Writer.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include <utility>
 
@@ -69,39 +67,6 @@ static TargetInfo *createTarget() {
   error("Unknown target machine");
 }
 
-// Makes a path by concatenating Dir and File.
-// If Dir starts with '=' the result will be preceded by Sysroot,
-// which can be set with --sysroot command line switch.
-static std::string buildSysrootedPath(StringRef Dir, StringRef File) {
-  SmallString<128> Path;
-  if (Dir.startswith("="))
-    sys::path::append(Path, Config->Sysroot, Dir.substr(1), File);
-  else
-    sys::path::append(Path, Dir, File);
-  return Path.str().str();
-}
-
-// Searches a given library from input search paths, which are filled
-// from -L command line switches. Returns a path to an existent library file.
-static std::string searchLibrary(StringRef Path) {
-  std::vector<std::string> Names;
-  if (Path[0] == ':') {
-    Names.push_back(Path.drop_front().str());
-  } else {
-    if (!Config->Static)
-      Names.push_back((Twine("lib") + Path + ".so").str());
-    Names.push_back((Twine("lib") + Path + ".a").str());
-  }
-  for (StringRef Dir : Config->InputSearchPaths) {
-    for (const std::string &Name : Names) {
-      std::string FullPath = buildSysrootedPath(Dir, Name);
-      if (sys::fs::exists(FullPath))
-        return FullPath;
-    }
-  }
-  error(Twine("Unable to find library -l") + Path);
-}
-
 // Opens and parses a file. Path has to be resolved already.
 // Newly created memory buffers are owned by this driver.
 void LinkerDriver::addFile(StringRef Path) {

Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=249966&r1=249965&r2=249966&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Sat Oct 10 22:28:39 2015
@@ -65,6 +65,9 @@ enum {
 // Parses a linker script. Calling this function updates the Symtab and Config.
 void readLinkerScript(llvm::BumpPtrAllocator *A, MemoryBufferRef MB);
 
+std::string searchLibrary(StringRef Path);
+std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
+
 } // namespace elf2
 } // namespace lld
 

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=249966&r1=249965&r2=249966&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Sat Oct 10 22:28:39 2015
@@ -17,6 +17,8 @@
 #include "Error.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 using namespace llvm;
 
@@ -75,3 +77,36 @@ opt::InputArgList ArgParser::parse(Array
 
   return Args;
 }
+
+// Searches a given library from input search paths, which are filled
+// from -L command line switches. Returns a path to an existent library file.
+std::string lld::elf2::searchLibrary(StringRef Path) {
+  std::vector<std::string> Names;
+  if (Path[0] == ':') {
+    Names.push_back(Path.drop_front());
+  } else {
+    if (!Config->Static)
+      Names.push_back(("lib" + Path + ".so").str());
+    Names.push_back(("lib" + Path + ".a").str());
+  }
+  for (StringRef Dir : Config->InputSearchPaths) {
+    for (const std::string &Name : Names) {
+      std::string FullPath = buildSysrootedPath(Dir, Name);
+      if (sys::fs::exists(FullPath))
+        return FullPath;
+    }
+  }
+  error("Unable to find library -l" + Path);
+}
+
+// Makes a path by concatenating Dir and File.
+// If Dir starts with '=' the result will be preceded by Sysroot,
+// which can be set with --sysroot command line switch.
+std::string lld::elf2::buildSysrootedPath(StringRef Dir, StringRef File) {
+  SmallString<128> Path;
+  if (Dir.startswith("="))
+    sys::path::append(Path, Config->Sysroot, Dir.substr(1), File);
+  else
+    sys::path::append(Path, Dir, File);
+  return Path.str();
+}




More information about the llvm-commits mailing list