gollvm: fix some problems with GCC installation detection

Fix a couple of problems with the driver's GCC installation detector
that prevent it from working correctly for certain cross compilers. On
Debian, cross-compiler bits wind up in /usr/lib/gcc-cross, not
/usr/lib/gcc. There was also an off-by-one error in the code that
locates program paths for cross compilers.

Change-Id: I824f206f9b04c88db458754e9b3454de536254cf
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/195320
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/driver/GccUtils.cpp b/driver/GccUtils.cpp
index 079722c..0815ca3 100644
--- a/driver/GccUtils.cpp
+++ b/driver/GccUtils.cpp
@@ -240,13 +240,16 @@
 
 void GCCInstallationDetector::scanPrefix(state &s, const std::string &pref)
 {
+  const char *infixes[] = { "/gcc/", "/gcc-cross/" };
   for (auto &lib : s.libdirs) {
     // Form candidate dir
-    for (auto &tripleAlias : s.tripleAliases) {
-      std::stringstream ss;
-      ss << pref << "/" << lib << "/gcc/" << tripleAlias;
-      for (auto &suffix : s.suffixes)
-        scanCandidate(s, ss.str(), tripleAlias, suffix);
+    for (auto &infix : infixes) {
+      for (auto &tripleAlias : s.tripleAliases) {
+        std::stringstream ss;
+        ss << pref << "/" << lib << infix << tripleAlias;
+        for (auto &suffix : s.suffixes)
+          scanCandidate(s, ss.str(), tripleAlias, suffix);
+      }
     }
   }
 }
diff --git a/driver/LinuxToolChain.cpp b/driver/LinuxToolChain.cpp
index c4fb887..dfce121 100644
--- a/driver/LinuxToolChain.cpp
+++ b/driver/LinuxToolChain.cpp
@@ -58,10 +58,9 @@
   pathlist &ppaths = programPaths();
   auto ftrip = gccDetector_.foundTriple().str();
   addIfPathExists(ppaths, llvm::Twine(gccDetector_.getParentLibPath() +
-                                      "/../" + ftrip +
+                                      "/../../" + ftrip +
                                       "/bin").str());
 
-
   // File paths
   pathlist &fpaths = filePaths();
   addIfPathExists(fpaths, gccDetector_.getLibPath());