gollvm: fix for link failure with -buildmode=c-shared

The gollvm driver's interpretation of the -nostdlib command line
option was not quite correct -- when this option is in effect we don't
include start/end files (ex: crt1.o) but we do still need to pass the
proper toolchain-specific -L arguments to the linker to control how
libgcc is picked up.

Change-Id: I65dbf4804d5cb2df46380213bdfb4f56bd71185d
Reviewed-on: https://go-review.googlesource.com/c/156899
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/driver/GnuTools.cpp b/driver/GnuTools.cpp
index 73f5f0b..026565d 100644
--- a/driver/GnuTools.cpp
+++ b/driver/GnuTools.cpp
@@ -357,15 +357,12 @@
 
   bool useStdLib = !args.hasArg(gollvm::options::OPT_nostdlib);
 
-  if (useStdLib) {
+  // Select proper options depending on presence of -static/-shared, etc.
+  // Dynamic linker selection is also done here.
+  addSharedAndOrStaticFlags(cmdArgs);
 
-    // Select proper options depending on presence of -static/-shared, etc.
-    // Dynamic linker selection is also done here.
-    addSharedAndOrStaticFlags(cmdArgs);
-
-    // Add crtbegin*.
+  if (useStdLib)
     addBeginFiles(cmdArgs);
-  }
 
   // Incorporate inputs and -l/-L flags with -Wl,.. and -Xlinker args, in
   // correct order.
@@ -397,6 +394,13 @@
 
     // crtend files.
     addEndFiles(cmdArgs);
+
+  } else {
+
+    // For the -nostdlib case we don't want start/end files, but we
+    // still need the toolchain-specific -L args so that the correct
+    // version of libgcc, etc.
+    addFilePathArgs(cmdArgs);
   }
 
   // end of args.