diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2105,8 +2105,10 @@ "x86_64-redhat-linux", "x86_64-suse-linux", "x86_64-manbo-linux-gnu", "x86_64-linux-gnu", "x86_64-slackware-linux", "x86_64-unknown-linux", - "x86_64-amazon-linux", "x86_64-linux-android"}; - static const char *const X32LibDirs[] = {"/libx32"}; + "x86_64-amazon-linux", "x86_64-linux-android", + "x86_64-linux-gnux32", "x86_64-unknown-linux-gnux32", + "x86_64-pc-linux-gnux32"}; + static const char *const X32LibDirs[] = {"/libx32", "/lib"}; static const char *const X86LibDirs[] = {"/lib32", "/lib"}; static const char *const X86Triples[] = { "i686-linux-gnu", "i686-pc-linux-gnu", "i386-redhat-linux6E", diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -87,6 +87,8 @@ case llvm::Triple::x86_64: if (IsAndroid) return "x86_64-linux-android"; + if (D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32")) + return "x86_64-linux-gnux32"; // We don't want this for x32, otherwise it will match x86_64 libs if (TargetEnvironment != llvm::Triple::GNUX32 && D.getVFS().exists(SysRoot + "/lib/x86_64-linux-gnu")) @@ -210,7 +212,10 @@ if (Triple.getArch() == llvm::Triple::x86_64 && Triple.getEnvironment() == llvm::Triple::GNUX32) - return "libx32"; + if (getDriver().getVFS().exists(SysRoot + "/lib/x86_64-linux-gnux32")) + return "lib32"; + else + return "libx32"; if (Triple.getArch() == llvm::Triple::riscv32) return "lib32";