gollvm: support one invocation with .go and .o inputs in the wrapper

gccgo's testing framework may invoke gccgo with both .go files
and .o files as input, which does compilation and linking in
one run. Add this support in the wrapper. If the wrapper is
invoked with both .go and .o inputs, it skips the .o files in
compilation, but records them and passes them to the linker.
This makes "rundir" action in gccgo's go.test work.

Change-Id: I3446f0f96e34b93c738075ea49c02d3062a031b3
Reviewed-on: https://go-review.googlesource.com/63590
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/tools/gollvm-wrap.py b/tools/gollvm-wrap.py
index 4988f6b..23acefa 100755
--- a/tools/gollvm-wrap.py
+++ b/tools/gollvm-wrap.py
@@ -121,6 +121,7 @@
   asmfile = None
   minus_s = False
   minus_c = False
+  ofiles = []
   for ii in range(1, len(sys.argv)):
     clarg = sys.argv[ii]
     if skipc != 0:
@@ -187,6 +188,12 @@
     if clarg.startswith("-fdebug-prefix-map"):
       continue
 
+    # skip .o files in compilation, but record
+    # them for linker invocation.
+    if clarg.endswith(".o"):
+      ofiles.append(clarg)
+      continue
+
     nargs.append(clarg)
 
   if not outfile:
@@ -240,7 +247,8 @@
     if not minus_c:
       bd = os.path.dirname(sys.argv[0])
       driver = "%s/gccgo.real" % bd
-      ldcmd = "%s %s -o %s" % (driver, objfile, outfile)
+      ldcmd = "%s %s -o %s " % (driver, objfile, outfile)
+      ldcmd += " ".join(ofiles) # pass extra .o files to the linker
       u.verbose(1, "link command is: %s" % ldcmd)
       rc = u.docmdnf(ldcmd)
       if rc != 0: