[lld] r203884 - [PECOFF] Implement /lib option.
Rui Ueyama
ruiu at google.com
Thu Mar 13 20:06:55 PDT 2014
Author: ruiu
Date: Thu Mar 13 22:06:55 2014
New Revision: 203884
URL: http://llvm.org/viewvc/llvm-project?rev=203884&view=rev
Log:
[PECOFF] Implement /lib option.
This option is not documented and seems weird, but yeah we need it anyway.
Added:
lld/trunk/test/pecoff/libarg.test
Modified:
lld/trunk/lib/Driver/WinLinkDriver.cpp
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=203884&r1=203883&r2=203884&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Mar 13 22:06:55 2014
@@ -711,12 +711,40 @@ static bool hasLibrary(const PECOFFLinki
return false;
}
+// If the first command line argument is "/lib", link.exe acts as if it's
+// "lib.exe" command. This feature is not documented and looks weird, or at
+// least seems redundant, but is needed for MSVC compatibility.
+static bool maybeRunLibCommand(int argc, const char **argv, raw_ostream &diag) {
+ if (argc <= 1)
+ return false;
+ if (!StringRef(argv[1]).equals_lower("/lib"))
+ return false;
+ std::string path = llvm::sys::FindProgramByName("lib.exe");
+ if (path.empty()) {
+ diag << "Unable to find lib.exe in PATH\n";
+ return true;
+ }
+
+ // Run lib.exe
+ std::vector<const char *> vec;
+ vec.push_back(path.c_str());
+ for (int i = 2; i < argc; ++i)
+ vec.push_back(argv[i]);
+ vec.push_back(nullptr);
+
+ if (llvm::sys::ExecuteAndWait(path.c_str(), &argv[0]) != 0)
+ diag << "lib.exe failed\n";
+ return true;
+}
+
//
// Main driver
//
-bool WinLinkDriver::linkPECOFF(int argc, const char *argv[],
- raw_ostream &diag) {
+bool WinLinkDriver::linkPECOFF(int argc, const char **argv, raw_ostream &diag) {
+ if (maybeRunLibCommand(argc, argv, diag))
+ return true;
+
PECOFFLinkingContext context;
std::vector<const char *> newargv = processLinkEnv(context, argc, argv);
processLibEnv(context);
Added: lld/trunk/test/pecoff/libarg.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/libarg.test?rev=203884&view=auto
==============================================================================
--- lld/trunk/test/pecoff/libarg.test (added)
+++ lld/trunk/test/pecoff/libarg.test Thu Mar 13 22:06:55 2014
@@ -0,0 +1,8 @@
+# REQUIRES: winlib
+#
+# If argv[1] == "/lib", link.exe morphs into lib.exe.
+#
+# RUN: lld -flavor link /lib >& %t.log
+# RUN: FileCheck %s < %t.log
+
+CHECK: usage: LIB
More information about the llvm-commits
mailing list