[PECOFF][Driver] Add -libpath command line option.
authorRui Ueyama <ruiu@google.com>
Fri, 19 Jul 2013 01:38:49 +0000 (01:38 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 19 Jul 2013 01:38:49 +0000 (01:38 +0000)
The logic to search a library from the library paths will be implemented
in a different patch.

llvm-svn: 186644

lld/include/lld/ReaderWriter/PECOFFTargetInfo.h
lld/lib/Driver/WinLinkDriver.cpp
lld/lib/Driver/WinLinkOptions.td
lld/unittests/DriverTests/WinLinkDriverTest.cpp

index 744e758..9d2f57b 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef LLD_READER_WRITER_PECOFF_TARGET_INFO_H
 #define LLD_READER_WRITER_PECOFF_TARGET_INFO_H
 
+#include <vector>
+
 #include "lld/Core/TargetInfo.h"
 #include "lld/ReaderWriter/Reader.h"
 #include "lld/ReaderWriter/Writer.h"
@@ -43,6 +45,14 @@ public:
 
   virtual void addPasses(PassManager &pm) const;
 
+  void appendInputSearchPath(StringRef dirPath) {
+    _inputSearchPaths.push_back(dirPath);
+  }
+
+  const std::vector<StringRef> getInputSearchPaths() {
+    return _inputSearchPaths;
+  }
+
   void setStackReserve(uint64_t size) { _stackReserve = size; }
   void setStackCommit(uint64_t size) { _stackCommit = size; }
   uint64_t getStackReserve() const { return _stackReserve; }
@@ -85,6 +95,7 @@ private:
   bool _nxCompat;
   bool _largeAddressAware;
 
+  std::vector<StringRef> _inputSearchPaths;
   mutable std::unique_ptr<Reader> _reader;
   mutable std::unique_ptr<Writer> _writer;
   llvm::BumpPtrAllocator _extraStrings;
index 0eff1b2..d1e51f9 100644 (file)
@@ -254,6 +254,13 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_entry))
     info.setEntrySymbolName(arg->getValue());
 
+  // Hanlde -libpath
+  for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_libpath),
+                               ie = parsedArgs->filtered_end();
+       it != ie; ++it) {
+    info.appendInputSearchPath((*it)->getValue());
+  }
+
   // Handle -force
   if (parsedArgs->getLastArg(OPT_force))
     info.setAllowRemainingUndefines(true);
index 8669ca8..16ebcd3 100644 (file)
@@ -25,6 +25,10 @@ def entry : Separate<["-", "/"], "entry">,
     HelpText<"Name of entry point symbol">;
 def entry_c: Joined<["-", "/"], "entry:">, Alias<entry>;
 
+def libpath : Separate<["-", "/"], "libpath">,
+    HelpText<"Additional library search path">;
+def libpath_c: Joined<["-", "/"], "libpath:">, Alias<libpath>;
+
 def force : Flag<["-", "/"], "force">,
     HelpText<"Allow undefined symbols when creating executables">;
 
index bb189e9..f79dc74 100644 (file)
@@ -17,6 +17,8 @@
 #include "lld/ReaderWriter/PECOFFTargetInfo.h"
 #include "llvm/Support/COFF.h"
 
+#include <vector>
+
 using namespace llvm;
 using namespace lld;
 
@@ -39,6 +41,7 @@ TEST_F(WinLinkParserTest, Basic) {
   EXPECT_EQ("a.obj", inputFile(0));
   EXPECT_EQ("b.obj", inputFile(1));
   EXPECT_EQ("c.obj", inputFile(2));
+  EXPECT_TRUE(_info.getInputSearchPaths().empty());
   EXPECT_EQ(6, _info.getMinOSVersion().majorVersion);
   EXPECT_EQ(0, _info.getMinOSVersion().minorVersion);
   EXPECT_EQ(1024 * 1024ULL, _info.getStackReserve());
@@ -49,7 +52,7 @@ TEST_F(WinLinkParserTest, Basic) {
 }
 
 TEST_F(WinLinkParserTest, WindowsStyleOption) {
-  EXPECT_FALSE(parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj", 
+  EXPECT_FALSE(parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj",
                   nullptr));
   EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
   EXPECT_EQ("a.exe", _info.outputPath());
@@ -72,6 +75,15 @@ TEST_F(WinLinkParserTest, NonStandardFileExtension) {
   EXPECT_EQ("foo.o", inputFile(0));
 }
 
+TEST_F(WinLinkParserTest, Libpath) {
+  EXPECT_FALSE(parse("link.exe", "-libpath", "dir1", "-libpath", "dir2",
+                     nullptr));
+  const std::vector<StringRef> &paths = _info.getInputSearchPaths();
+  EXPECT_EQ((size_t)2, paths.size());
+  EXPECT_EQ("dir1", paths[0]);
+  EXPECT_EQ("dir2", paths[1]);
+}
+
 TEST_F(WinLinkParserTest, MinMajorOSVersion) {
   EXPECT_FALSE(parse("link.exe", "-subsystem", "windows,3", "foo.o", nullptr));
   EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _info.getSubsystem());