gollvm: fix ordering of toolchain -L relative to libgo install dir

When constructing the linker command line, make sure we emit the "-L"
option to pick up the Go libraries prior to the -L options used to
pick up system libraries (such as libgcc), since it is possible to
accidentally pick up libgo.a/libgo.so from the host system instead of
the copy in the install.

Change-Id: I33f7c0b78ca82fc1e85bfd467f0e652d87d133c8
Reviewed-on: https://go-review.googlesource.com/114089
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/driver/GnuTools.cpp b/driver/GnuTools.cpp
index 02e2c42..bfcfaa5 100644
--- a/driver/GnuTools.cpp
+++ b/driver/GnuTools.cpp
@@ -241,6 +241,8 @@
   }
 }
 
+// Adds each thing in the toolchain filepath as an -L option.
+
 void Linker::addFilePathArgs(llvm::opt::ArgStringList &cmdArgs)
 {
   llvm::opt::ArgList &args = toolchain().driver().args();
@@ -255,6 +257,7 @@
   // Go and pthread related libs.
   cmdArgs.push_back("-lgobegin");
   cmdArgs.push_back("-lgo");
+  addFilePathArgs(cmdArgs);
   cmdArgs.push_back("-lm");
   cmdArgs.push_back("-u");
   cmdArgs.push_back("pthread_create");
@@ -281,6 +284,7 @@
   if (isStaticLibgo)
     cmdArgs.push_back("-Bdynamic");
 
+  addFilePathArgs(cmdArgs);
   cmdArgs.push_back("-lm");
   cmdArgs.push_back("--wrap=pthread_create");
 
@@ -344,9 +348,6 @@
   combineInputsWithEscapes(ldEscapes, ldFlags,
                            inputArtifacts, args, cmdArgs);
 
-  // Add each thing in the toolchain filepath as an -L option.
-  addFilePathArgs(cmdArgs);
-
   // Add -m flag.
   addLDM(cmdArgs);