[lld] r187256 - [PECOFF][Driver] Add a library file even if it does not exist.

Rui Ueyama ruiu at google.com
Fri Jul 26 15:17:08 PDT 2013


Author: ruiu
Date: Fri Jul 26 17:17:08 2013
New Revision: 187256

URL: http://llvm.org/viewvc/llvm-project?rev=187256&view=rev
Log:
[PECOFF][Driver] Add a library file even if it does not exist.

Missing files will be reported as errors in the later pass, so this patch
does not change the behavior of the LLD linker, but it helps writing unit
tests for the driver.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
    lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h?rev=187256&r1=187255&r2=187256&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFTargetInfo.h Fri Jul 26 17:17:08 2013
@@ -56,8 +56,8 @@ public:
     return _inputSearchPaths;
   }
 
-  bool appendInputFileOrLibrary(std::string path);
-  bool appendLibraryFile(StringRef path);
+  void appendInputFileOrLibrary(std::string path);
+  void appendLibraryFile(StringRef path);
 
   void setBaseAddress(uint64_t addr) { _baseAddress = addr; }
   uint64_t getBaseAddress() const { return _baseAddress; }

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp?rev=187256&r1=187255&r2=187256&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PECOFFTargetInfo.cpp Fri Jul 26 17:17:08 2013
@@ -89,32 +89,32 @@ void PECOFFTargetInfo::addImplicitFiles(
 
 /// Append the given file to the input file list. The file must be an object
 /// file or an import library file.
-bool PECOFFTargetInfo::appendInputFileOrLibrary(std::string path) {
+void PECOFFTargetInfo::appendInputFileOrLibrary(std::string path) {
   std::string ext = llvm::sys::path::extension(path).lower();
   // This is an import library file. Look for the library file in the search
   // paths, unless the path contains a directory name.
   if (ext == ".lib") {
     if (containDirectoryName(path)) {
       appendInputFile(path);
-      return true;
+      return;
     }
-    return appendLibraryFile(path);
+    appendLibraryFile(path);
+    return;
   }
   // This is an object file otherwise. Add ".obj" extension if the given path
   // name has no file extension.
   if (ext.empty())
     path.append(".obj");
   appendInputFile(allocateString(path));
-  return true;
 }
 
 /// Try to find the input library file from the search paths and append it to
 /// the input file list. Returns true if the library file is found.
-bool PECOFFTargetInfo::appendLibraryFile(StringRef filename) {
+void PECOFFTargetInfo::appendLibraryFile(StringRef filename) {
   // Current directory always takes precedence over the search paths.
   if (llvm::sys::fs::exists(filename)) {
     appendInputFile(filename);
-    return true;
+    return;
   }
   // Iterate over the search paths.
   for (StringRef dir : _inputSearchPaths) {
@@ -122,10 +122,10 @@ bool PECOFFTargetInfo::appendLibraryFile
     llvm::sys::path::append(path, filename);
     if (llvm::sys::fs::exists(path.str())) {
       appendInputFile(allocateString(path.str()));
-      return true;
+      return;
     }
   }
-  return false;
+  appendInputFile(filename);
 }
 
 Writer &PECOFFTargetInfo::writer() const {

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=187256&r1=187255&r2=187256&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Fri Jul 26 17:17:08 2013
@@ -111,6 +111,13 @@ TEST_F(WinLinkParserTest, MinMajorMinorO
   EXPECT_EQ(1, _info.getMinOSVersion().minorVersion);
 }
 
+TEST_F(WinLinkParserTest, DefaultLib) {
+  EXPECT_FALSE(parse("link.exe", "/defaultlib:user32.lib", "a.obj", nullptr));
+  EXPECT_EQ(2, inputFileCount());
+  EXPECT_EQ("a.obj", inputFile(0));
+  EXPECT_EQ("user32.lib", inputFile(1));
+}
+
 TEST_F(WinLinkParserTest, Base) {
   EXPECT_FALSE(parse("link.exe", "/base:8388608", "a.obj", nullptr));
   EXPECT_EQ(0x800000U, _info.getBaseAddress());





More information about the llvm-commits mailing list