Fix one of the (larger) FIXMEs where we were misusing the Driver's idea

of the target triple to stand in for the "host" triple.

Thanks to a great conversation with Richard Smith, I'm now much more
confident in how this is proceeding. In all of the places where we
currently reason about the "host" architecture or triple, what we really
want to reason about in the detected GCC installation architecture or
triple, and the ways in which that differs from the target. When we find
a GCC installation with a different triple from our target *but capable
of targeting our target* through an option such as '-m64', we want to
detect *that* case and change the paths within the GCC installation (and
libstdc++ installation) to reflect this difference.

This patch makes one function do this correctly. Subsequent commits will
hoist the logic used here into the GCCInstallation utility, and then
reuse it through the rest of the toolchains to fix the remaining places
where this is currently happening.

llvm-svn: 148852
This commit is contained in:
Chandler Carruth 2012-01-24 20:08:17 +00:00
parent 0d517a4278
commit 96bae7b1fd
1 changed files with 22 additions and 18 deletions

View File

@ -1897,8 +1897,7 @@ static std::string getMultiarchTriple(const llvm::Triple TargetTriple,
Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple) Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
: Generic_ELF(Host, Triple) { : Generic_ELF(Host, Triple) {
// FIXME: This is using the Driver's target triple to emulate the host triple! llvm::Triple::ArchType Arch = Triple.getArch();
llvm::Triple::ArchType Arch = getDriver().TargetTriple.getArch();
const std::string &SysRoot = getDriver().SysRoot; const std::string &SysRoot = getDriver().SysRoot;
// OpenSuse stores the linker with the compiler, add that to the search // OpenSuse stores the linker with the compiler, add that to the search
@ -1961,28 +1960,33 @@ Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
// possible permutations of these directories, and seeing which ones it added // possible permutations of these directories, and seeing which ones it added
// to the link paths. // to the link paths.
path_list &Paths = getFilePaths(); path_list &Paths = getFilePaths();
const bool Is32Bits = (getArch() == llvm::Triple::x86 ||
getArch() == llvm::Triple::mips ||
getArch() == llvm::Triple::mipsel ||
getArch() == llvm::Triple::ppc);
StringRef Suffix32; const bool Is32Bits = (Arch == llvm::Triple::x86 ||
StringRef Suffix64; Arch == llvm::Triple::mips ||
if (Arch == llvm::Triple::x86_64 || Arch == llvm::Triple::ppc64) { Arch == llvm::Triple::mipsel ||
Suffix32 = "/32"; Arch == llvm::Triple::ppc);
Suffix64 = "";
} else {
Suffix32 = "";
Suffix64 = "/64";
}
const std::string Suffix = Is32Bits ? Suffix32 : Suffix64;
const std::string Multilib = Is32Bits ? "lib32" : "lib64"; const std::string Multilib = Is32Bits ? "lib32" : "lib64";
const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot); const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot);
// Add the multilib suffixed paths where they are available. // Add the multilib suffixed paths where they are available.
bool SuffixedGCCInstallation = false;
if (GCCInstallation.isValid()) { if (GCCInstallation.isValid()) {
const std::string &LibPath = GCCInstallation.getParentLibPath(); StringRef Suffix32;
StringRef Suffix64;
const llvm::Triple &GCCTriple = GCCInstallation.getTriple(); const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
if (GCCTriple.getArch() == llvm::Triple::x86_64 ||
GCCTriple.getArch() == llvm::Triple::ppc64) {
Suffix32 = "/32";
Suffix64 = "";
} else {
Suffix32 = "";
Suffix64 = "/64";
}
const std::string Suffix = Is32Bits ? Suffix32 : Suffix64;
SuffixedGCCInstallation = !Suffix.empty();
const std::string &LibPath = GCCInstallation.getParentLibPath();
addPathIfExists(GCCInstallation.getInstallPath() + Suffix, Paths); addPathIfExists(GCCInstallation.getInstallPath() + Suffix, Paths);
addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib/../" + Multilib, addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib/../" + Multilib,
Paths); Paths);
@ -2004,7 +2008,7 @@ Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
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 (!Suffix.empty()) if (SuffixedGCCInstallation)
addPathIfExists(GCCInstallation.getInstallPath(), Paths); addPathIfExists(GCCInstallation.getInstallPath(), Paths);
addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib", Paths); addPathIfExists(LibPath + "/../" + GCCTriple.str() + "/lib", Paths);
addPathIfExists(LibPath, Paths); addPathIfExists(LibPath, Paths);