<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 20, 2013 at 6:54 PM, Shankar Easwaran <span dir="ltr"><<a href="mailto:shankare@codeaurora.org" target="_blank">shankare@codeaurora.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Rui,<br>
<br>
The InputGraph postProcess could be used to reorder input files. It does use a stable_sort now, and uses ordinals to rearrange them.<br>
<br>
Currently the implementation is not complete, but I think that could be improved.<br></blockquote><div><br></div><div>InputGraph contains different types of InputElements, so working on it is a bit more complicated than on the simple vector of strings. So it feels that it's be better do that here rather than in InputGraph if it suffices.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Any thoughts ?<br>
<br>
Thanks<br>
<br>
Shankar Easwaran<div class="HOEnZb"><div class="h5"><br>
On 11/20/2013 7:08 PM, Rui Ueyama wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: ruiu<br>
Date: Wed Nov 20 19:08:53 2013<br>
New Revision: 195295<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=195295&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=195295&view=rev</a><br>
Log:<br>
[PECOFF] Move files with ".lib" extension to the end of the input file list.<br>
<br>
It's allowed to specify library files *before* object files in the command<br>
line. Object files seems to be processed first, and then their undefined<br>
symbols are resolved from the libraries. This patch implements the compatible<br>
behavior.<br>
<br>
Modified:<br>
     lld/trunk/lib/Driver/<u></u>WinLinkDriver.cpp<br>
     lld/trunk/unittests/<u></u>DriverTests/WinLinkDriverTest.<u></u>cpp<br>
<br>
Modified: lld/trunk/lib/Driver/<u></u>WinLinkDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=195295&r1=195294&r2=195295&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lld/trunk/lib/Driver/<u></u>WinLinkDriver.cpp?rev=195295&<u></u>r1=195294&r2=195295&view=diff</a><br>


==============================<u></u>==============================<u></u>==================<br>
--- lld/trunk/lib/Driver/<u></u>WinLinkDriver.cpp (original)<br>
+++ lld/trunk/lib/Driver/<u></u>WinLinkDriver.cpp Wed Nov 20 19:08:53 2013<br>
@@ -13,6 +13,7 @@<br>
  ///<br>
  //===-------------------------<u></u>------------------------------<u></u>---------------===//<br>
  +#include <algorithm><br>
  #include <cctype><br>
  #include <sstream><br>
  #include <map><br>
@@ -600,6 +601,8 @@ WinLinkDriver::parse(int argc, const cha<br>
      defaultLibs.push_back((*it)-><u></u>getValue());<br>
    }<br>
  +  std::vector<StringRef> inputFiles;<br>
+<br>
    // Process all the arguments and create Input Elements<br>
    for (auto inputArg : *parsedArgs) {<br>
      switch (inputArg->getOption().getID()<u></u>) {<br>
@@ -850,8 +853,7 @@ WinLinkDriver::parse(int argc, const cha<br>
        break;<br>
        case OPT_INPUT:<br>
-      inputElements.push_back(std::<u></u>unique_ptr<InputElement>(<br>
-          new PECOFFFileNode(ctx, ctx.allocate(inputArg-><u></u>getValue()))));<br>
+      inputFiles.push_back(ctx.<u></u>allocate(inputArg->getValue())<u></u>);<br>
        break;<br>
    #define DEFINE_BOOLEAN_FLAG(name, setter)       \<br>
@@ -877,6 +879,17 @@ WinLinkDriver::parse(int argc, const cha<br>
      }<br>
    }<br>
  +  // Move files with ".lib" extension at the end of the input file list. Say<br>
+  // foo.obj depends on bar.lib. The linker needs to accept both "bar.lib<br>
+  // foo.obj" and "foo.obj bar.lib".<br>
+  auto compfn = [](StringRef a, StringRef b) {<br>
+    return !a.endswith_lower(".lib") && b.endswith_lower(".lib");<br>
+  };<br>
+  std::stable_sort(inputFiles.<u></u>begin(), inputFiles.end(), compfn);<br>
+  for (StringRef path : inputFiles)<br>
+    inputElements.push_back(std::<u></u>unique_ptr<InputElement>(<br>
+        new PECOFFFileNode(ctx, path)));<br>
+<br>
    // Use the default entry name if /entry option is not given.<br>
    if (ctx.entrySymbolName().empty()<u></u>)<br>
      ctx.setEntrySymbolName(<u></u>getDefaultEntrySymbolName(ctx)<u></u>);<br>
<br>
Modified: lld/trunk/unittests/<u></u>DriverTests/WinLinkDriverTest.<u></u>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=195295&r1=195294&r2=195295&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lld/trunk/unittests/<u></u>DriverTests/WinLinkDriverTest.<u></u>cpp?rev=195295&r1=195294&r2=<u></u>195295&view=diff</a><br>


==============================<u></u>==============================<u></u>==================<br>
--- lld/trunk/unittests/<u></u>DriverTests/WinLinkDriverTest.<u></u>cpp (original)<br>
+++ lld/trunk/unittests/<u></u>DriverTests/WinLinkDriverTest.<u></u>cpp Wed Nov 20 19:08:53 2013<br>
@@ -131,6 +131,21 @@ TEST_F(WinLinkParserTest, Libpath) {<br>
  }<br>
    //<br>
+// Tests for input file order<br>
+//<br>
+<br>
+TEST_F(WinLinkParserTest, InputOrder) {<br>
+  EXPECT_TRUE(parse("link.exe", "b.lib", "b.obj", "c.obj", "a.lib", "a.obj",<br>
+                    nullptr));<br>
+  EXPECT_EQ(5, inputFileCount());<br>
+  EXPECT_EQ("b.obj", inputFile(0));<br>
+  EXPECT_EQ("c.obj", inputFile(1));<br>
+  EXPECT_EQ("a.obj", inputFile(2));<br>
+  EXPECT_EQ("b.lib", inputFile(3));<br>
+  EXPECT_EQ("a.lib", inputFile(4));<br>
+}<br>
+<br>
+//<br>
  // Tests for command line options that take values.<br>
  //<br>
  <br>
<br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
<br>
<br>
</blockquote>
<br>
<br></div></div><span class="HOEnZb"><font color="#888888">
-- <br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation<br>
<br>
</font></span></blockquote></div><br></div></div>