summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/lib/Driver/WinLinkDriver.cpp36
-rw-r--r--lld/unittests/DriverTests/WinLinkDriverTest.cpp9
2 files changed, 20 insertions, 25 deletions
diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp
index 631bfe369cb..ca84d6534a0 100644
--- a/lld/lib/Driver/WinLinkDriver.cpp
+++ b/lld/lib/Driver/WinLinkDriver.cpp
@@ -1144,15 +1144,22 @@ bool WinLinkDriver::doParse(int argc, const char *argv[],
}
}
- // Move files with ".lib" extension at the end of the input file list. Say
- // foo.obj depends on bar.lib. The linker needs to accept both "bar.lib
- // foo.obj" and "foo.obj bar.lib".
- auto compfn = [](StringRef a, StringRef b) {
- return !a.endswith_lower(".lib") && b.endswith_lower(".lib");
- };
- std::stable_sort(inputFiles.begin(), inputFiles.end(), compfn);
- for (StringRef path : inputFiles)
- files.push_back(std::unique_ptr<FileNode>(new PECOFFFileNode(ctx, path)));
+ // Arguments after "--" are interpreted as filenames even if they
+ // start with a hypen or a slash. This is not compatible with link.exe
+ // but useful for us to test lld on Unix.
+ if (llvm::opt::Arg *dashdash = parsedArgs->getLastArg(OPT_DASH_DASH))
+ for (const StringRef value : dashdash->getValues())
+ inputFiles.push_back(value);
+
+ // Prepare objects to add them to input graph.
+ for (StringRef path : inputFiles) {
+ path = ctx.allocate(path);
+ if (path.endswith_lower(".lib")) {
+ libraries.push_back(std::unique_ptr<FileNode>(new PECOFFLibraryNode(ctx, path)));
+ } else {
+ files.push_back(std::unique_ptr<FileNode>(new PECOFFFileNode(ctx, path)));
+ }
+ }
// Use the default entry name if /entry option is not given.
if (ctx.entrySymbolName().empty() && !parsedArgs->getLastArg(OPT_noentry))
@@ -1180,17 +1187,6 @@ bool WinLinkDriver::doParse(int argc, const char *argv[],
for (const StringRef symbolName : ctx.initialUndefinedSymbols())
ctx.addDeadStripRoot(symbolName);
- // Arguments after "--" are interpreted as filenames even if they
- // start with a hypen or a slash. This is not compatible with link.exe
- // but useful for us to test lld on Unix.
- if (llvm::opt::Arg *dashdash = parsedArgs->getLastArg(OPT_DASH_DASH)) {
- for (const StringRef value : dashdash->getValues()) {
- std::unique_ptr<FileNode> elem(
- new PECOFFFileNode(ctx, ctx.allocate(value)));
- files.push_back(std::move(elem));
- }
- }
-
// Add the libraries specified by /defaultlib unless they are already added
// nor blacklisted by /nodefaultlib.
if (!ctx.getNoDefaultLibAll())
diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp
index a8218a844ff..0313a6ceff8 100644
--- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp
+++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp
@@ -137,14 +137,13 @@ TEST_F(WinLinkParserTest, Libpath) {
//
TEST_F(WinLinkParserTest, InputOrder) {
- EXPECT_TRUE(parse("link.exe", "b.lib", "b.obj", "c.obj", "a.lib", "a.obj",
+ EXPECT_TRUE(parse("link.exe", "a.lib", "b.obj", "c.obj", "a.lib", "d.obj",
nullptr));
- EXPECT_EQ(6, inputFileCount());
+ EXPECT_EQ(4, inputFileCount());
EXPECT_EQ("b.obj", inputFile(0));
EXPECT_EQ("c.obj", inputFile(1));
- EXPECT_EQ("a.obj", inputFile(2));
- EXPECT_EQ("b.lib", inputFile(3));
- EXPECT_EQ("a.lib", inputFile(4));
+ EXPECT_EQ("d.obj", inputFile(2));
+ EXPECT_EQ("a.lib", inputFile(3, 0));
}
//
OpenPOWER on IntegriCloud