[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-07 Thread Manoj Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC329512: [Driver] Update GCC libraries detection logic for 
Gentoo. (authored by manojgupta, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45233?vs=141295=141501#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp

Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1676,18 +1676,21 @@
   // in /usr. This avoids accidentally enforcing the system GCC version
   // when using a custom toolchain.
   if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
-for (StringRef CandidateTriple : ExtraTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateBiarchTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
-return;
-}
+SmallVector GentooTestTriples;
+// Try to match an exact triple as target triple first.
+// e.g. crossdev -S x86_64-gentoo-linux-gnu will install gcc libs for
+// x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
+// may pick the libraries for x86_64-pc-linux-gnu even when exact matching
+// triple x86_64-gentoo-linux-gnu is present.
+GentooTestTriples.push_back(TargetTriple.str());
+// Check rest of triples.
+GentooTestTriples.append(ExtraTripleAliases.begin(),
+ ExtraTripleAliases.end());
+GentooTestTriples.append(CandidateTripleAliases.begin(),
+ CandidateTripleAliases.end());
+if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
+  CandidateBiarchTripleAliases))
+  return;
   }
 
   // Loop over the various components which exist and select the best GCC
@@ -1700,6 +1703,9 @@
   const std::string LibDir = Prefix + Suffix.str();
   if (!D.getVFS().exists(LibDir))
 continue;
+  // Try to match the exact target triple first.
+  ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, TargetTriple.str());
+  // Try rest of possible triples.
   for (StringRef Candidate : ExtraTripleAliases) // Try these first.
 ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
   for (StringRef Candidate : CandidateTripleAliases)
@@ -2193,6 +2199,22 @@
   }
 }
 
+bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
+const llvm::Triple , const ArgList ,
+const SmallVectorImpl ,
+const SmallVectorImpl ) {
+  for (StringRef CandidateTriple : CandidateTriples) {
+if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
+  return true;
+  }
+
+  for (StringRef CandidateTriple : CandidateBiarchTriples) {
+if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
+  return true;
+  }
+  return false;
+}
+
 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
 const llvm::Triple , const ArgList ,
 StringRef CandidateTriple, bool NeedsBiarchSuffix) {
@@ -2205,23 +2227,53 @@
 for (StringRef Line : Lines) {
   Line = Line.trim();
   // CURRENT=triple-version
-  if (Line.consume_front("CURRENT=")) {
-const std::pair ActiveVersion =
-  Line.rsplit('-');
-// Note: Strictly speaking, we should be 

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-07 Thread Michał Górny via Phabricator via cfe-commits
mgorny accepted this revision.
mgorny added a comment.
This revision is now accepted and ready to land.

Works fine, thanks a lot! Note that I haven't tested crossdev or anything 
special, just regular multilib.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-07 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

I'm sorry, I see the problem now — the diff generated by Phabricator does not 
include the empty files x_x (seriously, this thing keeps surprising me in how 
broken it could be). I'm going to try again with correct file set tonight or 
tomorrow. If you could send the complete patch (preferably -p1 if you have one) 
to mgorny AT gentoo.org, that would also be helpful.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-06 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

I can't reproduce this using the trunk llvm. Does it pass for you if %clang is 
replaced by %clang++ in the test case?


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-06 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Well, it's better:

  Failing Tests (1):
  Clang :: Driver/linux-header-search.cpp

It is apparently the new test failing:

  + 
/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/bin/clang
 -no-canonical-prefixes 
/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/linux-header-search.cpp
 -### -fsyntax-only -target i386-unknown-linux-gnu -stdlib=libstdc++ 
--sysroot=/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree
 --gcc-toolchain=
  + 
/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/bin/clang
 -no-canonical-prefixes 
/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/linux-header-search.cpp
 -### -fsyntax-only -target x86_64-unknown-linux-gnu -stdlib=libstdc++ 
--sysroot=/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree
 --gcc-toolchain=
  + /usr/lib64/llvm/6/bin/FileCheck --check-prefix=CHECK-GENTOO-4-9-X 
/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/linux-header-search.cpp
  
/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/linux-header-search.cpp:359:24:
 error: expected string not found in input
  // CHECK-GENTOO-4-9-X: "-internal-isystem" 
"[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
 ^
  :5:752: note: scanning from here
   
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/bin/clang"
 "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-fsyntax-only" "-disable-free" 
"-disable-llvm-verifier" "-discard-value-names" "-main-file-name" 
"linux-header-search.cpp" "-mrelocation-model" "static" "-mthread-model" 
"posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" 
"-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" 
"x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/bin/../../../../lib/clang/6.0.0"
 "-isysroot" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree"
 "-internal-isystem" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/local/include"
 "-internal-isystem" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/bin/../../../../lib/clang/6.0.0/include"
 "-internal-externc-isystem" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/include"
 "-internal-externc-isystem" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/include"
 "-fdeprecated-macro" "-fdebug-compilation-dir" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/test/Driver"
 "-ferror-limit" "19" "-fmessage-length" "0" "-fobjc-runtime=gcc" 
"-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-x" "c++" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/linux-header-search.cpp"









 ^
  :5:752: note: with variable "SYSROOT" equal to 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree"
   
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/bin/clang"
 "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-fsyntax-only" "-disable-free" 
"-disable-llvm-verifier" "-discard-value-names" "-main-file-name" 
"linux-header-search.cpp" "-mrelocation-model" "static" "-mthread-model" 
"posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" 
"-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" 
"x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src-abi_x86_32.x86/bin/../../../../lib/clang/6.0.0"
 "-isysroot" 
"/var/tmp/portage/sys-devel/clang-6.0.0-r1/work/x/y/cfe-6.0.0.src/test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree"
 "-internal-isystem" 

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-06 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Michał, can you give the latest change a try? Hopefully it should not break any 
tests.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-06 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 141295.
manojgupta edited the summary of this revision.
manojgupta added a comment.

Can solve crossdev issue by passing -gcc-toolchain=/usr
so just detect gcc libs as an offset to sysroot for now.


Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp

Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -343,6 +343,59 @@
 // CHECK-GENTOO-4-9-3-32: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-GENTOO-4-9-3-32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
+// Test support for parsing Gentoo's gcc-config -- clang should parse the
+// /etc/env.d/gcc/config-x86_64-pc-linux-gnu file to find CURRENT gcc used.
+// Then should pick the multilibs from version 4.9.x specified in
+// /etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_4.9.x_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X %s
+//
+// CHECK-GENTOO-4-9-X: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnux32 -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_4.9.x_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X-X32 %s
+// CHECK-GENTOO-4-9-X-X32: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X-X32: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu/x32"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target i386-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_4.9.x_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X-32 %s
+// CHECK-GENTOO-4-9-X-32: "{{.*}}clang{{.*}}" "-cc1"
+// 

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-06 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

To be honest, I don't really know. But since we're not installing it straight 
to `/usr`, I suppose that's not a problem we need to solve right now.

However, they do work with clang installed in `/usr/lib/llvm/*/bin`, and this 
patch must not regress that. So if your `/usr` hack solves that, I don't see a 
problem with it.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-05 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

I think the tests are already broken in Gentoo when clang is installed in 
/usr/bin even without this patch.  The tests only work if clang binary is not 
installed in /usr/bin.

RootCause is the existing lines in Gnu.cpp:

  

  // Then look for gcc installed alongside clang.
  Prefixes.push_back(D.InstalledDir + "/..");

e.g. Specified debian sysroot is not picked  as expected for the following 
command line.

$ clang -v --target=i386-unknown-linux   --gcc-toolchain=""   
--sysroot=test/Driver/Inputs/debian_multiarch_tree 2>&1 
clang version 7.0.0
Target: i386-unknown-linux
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-pc-linux-gnu/4.9.x
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/4.9.x
Found candidate GCC installation: 
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x
Found candidate GCC installation: 
test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/i686-linux-gnu/4.5
Found candidate GCC installation: 
test/Driver/Inputs/debian_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/4.5
Selected GCC installation: /usr/bin/../lib/gcc/i686-pc-linux-gnu/4.9.x
Candidate multilib: .;@m32
Selected multilib: .;@m32


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-05 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Ok, that's a problem. I think we really ought to consider all possibilites of 
sysroot first, and either do not fall back to main system at all or do that 
only if sysroot doesn't have any install at all. Basically, it is important 
that we don't break non-Gentoo sysroots, even when running on top of Gentoo.

I don't really understand what you mean with the prefixes stuff but it doesn't 
sound like it's going to solve the problem.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-05 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

My understanding is that some of the tests are failing since we are scanning 
for Gentoo specific GCC installation first in both sysroot and "/". So, clang 
succeeds in find the libraries in "/usr/lib/gcc" even when sysroot argument is 
passed.
Previously, "/usr/lib/gcc" was not scanned when sysroot was passed.

Maybe, it is better to add /usr to list of paths to search instead of scanning 
in "/"?

Basically, Remove the newly added line 2245: SysRootPrefixes.push_back("");
and instead do Prefixes.push_back("/usr") ?


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-05 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Ok, I've tried it on top of clang-6.0.0 and I get the following test failures:

  Failing Tests (8):
  Clang :: Driver/android-ndk-standalone.cpp
  Clang :: Driver/constructors.c
  Clang :: Driver/cuda-detect.cu
  Clang :: Driver/env.c
  Clang :: Driver/gcc-version-debug.c
  Clang :: Driver/linux-header-search.cpp
  Clang :: Driver/linux-ld.c
  Clang :: Driver/pic.c

Could you check whether the tests pass for you? Me using 6.0.0 may be the 
culprit here but I don't think it should have such significant effect.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-05 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 141182.
manojgupta added a comment.

Updated tests and added a sysroot to test that LDLIBS are picked by
parsing /etc/env.d/gcc/tuple-version file.


Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_4.9.x_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp

Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -343,6 +343,59 @@
 // CHECK-GENTOO-4-9-3-32: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-GENTOO-4-9-3-32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
+// Test support for parsing Gentoo's gcc-config -- clang should parse the
+// /etc/env.d/gcc/config-x86_64-pc-linux-gnu file to find CURRENT gcc used.
+// Then should pick the multilibs from version 4.9.x specified in
+// /etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_4.9.x_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X %s
+//
+// CHECK-GENTOO-4-9-X: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnux32 -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_4.9.x_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X-X32 %s
+// CHECK-GENTOO-4-9-X-X32: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X-X32: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu/x32"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target i386-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_4.9.x_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X-32 %s
+// CHECK-GENTOO-4-9-X-32: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X-32: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

If that's not a problem, then the more tests, the merrier ;-). Preferably 
something specific to crossdev would be helpful, given this is a new use case, 
and/or something that would actually have directory mismatches with CURRENT 
entry name (i.e. that wouldn't have worked before).


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 141099.
manojgupta added a comment.

Avoid double appending of sysroot prefix to base path.


Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/crtbegin.o
  test/Driver/linux-header-search.cpp

Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -308,40 +308,51 @@
 // RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
 // RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
 // RUN: --gcc-toolchain="" \
-// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3 %s
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X %s
+//
+// CHECK-GENTOO-4-9-X: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
 // Test that gcc-config support does not break multilib.
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target x86_64-unknown-linux-gnux32 -stdlib=libstdc++ \
 // RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
 // RUN: --gcc-toolchain="" \
-// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3-X32 %s
-// CHECK-GENTOO-4-9-3-X32: "{{.*}}clang{{.*}}" "-cc1"
-// CHECK-GENTOO-4-9-3-X32: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-GENTOO-4-9-3-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/x86_64-pc-linux-gnu/x32"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/backward"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
-// CHECK-GENTOO-4-9-3-X32: "-internal-externc-isystem" "[[SYSROOT]]/include"
-// CHECK-GENTOO-4-9-3-X32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X-X32 %s
+// CHECK-GENTOO-4-9-X-X32: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X-X32: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu/x32"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target 

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Modified an existing gentoo sysroot as the test case. Please let me know if you 
want me checkin a new sysroot.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 141096.
manojgupta added a comment.

Fix a bug in passing the actual path when libraries are present in sysroot.


Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/x32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/32/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/x32/crtbegin.o
  test/Driver/linux-header-search.cpp

Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -308,40 +308,51 @@
 // RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
 // RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
 // RUN: --gcc-toolchain="" \
-// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3 %s
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X %s
+//
+// CHECK-GENTOO-4-9-X: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
 // Test that gcc-config support does not break multilib.
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target x86_64-unknown-linux-gnux32 -stdlib=libstdc++ \
 // RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
 // RUN: --gcc-toolchain="" \
-// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3-X32 %s
-// CHECK-GENTOO-4-9-3-X32: "{{.*}}clang{{.*}}" "-cc1"
-// CHECK-GENTOO-4-9-3-X32: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-GENTOO-4-9-3-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/x86_64-pc-linux-gnu/x32"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/backward"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
-// CHECK-GENTOO-4-9-3-X32: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
-// CHECK-GENTOO-4-9-3-X32: "-internal-externc-isystem" "[[SYSROOT]]/include"
-// CHECK-GENTOO-4-9-3-X32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-X-X32 %s
+// CHECK-GENTOO-4-9-X-X32: "{{.*}}clang{{.*}}" "-cc1"
+// CHECK-GENTOO-4-9-X-X32: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/x86_64-pc-linux-gnu/x32"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/include/g++-v4.9.3/backward"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[SYSROOT]]/usr/local/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-isystem" "[[RESOURCE_DIR]]{{/|}}include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/include"
+// CHECK-GENTOO-4-9-X-X32: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: 

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 141084.
manojgupta added a comment.

Fix some typos.
Reduced indent in the loop.


Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h

Index: lib/Driver/ToolChains/Gnu.h
===
--- lib/Driver/ToolChains/Gnu.h
+++ lib/Driver/ToolChains/Gnu.h
@@ -265,9 +265,15 @@
 StringRef CandidateTriple,
 bool NeedsBiarchSuffix = false);
 
+bool ScanGentooConfigs(const llvm::Triple ,
+   const llvm::opt::ArgList ,
+   const SmallVectorImpl ,
+   const SmallVectorImpl );
+
 bool ScanGentooGccConfig(const llvm::Triple ,
  const llvm::opt::ArgList ,
  StringRef CandidateTriple,
+ const std::string& SysRootPrefix,
  bool NeedsBiarchSuffix = false);
   };
 
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1707,18 +1707,21 @@
   // in /usr. This avoids accidentally enforcing the system GCC version
   // when using a custom toolchain.
   if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
-for (StringRef CandidateTriple : ExtraTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateBiarchTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
-return;
-}
+SmallVector GentooTestTriples;
+// Try to match an exact triple as target triple first.
+// e.g. crossdev -S x86_64-gentoo-linux-gnu will install gcc libs for
+// x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
+// may pick the libraries for x86_64-pc-linux-gnu even when exact matching
+// triple x86_64-gentoo-linux-gnu is present.
+GentooTestTriples.push_back(TargetTriple.str());
+// Check rest of triples.
+GentooTestTriples.append(ExtraTripleAliases.begin(),
+ ExtraTripleAliases.end());
+GentooTestTriples.append(CandidateTripleAliases.begin(),
+ CandidateTripleAliases.end());
+if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
+  CandidateBiarchTripleAliases))
+  return;
   }
 
   // Loop over the various components which exist and select the best GCC
@@ -2224,35 +2227,97 @@
   }
 }
 
+bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
+const llvm::Triple , const ArgList ,
+const SmallVectorImpl ,
+const SmallVectorImpl ) {
+  // First scan libraries from the sysroot directory if specified.
+  // If not successful, scan the root directories. This is needed to find
+  // cross-compilation files/libraries installed by crossdev. For instance,
+  // crossdev -S aarch64-gentoo-linux-gnu installs GCC libraries in
+  // /usr/lib/gcc/version/aarch64-gentoo-linux-gnu and the headers are
+  // installed at /usr/aarch64-gentoo-linux-gnu. Sysroot argument is
+  // needed to find the headers installed in /usr/aarch64-gentoo-linux-gnu.
+  SmallVector SysRootPrefixes;
+  if (!D.SysRoot.empty()) {
+SysRootPrefixes.push_back(D.SysRoot);
+  }
+  SysRootPrefixes.push_back("");
+
+  for (const std::string  : SysRootPrefixes) {
+for (StringRef CandidateTriple : CandidateTriples) {
+  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, SysRoot))
+return true;
+}
+
+for (StringRef CandidateTriple : CandidateBiarchTriples) {
+  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, SysRoot,
+  true))
+return true;
+}
+  }
+  return false;
+}
+
 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
 const llvm::Triple , const ArgList ,
-StringRef CandidateTriple, bool NeedsBiarchSuffix) {
+StringRef CandidateTriple, const std::string ,
+bool NeedsBiarchSuffix) {
   llvm::ErrorOr File =
-  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  D.getVFS().getBufferForFile(SysRootPrefix + "/etc/env.d/gcc/config-" +
   CandidateTriple.str());
   if (File) {
 SmallVector Lines;
 File.get()->getBuffer().split(Lines, "\n");
 for (StringRef Line : Lines) {
   Line = Line.trim();
   // CURRENT=triple-version
-  if (Line.consume_front("CURRENT=")) {
-const std::pair ActiveVersion 

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

Thousands of lines of C++ to answer one of life's most simple questions: where 
are the libraries and where are the headers. =p

lgtm




Comment at: lib/Driver/ToolChains/Gnu.cpp:2275
   // CURRENT=triple-version
   if (Line.consume_front("CURRENT=")) {
+// Actual config file pointed to by CURRENT.

Can you break the loop here to reduce indentation of the config parsing logic 
below?


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added reviewers: thakis, rnk.
manojgupta added a comment.

Adding more reviewers.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Thanks. Besides that one tiny nit, looks good at a first glance. I'll test it 
tomorrow or the next day (but only for the most basic use, sorry).

However, I do not feel confident enough with Clang code to ack change this 
large on my own. So let's wait for @chandlerc to take a second look, or maybe 
try to add more reviewers.




Comment at: lib/Driver/ToolChains/Gnu.cpp:2300
+ConfLine = ConfLine.trim();
+if (ConfLine.consume_front("LDPATH=\"") &&
+ConfLine.consume_back("\"")) {

mgorny wrote:
> This probably doesn't harm but I'd prefer if quotes weren't considered an 
> obligatory part of the string. I'd rather grab it by `LDPATH=` and strip 
> quotes afterwards if present on both sides. But I won't insist on this.
Well, I meant stripping them if **both** are present. However, this is not a 
biggie.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta marked 3 inline comments as done.
manojgupta added inline comments.



Comment at: lib/Driver/ToolChains/Gnu.cpp:2303
+  std::pair GentooLibs = ConfLine.split(':');
+  GentooScanPaths.push_back(GentooLibs.first.str());
+  if (!GentooLibs.second.empty()) {

mgorny wrote:
> Here you seem to assume that there would be at most 2 paths. That's a wrong 
> assumption — there are triple-ABI targets (e.g. amd64 with x32 variant), and 
> there is no reason prohibiting more LDPATHs. So please use the 'full' split, 
> and iterate over all paths.
I had forgotten about x32. Splitting to get all paths is the right thing to do 
anyway.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 141019.
manojgupta added a comment.

Address requested changes.


Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h

Index: lib/Driver/ToolChains/Gnu.h
===
--- lib/Driver/ToolChains/Gnu.h
+++ lib/Driver/ToolChains/Gnu.h
@@ -265,9 +265,15 @@
 StringRef CandidateTriple,
 bool NeedsBiarchSuffix = false);
 
+bool ScanGentooConfigs(const llvm::Triple ,
+   const llvm::opt::ArgList ,
+   const SmallVectorImpl ,
+   const SmallVectorImpl );
+
 bool ScanGentooGccConfig(const llvm::Triple ,
  const llvm::opt::ArgList ,
  StringRef CandidateTriple,
+ const std::string& SysRootPrefix,
  bool NeedsBiarchSuffix = false);
   };
 
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1707,18 +1707,21 @@
   // in /usr. This avoids accidentally enforcing the system GCC version
   // when using a custom toolchain.
   if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
-for (StringRef CandidateTriple : ExtraTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateBiarchTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
-return;
-}
+SmallVector GentooTestTriples;
+// Try to match an exact triple as target triple first.
+// e.g. crossdev -S x86_64-gentoo-linux-gnu will install gcc libs for
+// x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
+// may pick the libraries for x86_64-pc-linux-gnu even when exact matching
+// triple x86_64-gentoo-linux-gnu is present.
+GentooTestTriples.push_back(TargetTriple.str());
+// Check rest of triples.
+GentooTestTriples.append(ExtraTripleAliases.begin(),
+ ExtraTripleAliases.end());
+GentooTestTriples.append(CandidateTripleAliases.begin(),
+ CandidateTripleAliases.end());
+if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
+  CandidateBiarchTripleAliases))
+  return;
   }
 
   // Loop over the various components which exist and select the best GCC
@@ -2224,38 +2227,100 @@
   }
 }
 
+bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
+const llvm::Triple , const ArgList ,
+const SmallVectorImpl ,
+const SmallVectorImpl ) {
+  // First scan libraries from the sysroot directory if specified.
+  // If not sucessful, scan the root directories. This is needed to find
+  // cross-compilation files/libraries installed by crossdev. For instance,
+  // crossdev -S aarch64-gentoo-linux-gnu installs GCC libraries in
+  // /usr/lib/gcc/version/aarch64-gentoo-linux-gnu and the headers are
+  // installed at /usr/aarch64-gentoo-linux-gnu. Sysroot argument is
+  // needed to find the headers installed in /usr/aarch64-gentoo-linux-gnu.
+  SmallVector SysRootPrefixes;
+  if (!D.SysRoot.empty()) {
+SysRootPrefixes.push_back(D.SysRoot);
+  }
+  SysRootPrefixes.push_back("");
+
+  for (const std::string  : SysRootPrefixes) {
+for (StringRef CandidateTriple : CandidateTriples) {
+  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, SysRoot))
+return true;
+}
+
+for (StringRef CandidateTriple : CandidateBiarchTriples) {
+  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, SysRoot,
+  true))
+return true;
+}
+  }
+  return false;
+}
+
 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
 const llvm::Triple , const ArgList ,
-StringRef CandidateTriple, bool NeedsBiarchSuffix) {
+StringRef CandidateTriple, const std::string ,
+bool NeedsBiarchSuffix) {
   llvm::ErrorOr File =
-  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  D.getVFS().getBufferForFile(SysRootPrefix + "/etc/env.d/gcc/config-" +
   CandidateTriple.str());
   if (File) {
 SmallVector Lines;
 File.get()->getBuffer().split(Lines, "\n");
 for (StringRef Line : Lines) {
   Line = Line.trim();
   // CURRENT=triple-version
   if (Line.consume_front("CURRENT=")) {
-const std::pair ActiveVersion =
-  

[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-04 Thread Michał Górny via Phabricator via cfe-commits
mgorny requested changes to this revision.
mgorny added inline comments.
This revision now requires changes to proceed.



Comment at: lib/Driver/ToolChains/Gnu.cpp:2284
+// Test the path based on the version in /etc/env.d/gcc/config-{tuple}.
+GentooScanPaths.push_back(SysRootPrefix + "/usr/lib/gcc/" +
+  ActiveVersion.first.str() + "/" +

I'm not sure if there's a point in keeping this if you actually parse the 
config file. I can't think of a really valid case when GCC would be installed 
without LDPATH in the config file. Not saying it's wrong. You may want at least 
to push it after the configfile paths though.



Comment at: lib/Driver/ToolChains/Gnu.cpp:2287
+  ActiveVersion.second.str());
+// Scan the Config file to find installed GCC libaries path.
+// A typical content of gcc config file:

Typo: 'libaries'



Comment at: lib/Driver/ToolChains/Gnu.cpp:2296
+if (ConfigFile) {
+ SmallVector ConfigLines;
+  ConfigFile.get()->getBuffer().split(ConfigLines, "\n");

Misindent.



Comment at: lib/Driver/ToolChains/Gnu.cpp:2300
+ConfLine = ConfLine.trim();
+if (ConfLine.consume_front("LDPATH=\"") &&
+ConfLine.consume_back("\"")) {

This probably doesn't harm but I'd prefer if quotes weren't considered an 
obligatory part of the string. I'd rather grab it by `LDPATH=` and strip quotes 
afterwards if present on both sides. But I won't insist on this.



Comment at: lib/Driver/ToolChains/Gnu.cpp:2303
+  std::pair GentooLibs = ConfLine.split(':');
+  GentooScanPaths.push_back(GentooLibs.first.str());
+  if (!GentooLibs.second.empty()) {

Here you seem to assume that there would be at most 2 paths. That's a wrong 
assumption — there are triple-ABI targets (e.g. amd64 with x32 variant), and 
there is no reason prohibiting more LDPATHs. So please use the 'full' split, 
and iterate over all paths.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-03 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a reviewer: chandlerc.
manojgupta added a comment.

Chandler, I recall that you are also a Gentoo user so please take a look.


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-03 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

Michał, will appreciate if you can test this on your (multiple?) Gentoo 
configurations.
Will work on updating the testcases after that.

To test it locally, I used the following :

$ cat test.cpp

  #include 
  #include 
  
  int main() {
std::cout << " Hello, World!" << std::endl;
return 0;
  }



Setup cross compilers for x86_64 and aarch64.
=

$ sudo crossdev -S x86_64-gentoo-linux-gnu
$ sudo crossdev -S aarch64-gentoo-linux-gnu

$ Build and install clang in a location other than /usr/bin e.g. 
$HOME/clang-testing/bin
Verify that correct gcc libs are picked.
$ /path/to/clang++ --sysroot=/usr/aarch64-gentoo-linux-gnu 
-B/usr/libexec/gcc/aarch64-gentoo-linux-gnu -target aarch64-gentoo-linux-gnu 
test.cpp -o main -Wl,-t -v

Further verify that any lib/headers from x86_64-pc-linux-gnu are NOT picked 
after the patch is applied.
$ /path/to/clang++ --sysroot=/usr/x86_64-gentoo-linux-gnu 
-B/usr/libexec/gcc/x86_64-gentoo-linux-gnu -target x86_64-gentoo-linux-gnu 
test.cpp -o main -Wl,-t -v


Repository:
  rC Clang

https://reviews.llvm.org/D45233



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45233: [Driver] Update GCC libraries detection logic for Gentoo.

2018-04-03 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added a reviewer: mgorny.

1. Find GCC's LDPATH from the actual GCC config file.
2. Make library detection to take into account crossdev installed 
cross-compiler gcc libraries even when a sysroot is specified.
3. Avoid picking libraries from a similar named tuple if the exact tuple is 
installed.


Repository:
  rC Clang

https://reviews.llvm.org/D45233

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h

Index: lib/Driver/ToolChains/Gnu.h
===
--- lib/Driver/ToolChains/Gnu.h
+++ lib/Driver/ToolChains/Gnu.h
@@ -265,9 +265,15 @@
 StringRef CandidateTriple,
 bool NeedsBiarchSuffix = false);
 
+bool ScanGentooConfigs(const llvm::Triple ,
+   const llvm::opt::ArgList ,
+   const SmallVectorImpl ,
+   const SmallVectorImpl );
+
 bool ScanGentooGccConfig(const llvm::Triple ,
  const llvm::opt::ArgList ,
  StringRef CandidateTriple,
+ const std::string& SysRootPrefix,
  bool NeedsBiarchSuffix = false);
   };
 
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1707,18 +1707,21 @@
   // in /usr. This avoids accidentally enforcing the system GCC version
   // when using a custom toolchain.
   if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
-for (StringRef CandidateTriple : ExtraTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple))
-return;
-}
-for (StringRef CandidateTriple : CandidateBiarchTripleAliases) {
-  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, true))
-return;
-}
+SmallVector GentooTestTriples;
+// Try to match an exact triple as target triple first.
+// e.g. crossdev -S x86_64-gentoo-linux-gnu will install gcc libs for
+// x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
+// may pick the libraries for x86_64-pc-linux-gnu even when exact matching
+// triple x86_64-gentoo-linux-gnu is present.
+GentooTestTriples.push_back(TargetTriple.str());
+// Check rest of triples.
+GentooTestTriples.append(ExtraTripleAliases.begin(),
+ ExtraTripleAliases.end());
+GentooTestTriples.append(CandidateTripleAliases.begin(),
+ CandidateTripleAliases.end());
+if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
+  CandidateBiarchTripleAliases))
+  return;
   }
 
   // Loop over the various components which exist and select the best GCC
@@ -2224,38 +2227,99 @@
   }
 }
 
+bool Generic_GCC::GCCInstallationDetector::ScanGentooConfigs(
+const llvm::Triple , const ArgList ,
+const SmallVectorImpl ,
+const SmallVectorImpl ) {
+  // First scan libraries from the sysroot directory if specified.
+  // If not sucessful, scan the root directories. This is needed to find
+  // cross-compilation files/libraries installed by crossdev. For instance,
+  // crossdev -S aarch64-gentoo-linux-gnu installs GCC libraries in
+  // /usr/lib/gcc/version/aarch64-gentoo-linux-gnu and the headers are
+  // installed at /usr/aarch64-gentoo-linux-gnu. Sysroot argument is
+  // needed to find the headers installed in /usr/aarch64-gentoo-linux-gnu.
+  SmallVector SysRootPrefixes;
+  if (!D.SysRoot.empty()) {
+SysRootPrefixes.push_back(D.SysRoot);
+  }
+  SysRootPrefixes.push_back("");
+
+  for (const std::string  : SysRootPrefixes) {
+for (StringRef CandidateTriple : CandidateTriples) {
+  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, SysRoot))
+return true;
+}
+
+for (StringRef CandidateTriple : CandidateBiarchTriples) {
+  if (ScanGentooGccConfig(TargetTriple, Args, CandidateTriple, SysRoot,
+  true))
+return true;
+}
+  }
+  return false;
+}
+
 bool Generic_GCC::GCCInstallationDetector::ScanGentooGccConfig(
 const llvm::Triple , const ArgList ,
-StringRef CandidateTriple, bool NeedsBiarchSuffix) {
+StringRef CandidateTriple, const std::string ,
+bool NeedsBiarchSuffix) {
   llvm::ErrorOr File =
-  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  D.getVFS().getBufferForFile(SysRootPrefix + "/etc/env.d/gcc/config-" +
   CandidateTriple.str());
   if (File) {
 SmallVector Lines;