Reword and reformat some of the "Multiarch" code in the toolchain setup.

There are fundamentally two different things that were getting conflated
here.

1) A bi-arch GCC toolchain install. This is not a full blown cross
   compiler, but it supports targetting both 32-bit and 64-bit variants
   of the same architecture using multilib OS installs and runtimes.

2) A "multiarch" Debian OS/runtime layout that lays out the libraries,
   headers, etc as-if there were going to be a full blown cross compiler
   even when in reality it is just a bi-arch GCC targeting two variants.
   Also, these tend to use oddly "canonicalized" triples without the
   vendor in them unlike the typical cross compiler runtime library
   search that vanilla GCC cross compilers perform.

Now, when we mean the bi-arch nature of GCC accomplished with just
a suffix or tweak to the GCC paths, we say 'Biarch' or something
related. When we mean the Debian layout of includes and libraries, we
say multiarch or reference the multiarch triple.

In the process of reading and often renaming stuff in all these places,
also reformat with clang-format. No functionality change should be going
on here, this is just tidying up.

llvm-svn: 184632
This commit is contained in:
Chandler Carruth 2013-06-22 11:35:51 +00:00
parent 626032f6fc
commit b427c56399
2 changed files with 168 additions and 207 deletions

View File

@ -1003,23 +1003,20 @@ static StringRef getGCCToolchainDir(const ArgList &Args) {
/// necessary because the driver doesn't store the final version of the target /// necessary because the driver doesn't store the final version of the target
/// triple. /// triple.
Generic_GCC::GCCInstallationDetector::GCCInstallationDetector( Generic_GCC::GCCInstallationDetector::GCCInstallationDetector(
const Driver &D, const Driver &D, const llvm::Triple &TargetTriple, const ArgList &Args)
const llvm::Triple &TargetTriple,
const ArgList &Args)
: IsValid(false) { : IsValid(false) {
llvm::Triple MultiarchTriple llvm::Triple BiarchVariantTriple =
= TargetTriple.isArch32Bit() ? TargetTriple.get64BitArchVariant() TargetTriple.isArch32Bit() ? TargetTriple.get64BitArchVariant()
: TargetTriple.get32BitArchVariant(); : TargetTriple.get32BitArchVariant();
llvm::Triple::ArchType TargetArch = TargetTriple.getArch(); llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
// The library directories which may contain GCC installations. // The library directories which may contain GCC installations.
SmallVector<StringRef, 4> CandidateLibDirs, CandidateMultiarchLibDirs; SmallVector<StringRef, 4> CandidateLibDirs, CandidateBiarchLibDirs;
// The compatible GCC triples for this particular architecture. // The compatible GCC triples for this particular architecture.
SmallVector<StringRef, 10> CandidateTripleAliases; SmallVector<StringRef, 10> CandidateTripleAliases;
SmallVector<StringRef, 10> CandidateMultiarchTripleAliases; SmallVector<StringRef, 10> CandidateBiarchTripleAliases;
CollectLibDirsAndTriples(TargetTriple, MultiarchTriple, CandidateLibDirs, CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
CandidateTripleAliases, CandidateTripleAliases, CandidateBiarchLibDirs,
CandidateMultiarchLibDirs, CandidateBiarchTripleAliases);
CandidateMultiarchTripleAliases);
// Compute the set of prefixes for our search. // Compute the set of prefixes for our search.
SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(), SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(),
@ -1051,81 +1048,58 @@ Generic_GCC::GCCInstallationDetector::GCCInstallationDetector(
ScanLibDirForGCCTriple(TargetArch, Args, LibDir, ScanLibDirForGCCTriple(TargetArch, Args, LibDir,
CandidateTripleAliases[k]); CandidateTripleAliases[k]);
} }
for (unsigned j = 0, je = CandidateMultiarchLibDirs.size(); j < je; ++j) { for (unsigned j = 0, je = CandidateBiarchLibDirs.size(); j < je; ++j) {
const std::string LibDir const std::string LibDir = Prefixes[i] + CandidateBiarchLibDirs[j].str();
= Prefixes[i] + CandidateMultiarchLibDirs[j].str();
if (!llvm::sys::fs::exists(LibDir)) if (!llvm::sys::fs::exists(LibDir))
continue; continue;
for (unsigned k = 0, ke = CandidateMultiarchTripleAliases.size(); k < ke; for (unsigned k = 0, ke = CandidateBiarchTripleAliases.size(); k < ke;
++k) ++k)
ScanLibDirForGCCTriple(TargetArch, Args, LibDir, ScanLibDirForGCCTriple(TargetArch, Args, LibDir,
CandidateMultiarchTripleAliases[k], CandidateBiarchTripleAliases[k],
/*NeedsMultiarchSuffix=*/true); /*NeedsBiarchSuffix=*/ true);
} }
} }
} }
/*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples( /*static*/ void Generic_GCC::GCCInstallationDetector::CollectLibDirsAndTriples(
const llvm::Triple &TargetTriple, const llvm::Triple &TargetTriple, const llvm::Triple &BiarchTriple,
const llvm::Triple &MultiarchTriple,
SmallVectorImpl<StringRef> &LibDirs, SmallVectorImpl<StringRef> &LibDirs,
SmallVectorImpl<StringRef> &TripleAliases, SmallVectorImpl<StringRef> &TripleAliases,
SmallVectorImpl<StringRef> &MultiarchLibDirs, SmallVectorImpl<StringRef> &BiarchLibDirs,
SmallVectorImpl<StringRef> &MultiarchTripleAliases) { SmallVectorImpl<StringRef> &BiarchTripleAliases) {
// Declare a bunch of static data sets that we'll select between below. These // Declare a bunch of static data sets that we'll select between below. These
// are specifically designed to always refer to string literals to avoid any // are specifically designed to always refer to string literals to avoid any
// lifetime or initialization issues. // lifetime or initialization issues.
static const char *const AArch64LibDirs[] = { "/lib" }; static const char *const AArch64LibDirs[] = { "/lib" };
static const char *const AArch64Triples[] = { static const char *const AArch64Triples[] = { "aarch64-none-linux-gnu",
"aarch64-none-linux-gnu", "aarch64-linux-gnu" };
"aarch64-linux-gnu"
};
static const char *const ARMLibDirs[] = { "/lib" }; static const char *const ARMLibDirs[] = { "/lib" };
static const char *const ARMTriples[] = { static const char *const ARMTriples[] = { "arm-linux-gnueabi",
"arm-linux-gnueabi", "arm-linux-androideabi" };
"arm-linux-androideabi" static const char *const ARMHFTriples[] = { "arm-linux-gnueabihf",
}; "armv7hl-redhat-linux-gnueabi" };
static const char *const ARMHFTriples[] = {
"arm-linux-gnueabihf",
"armv7hl-redhat-linux-gnueabi"
};
static const char *const X86_64LibDirs[] = { "/lib64", "/lib" }; static const char *const X86_64LibDirs[] = { "/lib64", "/lib" };
static const char *const X86_64Triples[] = { static const char *const X86_64Triples[] = {
"x86_64-linux-gnu", "x86_64-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-pc-linux-gnu",
"x86_64-unknown-linux-gnu", "x86_64-redhat-linux6E", "x86_64-redhat-linux", "x86_64-suse-linux",
"x86_64-pc-linux-gnu", "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", "x86_64-slackware-linux"
"x86_64-redhat-linux6E",
"x86_64-redhat-linux",
"x86_64-suse-linux",
"x86_64-manbo-linux-gnu",
"x86_64-linux-gnu",
"x86_64-slackware-linux"
}; };
static const char *const X86LibDirs[] = { "/lib32", "/lib" }; static const char *const X86LibDirs[] = { "/lib32", "/lib" };
static const char *const X86Triples[] = { static const char *const X86Triples[] = {
"i686-linux-gnu", "i686-linux-gnu", "i686-pc-linux-gnu", "i486-linux-gnu", "i386-linux-gnu",
"i686-pc-linux-gnu", "i386-redhat-linux6E", "i686-redhat-linux", "i586-redhat-linux",
"i486-linux-gnu", "i386-redhat-linux", "i586-suse-linux", "i486-slackware-linux",
"i386-linux-gnu",
"i386-redhat-linux6E",
"i686-redhat-linux",
"i586-redhat-linux",
"i386-redhat-linux",
"i586-suse-linux",
"i486-slackware-linux",
"i686-montavista-linux" "i686-montavista-linux"
}; };
static const char *const MIPSLibDirs[] = { "/lib" }; static const char *const MIPSLibDirs[] = { "/lib" };
static const char *const MIPSTriples[] = { "mips-linux-gnu" }; static const char *const MIPSTriples[] = { "mips-linux-gnu" };
static const char *const MIPSELLibDirs[] = { "/lib" }; static const char *const MIPSELLibDirs[] = { "/lib" };
static const char *const MIPSELTriples[] = { static const char *const MIPSELTriples[] = { "mipsel-linux-gnu",
"mipsel-linux-gnu", "mipsel-linux-android",
"mipsel-linux-android", "mips-linux-gnu" };
"mips-linux-gnu"
};
static const char *const MIPS64LibDirs[] = { "/lib64", "/lib" }; static const char *const MIPS64LibDirs[] = { "/lib64", "/lib" };
static const char *const MIPS64Triples[] = { "mips64-linux-gnu" }; static const char *const MIPS64Triples[] = { "mips64-linux-gnu" };
@ -1134,134 +1108,129 @@ Generic_GCC::GCCInstallationDetector::GCCInstallationDetector(
static const char *const PPCLibDirs[] = { "/lib32", "/lib" }; static const char *const PPCLibDirs[] = { "/lib32", "/lib" };
static const char *const PPCTriples[] = { static const char *const PPCTriples[] = {
"powerpc-linux-gnu", "powerpc-linux-gnu", "powerpc-unknown-linux-gnu", "powerpc-linux-gnuspe",
"powerpc-unknown-linux-gnu", "powerpc-suse-linux", "powerpc-montavista-linuxspe"
"powerpc-linux-gnuspe",
"powerpc-suse-linux",
"powerpc-montavista-linuxspe"
}; };
static const char *const PPC64LibDirs[] = { "/lib64", "/lib" }; static const char *const PPC64LibDirs[] = { "/lib64", "/lib" };
static const char *const PPC64Triples[] = { static const char *const PPC64Triples[] = { "powerpc64-linux-gnu",
"powerpc64-linux-gnu", "powerpc64-unknown-linux-gnu",
"powerpc64-unknown-linux-gnu", "powerpc64-suse-linux",
"powerpc64-suse-linux", "ppc64-redhat-linux" };
"ppc64-redhat-linux"
};
static const char *const SystemZLibDirs[] = { "/lib64", "/lib" }; static const char *const SystemZLibDirs[] = { "/lib64", "/lib" };
static const char *const SystemZTriples[] = { static const char *const SystemZTriples[] = {
"s390x-linux-gnu", "s390x-linux-gnu", "s390x-unknown-linux-gnu", "s390x-ibm-linux-gnu",
"s390x-unknown-linux-gnu", "s390x-suse-linux", "s390x-redhat-linux"
"s390x-ibm-linux-gnu",
"s390x-suse-linux",
"s390x-redhat-linux"
}; };
switch (TargetTriple.getArch()) { switch (TargetTriple.getArch()) {
case llvm::Triple::aarch64: case llvm::Triple::aarch64:
LibDirs.append(AArch64LibDirs, AArch64LibDirs LibDirs.append(AArch64LibDirs,
+ llvm::array_lengthof(AArch64LibDirs)); AArch64LibDirs + llvm::array_lengthof(AArch64LibDirs));
TripleAliases.append( TripleAliases.append(AArch64Triples,
AArch64Triples, AArch64Triples + llvm::array_lengthof(AArch64Triples)); AArch64Triples + llvm::array_lengthof(AArch64Triples));
MultiarchLibDirs.append( BiarchLibDirs.append(AArch64LibDirs,
AArch64LibDirs, AArch64LibDirs + llvm::array_lengthof(AArch64LibDirs)); AArch64LibDirs + llvm::array_lengthof(AArch64LibDirs));
MultiarchTripleAliases.append( BiarchTripleAliases.append(
AArch64Triples, AArch64Triples + llvm::array_lengthof(AArch64Triples)); AArch64Triples, AArch64Triples + llvm::array_lengthof(AArch64Triples));
break; break;
case llvm::Triple::arm: case llvm::Triple::arm:
case llvm::Triple::thumb: case llvm::Triple::thumb:
LibDirs.append(ARMLibDirs, ARMLibDirs + llvm::array_lengthof(ARMLibDirs)); LibDirs.append(ARMLibDirs, ARMLibDirs + llvm::array_lengthof(ARMLibDirs));
if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) { if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF) {
TripleAliases.append( TripleAliases.append(ARMHFTriples,
ARMHFTriples, ARMHFTriples + llvm::array_lengthof(ARMHFTriples)); ARMHFTriples + llvm::array_lengthof(ARMHFTriples));
} else { } else {
TripleAliases.append( TripleAliases.append(ARMTriples,
ARMTriples, ARMTriples + llvm::array_lengthof(ARMTriples)); ARMTriples + llvm::array_lengthof(ARMTriples));
} }
break; break;
case llvm::Triple::x86_64: case llvm::Triple::x86_64:
LibDirs.append( LibDirs.append(X86_64LibDirs,
X86_64LibDirs, X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs)); X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs));
TripleAliases.append( TripleAliases.append(X86_64Triples,
X86_64Triples, X86_64Triples + llvm::array_lengthof(X86_64Triples)); X86_64Triples + llvm::array_lengthof(X86_64Triples));
MultiarchLibDirs.append( BiarchLibDirs.append(X86LibDirs,
X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs)); X86LibDirs + llvm::array_lengthof(X86LibDirs));
MultiarchTripleAliases.append( BiarchTripleAliases.append(X86Triples,
X86Triples, X86Triples + llvm::array_lengthof(X86Triples)); X86Triples + llvm::array_lengthof(X86Triples));
break; break;
case llvm::Triple::x86: case llvm::Triple::x86:
LibDirs.append(X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs)); LibDirs.append(X86LibDirs, X86LibDirs + llvm::array_lengthof(X86LibDirs));
TripleAliases.append( TripleAliases.append(X86Triples,
X86Triples, X86Triples + llvm::array_lengthof(X86Triples)); X86Triples + llvm::array_lengthof(X86Triples));
MultiarchLibDirs.append( BiarchLibDirs.append(X86_64LibDirs,
X86_64LibDirs, X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs)); X86_64LibDirs + llvm::array_lengthof(X86_64LibDirs));
MultiarchTripleAliases.append( BiarchTripleAliases.append(
X86_64Triples, X86_64Triples + llvm::array_lengthof(X86_64Triples)); X86_64Triples, X86_64Triples + llvm::array_lengthof(X86_64Triples));
break; break;
case llvm::Triple::mips: case llvm::Triple::mips:
LibDirs.append( LibDirs.append(MIPSLibDirs,
MIPSLibDirs, MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs)); MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs));
TripleAliases.append( TripleAliases.append(MIPSTriples,
MIPSTriples, MIPSTriples + llvm::array_lengthof(MIPSTriples)); MIPSTriples + llvm::array_lengthof(MIPSTriples));
MultiarchLibDirs.append( BiarchLibDirs.append(MIPS64LibDirs,
MIPS64LibDirs, MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs)); MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs));
MultiarchTripleAliases.append( BiarchTripleAliases.append(
MIPS64Triples, MIPS64Triples + llvm::array_lengthof(MIPS64Triples)); MIPS64Triples, MIPS64Triples + llvm::array_lengthof(MIPS64Triples));
break; break;
case llvm::Triple::mipsel: case llvm::Triple::mipsel:
LibDirs.append( LibDirs.append(MIPSELLibDirs,
MIPSELLibDirs, MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs)); MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs));
TripleAliases.append( TripleAliases.append(MIPSELTriples,
MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples)); MIPSELTriples + llvm::array_lengthof(MIPSELTriples));
MultiarchLibDirs.append( BiarchLibDirs.append(
MIPS64ELLibDirs, MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs)); MIPS64ELLibDirs,
MultiarchTripleAliases.append( MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs));
MIPS64ELTriples, MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples)); BiarchTripleAliases.append(
MIPS64ELTriples,
MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples));
break; break;
case llvm::Triple::mips64: case llvm::Triple::mips64:
LibDirs.append( LibDirs.append(MIPS64LibDirs,
MIPS64LibDirs, MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs)); MIPS64LibDirs + llvm::array_lengthof(MIPS64LibDirs));
TripleAliases.append( TripleAliases.append(MIPS64Triples,
MIPS64Triples, MIPS64Triples + llvm::array_lengthof(MIPS64Triples)); MIPS64Triples + llvm::array_lengthof(MIPS64Triples));
MultiarchLibDirs.append( BiarchLibDirs.append(MIPSLibDirs,
MIPSLibDirs, MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs)); MIPSLibDirs + llvm::array_lengthof(MIPSLibDirs));
MultiarchTripleAliases.append( BiarchTripleAliases.append(MIPSTriples,
MIPSTriples, MIPSTriples + llvm::array_lengthof(MIPSTriples)); MIPSTriples + llvm::array_lengthof(MIPSTriples));
break; break;
case llvm::Triple::mips64el: case llvm::Triple::mips64el:
LibDirs.append( LibDirs.append(MIPS64ELLibDirs,
MIPS64ELLibDirs, MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs)); MIPS64ELLibDirs + llvm::array_lengthof(MIPS64ELLibDirs));
TripleAliases.append( TripleAliases.append(
MIPS64ELTriples, MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples)); MIPS64ELTriples,
MultiarchLibDirs.append( MIPS64ELTriples + llvm::array_lengthof(MIPS64ELTriples));
MIPSELLibDirs, MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs)); BiarchLibDirs.append(MIPSELLibDirs,
MultiarchTripleAliases.append( MIPSELLibDirs + llvm::array_lengthof(MIPSELLibDirs));
MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples)); BiarchTripleAliases.append(
MIPSELTriples, MIPSELTriples + llvm::array_lengthof(MIPSELTriples));
break; break;
case llvm::Triple::ppc: case llvm::Triple::ppc:
LibDirs.append(PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs)); LibDirs.append(PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs));
TripleAliases.append( TripleAliases.append(PPCTriples,
PPCTriples, PPCTriples + llvm::array_lengthof(PPCTriples)); PPCTriples + llvm::array_lengthof(PPCTriples));
MultiarchLibDirs.append( BiarchLibDirs.append(PPC64LibDirs,
PPC64LibDirs, PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs)); PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs));
MultiarchTripleAliases.append( BiarchTripleAliases.append(
PPC64Triples, PPC64Triples + llvm::array_lengthof(PPC64Triples)); PPC64Triples, PPC64Triples + llvm::array_lengthof(PPC64Triples));
break; break;
case llvm::Triple::ppc64: case llvm::Triple::ppc64:
LibDirs.append( LibDirs.append(PPC64LibDirs,
PPC64LibDirs, PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs)); PPC64LibDirs + llvm::array_lengthof(PPC64LibDirs));
TripleAliases.append( TripleAliases.append(PPC64Triples,
PPC64Triples, PPC64Triples + llvm::array_lengthof(PPC64Triples)); PPC64Triples + llvm::array_lengthof(PPC64Triples));
MultiarchLibDirs.append( BiarchLibDirs.append(PPCLibDirs,
PPCLibDirs, PPCLibDirs + llvm::array_lengthof(PPCLibDirs)); PPCLibDirs + llvm::array_lengthof(PPCLibDirs));
MultiarchTripleAliases.append( BiarchTripleAliases.append(PPCTriples,
PPCTriples, PPCTriples + llvm::array_lengthof(PPCTriples)); PPCTriples + llvm::array_lengthof(PPCTriples));
break; break;
case llvm::Triple::systemz: case llvm::Triple::systemz:
LibDirs.append( LibDirs.append(SystemZLibDirs,
SystemZLibDirs, SystemZLibDirs + llvm::array_lengthof(SystemZLibDirs)); SystemZLibDirs + llvm::array_lengthof(SystemZLibDirs));
TripleAliases.append( TripleAliases.append(SystemZTriples,
SystemZTriples, SystemZTriples + llvm::array_lengthof(SystemZTriples)); SystemZTriples + llvm::array_lengthof(SystemZTriples));
break; break;
default: default:
@ -1275,8 +1244,8 @@ Generic_GCC::GCCInstallationDetector::GCCInstallationDetector(
TripleAliases.push_back(TargetTriple.str()); TripleAliases.push_back(TargetTriple.str());
// Also include the multiarch variant if it's different. // Also include the multiarch variant if it's different.
if (TargetTriple.str() != MultiarchTriple.str()) if (TargetTriple.str() != BiarchTriple.str())
MultiarchTripleAliases.push_back(MultiarchTriple.str()); BiarchTripleAliases.push_back(BiarchTriple.str());
} }
static bool isSoftFloatABI(const ArgList &Args) { static bool isSoftFloatABI(const ArgList &Args) {
@ -1340,10 +1309,12 @@ static StringRef getMipsTargetABISuffix(llvm::Triple::ArchType TargetArch,
return "/32"; return "/32";
} }
static bool findTargetMultiarchSuffix(std::string &Suffix, static bool findTargetBiarchSuffix(std::string &Suffix, StringRef Path,
StringRef Path, llvm::Triple::ArchType TargetArch,
llvm::Triple::ArchType TargetArch, const ArgList &Args) {
const ArgList &Args) { // FIXME: This routine was only intended to model bi-arch toolchains which
// use -m32 and -m64 to swap between variants of a target. It shouldn't be
// doing ABI-based builtin location for MIPS.
if (isMipsArch(TargetArch)) { if (isMipsArch(TargetArch)) {
StringRef ABISuffix = getMipsTargetABISuffix(TargetArch, Args); StringRef ABISuffix = getMipsTargetABISuffix(TargetArch, Args);
@ -1377,8 +1348,8 @@ static bool findTargetMultiarchSuffix(std::string &Suffix,
void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
llvm::Triple::ArchType TargetArch, const ArgList &Args, llvm::Triple::ArchType TargetArch, const ArgList &Args,
const std::string &LibDir, const std::string &LibDir, StringRef CandidateTriple,
StringRef CandidateTriple, bool NeedsMultiarchSuffix) { bool NeedsBiarchSuffix) {
// There are various different suffixes involving the triple we // There are various different suffixes involving the triple we
// check for. We also record what is necessary to walk from each back // check for. We also record what is necessary to walk from each back
// up to the lib directory. // up to the lib directory.
@ -1396,15 +1367,11 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
// triple. // triple.
"/i386-linux-gnu/gcc/" + CandidateTriple.str() "/i386-linux-gnu/gcc/" + CandidateTriple.str()
}; };
const std::string InstallSuffixes[] = { const std::string InstallSuffixes[] = { "/../../..", "/../../../..", "/../..",
"/../../..", "/../../../.." };
"/../../../..",
"/../..",
"/../../../.."
};
// Only look at the final, weird Ubuntu suffix for i386-linux-gnu. // Only look at the final, weird Ubuntu suffix for i386-linux-gnu.
const unsigned NumLibSuffixes = (llvm::array_lengthof(LibSuffixes) - const unsigned NumLibSuffixes =
(TargetArch != llvm::Triple::x86)); (llvm::array_lengthof(LibSuffixes) - (TargetArch != llvm::Triple::x86));
for (unsigned i = 0; i < NumLibSuffixes; ++i) { for (unsigned i = 0; i < NumLibSuffixes; ++i) {
StringRef LibSuffix = LibSuffixes[i]; StringRef LibSuffix = LibSuffixes[i];
llvm::error_code EC; llvm::error_code EC;
@ -1422,18 +1389,17 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
// in what would normally be GCCInstallPath and put the 64-bit // in what would normally be GCCInstallPath and put the 64-bit
// libs in a subdirectory named 64. The simple logic we follow is that // libs in a subdirectory named 64. The simple logic we follow is that
// *if* there is a subdirectory of the right name with crtbegin.o in it, // *if* there is a subdirectory of the right name with crtbegin.o in it,
// we use that. If not, and if not a multiarch triple, we look for // we use that. If not, and if not a biarch triple alias, we look for
// crtbegin.o without the subdirectory. // crtbegin.o without the subdirectory.
std::string MultiarchSuffix; std::string BiarchSuffix;
if (findTargetMultiarchSuffix(MultiarchSuffix, if (findTargetBiarchSuffix(BiarchSuffix, LI->path(), TargetArch, Args)) {
LI->path(), TargetArch, Args)) { GCCBiarchSuffix = BiarchSuffix;
GCCMultiarchSuffix = MultiarchSuffix;
} else { } else {
if (NeedsMultiarchSuffix || if (NeedsBiarchSuffix ||
!llvm::sys::fs::exists(LI->path() + "/crtbegin.o")) !llvm::sys::fs::exists(LI->path() + "/crtbegin.o"))
continue; continue;
GCCMultiarchSuffix.clear(); GCCBiarchSuffix.clear();
} }
Version = CandidateVersion; Version = CandidateVersion;
@ -2293,12 +2259,11 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
if (IsAndroid && isMipsR2Arch(Triple.getArch(), Args)) if (IsAndroid && isMipsR2Arch(Triple.getArch(), Args))
addPathIfExists(GCCInstallation.getInstallPath() + addPathIfExists(GCCInstallation.getInstallPath() +
GCCInstallation.getMultiarchSuffix() + GCCInstallation.getBiarchSuffix() + "/mips-r2",
"/mips-r2",
Paths); Paths);
else else
addPathIfExists((GCCInstallation.getInstallPath() + addPathIfExists((GCCInstallation.getInstallPath() +
GCCInstallation.getMultiarchSuffix()), GCCInstallation.getBiarchSuffix()),
Paths); Paths);
// If the GCC installation we found is inside of the sysroot, we want to // If the GCC installation we found is inside of the sysroot, we want to
@ -2334,7 +2299,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths); addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
addPathIfExists(SysRoot + "/usr/lib/../" + Multilib, Paths); addPathIfExists(SysRoot + "/usr/lib/../" + Multilib, Paths);
// Try walking via the GCC triple path in case of multiarch GCC // Try walking via the GCC triple path in case of biarch or multiarch GCC
// installations with strange symlinks. // installations with strange symlinks.
if (GCCInstallation.isValid()) if (GCCInstallation.isValid())
addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() + addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
@ -2344,7 +2309,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
if (GCCInstallation.isValid()) { if (GCCInstallation.isValid()) {
const std::string &LibPath = GCCInstallation.getParentLibPath(); const std::string &LibPath = GCCInstallation.getParentLibPath();
const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
if (!GCCInstallation.getMultiarchSuffix().empty()) if (!GCCInstallation.getBiarchSuffix().empty())
addPathIfExists(GCCInstallation.getInstallPath(), Paths); addPathIfExists(GCCInstallation.getInstallPath(), Paths);
if (StringRef(LibPath).startswith(SysRoot)) { if (StringRef(LibPath).startswith(SysRoot)) {
@ -2437,15 +2402,13 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// Sourcery CodeBench and modern FSF Mips toolchains put extern C // Sourcery CodeBench and modern FSF Mips toolchains put extern C
// system includes under three additional directories. // system includes under three additional directories.
if (GCCInstallation.isValid() && isMipsArch(getTriple().getArch())) { if (GCCInstallation.isValid() && isMipsArch(getTriple().getArch())) {
addExternCSystemIncludeIfExists(DriverArgs, CC1Args, addExternCSystemIncludeIfExists(
GCCInstallation.getInstallPath() + DriverArgs, CC1Args, GCCInstallation.getInstallPath() + "/include");
"/include");
addExternCSystemIncludeIfExists(DriverArgs, CC1Args, addExternCSystemIncludeIfExists(
GCCInstallation.getInstallPath() + DriverArgs, CC1Args,
"/../../../../" + GCCInstallation.getInstallPath() + "/../../../../" +
GCCInstallation.getTriple().str() + GCCInstallation.getTriple().str() + "/libc/usr/include");
"/libc/usr/include");
} }
// Implement generic Debian multiarch support. // Implement generic Debian multiarch support.
@ -2455,8 +2418,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// FIXME: These are older forms of multiarch. It's not clear that they're // FIXME: These are older forms of multiarch. It's not clear that they're
// in use in any released version of Debian, so we should consider // in use in any released version of Debian, so we should consider
// removing them. // removing them.
"/usr/include/i686-linux-gnu/64", "/usr/include/i686-linux-gnu/64", "/usr/include/i486-linux-gnu/64"
"/usr/include/i486-linux-gnu/64"
}; };
const StringRef X86MultiarchIncludeDirs[] = { const StringRef X86MultiarchIncludeDirs[] = {
"/usr/include/i386-linux-gnu", "/usr/include/i386-linux-gnu",
@ -2464,8 +2426,7 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// FIXME: These are older forms of multiarch. It's not clear that they're // FIXME: These are older forms of multiarch. It's not clear that they're
// in use in any released version of Debian, so we should consider // in use in any released version of Debian, so we should consider
// removing them. // removing them.
"/usr/include/x86_64-linux-gnu/32", "/usr/include/x86_64-linux-gnu/32", "/usr/include/i686-linux-gnu",
"/usr/include/i686-linux-gnu",
"/usr/include/i486-linux-gnu" "/usr/include/i486-linux-gnu"
}; };
const StringRef AArch64MultiarchIncludeDirs[] = { const StringRef AArch64MultiarchIncludeDirs[] = {
@ -2585,11 +2546,9 @@ void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
StringRef Version = GCCInstallation.getVersion().Text; StringRef Version = GCCInstallation.getVersion().Text;
StringRef TripleStr = GCCInstallation.getTriple().str(); StringRef TripleStr = GCCInstallation.getTriple().str();
if (addLibStdCXXIncludePaths(LibDir.str() + "/../include", if (addLibStdCXXIncludePaths(
"/c++/" + Version.str(), LibDir.str() + "/../include", "/c++/" + Version.str(), TripleStr,
TripleStr, GCCInstallation.getBiarchSuffix(), DriverArgs, CC1Args))
GCCInstallation.getMultiarchSuffix(),
DriverArgs, CC1Args))
return; return;
const std::string IncludePathCandidates[] = { const std::string IncludePathCandidates[] = {
@ -2604,9 +2563,10 @@ void Linux::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
}; };
for (unsigned i = 0; i < llvm::array_lengthof(IncludePathCandidates); ++i) { for (unsigned i = 0; i < llvm::array_lengthof(IncludePathCandidates); ++i) {
if (addLibStdCXXIncludePaths(IncludePathCandidates[i], (TripleStr + if (addLibStdCXXIncludePaths(
GCCInstallation.getMultiarchSuffix()), IncludePathCandidates[i],
DriverArgs, CC1Args)) (TripleStr + GCCInstallation.getBiarchSuffix()), DriverArgs,
CC1Args))
break; break;
} }
} }

View File

@ -74,7 +74,7 @@ protected:
// FIXME: These might be better as path objects. // FIXME: These might be better as path objects.
std::string GCCInstallPath; std::string GCCInstallPath;
std::string GCCMultiarchSuffix; std::string GCCBiarchSuffix;
std::string GCCParentLibPath; std::string GCCParentLibPath;
GCCVersion Version; GCCVersion Version;
@ -92,8 +92,9 @@ protected:
/// \brief Get the detected GCC installation path. /// \brief Get the detected GCC installation path.
StringRef getInstallPath() const { return GCCInstallPath; } StringRef getInstallPath() const { return GCCInstallPath; }
/// \brief Get the detected GCC installation path suffix for multiarch GCCs. /// \brief Get the detected GCC installation path suffix for the bi-arch
StringRef getMultiarchSuffix() const { return GCCMultiarchSuffix; } /// target variant.
StringRef getBiarchSuffix() const { return GCCBiarchSuffix; }
/// \brief Get the detected GCC parent lib path. /// \brief Get the detected GCC parent lib path.
StringRef getParentLibPath() const { return GCCParentLibPath; } StringRef getParentLibPath() const { return GCCParentLibPath; }
@ -102,19 +103,19 @@ protected:
const GCCVersion &getVersion() const { return Version; } const GCCVersion &getVersion() const { return Version; }
private: private:
static void CollectLibDirsAndTriples( static void
const llvm::Triple &TargetTriple, CollectLibDirsAndTriples(const llvm::Triple &TargetTriple,
const llvm::Triple &MultiarchTriple, const llvm::Triple &BiarchTriple,
SmallVectorImpl<StringRef> &LibDirs, SmallVectorImpl<StringRef> &LibDirs,
SmallVectorImpl<StringRef> &TripleAliases, SmallVectorImpl<StringRef> &TripleAliases,
SmallVectorImpl<StringRef> &MultiarchLibDirs, SmallVectorImpl<StringRef> &BiarchLibDirs,
SmallVectorImpl<StringRef> &MultiarchTripleAliases); SmallVectorImpl<StringRef> &BiarchTripleAliases);
void ScanLibDirForGCCTriple(llvm::Triple::ArchType TargetArch, void ScanLibDirForGCCTriple(llvm::Triple::ArchType TargetArch,
const llvm::opt::ArgList &Args, const llvm::opt::ArgList &Args,
const std::string &LibDir, const std::string &LibDir,
StringRef CandidateTriple, StringRef CandidateTriple,
bool NeedsMultiarchSuffix = false); bool NeedsBiarchSuffix = false);
}; };
GCCInstallationDetector GCCInstallation; GCCInstallationDetector GCCInstallation;