gollvm: factor in prefix dirs (-B args) in package search

For compatibility with gccgo, include prefix dirs (-B args) when
when constructing the package search path.

Change-Id: I1d1904f33ed89aad56fe26e33bb3beb87df5ae12
Reviewed-on: https://go-review.googlesource.com/116358
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/driver/CompileGo.cpp b/driver/CompileGo.cpp
index 14f1809..e790391 100644
--- a/driver/CompileGo.cpp
+++ b/driver/CompileGo.cpp
@@ -539,13 +539,20 @@
   // Make up a list of dirs starting with -L args, then -B args,
   // and finally the installation dir.
   std::vector<std::string> dirs;
+
+  // First -L args.
   for (auto &dir : args_.getAllArgValues(gollvm::options::OPT_L)) {
     if (!sys::fs::is_directory(dir))
       continue;
     dirs.push_back(dir);
   }
 
-  // FIXME: add -B args here
+  // Add in -B args.
+  for (const std::string &pdir : driver_.prefixes()) {
+    if (!sys::fs::is_directory(pdir))
+      continue;
+    dirs.push_back(pdir);
+  }
 
   // Finish up with system install dir.
   dirs.push_back(GOLLVM_INSTALL_LIBDIR);
diff --git a/driver/Driver.h b/driver/Driver.h
index e6185ca..6e42123 100644
--- a/driver/Driver.h
+++ b/driver/Driver.h
@@ -94,6 +94,9 @@
   // Install directory of compiler binary.
   std::string installDir() { return installDir_; }
 
+  // Prefix directories (supplied via -B args)
+  const std::vector<std::string> &prefixes() const { return prefixes_; }
+
   // Helpers related to command line options.
   llvm::PICLevel::Level getPicLevel();
   llvm::PIELevel::Level getPieLevel();