smeenai updated this revision to Diff 555086. smeenai added a comment. Kick off pre-merge checks
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158476/new/ https://reviews.llvm.org/D158476 Files: clang/include/clang/Driver/ToolChain.h clang/lib/Driver/ToolChain.cpp clang/test/Driver/Inputs/basic_android_libcxx_tree/usr/lib/aarch64-unknown-linux-android21/libc++.so clang/test/Driver/Inputs/basic_android_libcxx_tree/usr/lib/aarch64-unknown-linux-android23/libc++.so clang/test/Driver/Inputs/basic_android_libcxx_tree/usr/lib/aarch64-unknown-linux-android29/libc++.so clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android21/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android23/libclang_rt.builtins.a clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-linux-android29/libclang_rt.builtins.a clang/test/Driver/android-installed-libcxx.cpp clang/test/Driver/linux-per-target-runtime-dir.c
Index: clang/test/Driver/linux-per-target-runtime-dir.c =================================================================== --- clang/test/Driver/linux-per-target-runtime-dir.c +++ clang/test/Driver/linux-per-target-runtime-dir.c @@ -17,12 +17,25 @@ // RUN: %clang --target=aarch64-unknown-linux-android21 -print-file-name=libc++.so 2>&1 \ // RUN: -ccc-install-dir %S/Inputs/basic_android_libcxx_tree/usr/bin \ // RUN: | FileCheck --check-prefix=CHECK-LIBCXX-ANDROID21 %s -// CHECK-LIBCXX-ANDROID21: ..{{/|\\}}lib{{/|\\}}aarch64-unknown-linux-android21{{/|\\}}libc++.so +// CHECK-LIBCXX-ANDROID21: ..{{/|\\}}lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libc++.so // RUN: %clang --target=aarch64-unknown-linux-android23 -print-file-name=libc++.so 2>&1 \ // RUN: -ccc-install-dir %S/Inputs/basic_android_libcxx_tree/usr/bin \ // RUN: | FileCheck --check-prefix=CHECK-LIBCXX-ANDROID23 %s -// CHECK-LIBCXX-ANDROID23: ..{{/|\\}}lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libc++.so +// CHECK-LIBCXX-ANDROID23: ..{{/|\\}}lib{{/|\\}}aarch64-unknown-linux-android23{{/|\\}}libc++.so + +// RUN: %clang --target=aarch64-unknown-linux-android26 -print-file-name=libc++.so 2>&1 \ +// RUN: -ccc-install-dir %S/Inputs/basic_android_libcxx_tree/usr/bin \ +// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-ANDROID23 %s + +// RUN: %clang --target=aarch64-unknown-linux-android29 -print-file-name=libc++.so 2>&1 \ +// RUN: -ccc-install-dir %S/Inputs/basic_android_libcxx_tree/usr/bin \ +// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-ANDROID29 %s +// CHECK-LIBCXX-ANDROID29: ..{{/|\\}}lib{{/|\\}}aarch64-unknown-linux-android29{{/|\\}}libc++.so + +// RUN: %clang --target=aarch64-unknown-linux-android31 -print-file-name=libc++.so 2>&1 \ +// RUN: -ccc-install-dir %S/Inputs/basic_android_libcxx_tree/usr/bin \ +// RUN: | FileCheck --check-prefix=CHECK-LIBCXX-ANDROID29 %s // RUN: %clang --target=aarch64-unknown-linux-android -print-file-name=libc++.so 2>&1 \ // RUN: -ccc-install-dir %S/Inputs/basic_android_libcxx_tree/usr/bin \ @@ -45,13 +58,29 @@ // RUN: --target=aarch64-unknown-linux-android21 \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID21 %s -// CHECK-FILE-NAME-ANDROID21: lib{{/|\\}}aarch64-unknown-linux-android21{{/|\\}}libclang_rt.builtins.a +// CHECK-FILE-NAME-ANDROID21: lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libclang_rt.builtins.a // RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \ // RUN: --target=aarch64-unknown-linux-android23 \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID23 %s -// CHECK-FILE-NAME-ANDROID23: lib{{/|\\}}aarch64-unknown-linux-android{{/|\\}}libclang_rt.builtins.a +// CHECK-FILE-NAME-ANDROID23: lib{{/|\\}}aarch64-unknown-linux-android23{{/|\\}}libclang_rt.builtins.a + +// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \ +// RUN: --target=aarch64-unknown-linux-android26 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID23 %s + +// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \ +// RUN: --target=aarch64-unknown-linux-android29 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID29 %s +// CHECK-FILE-NAME-ANDROID29: lib{{/|\\}}aarch64-unknown-linux-android29{{/|\\}}libclang_rt.builtins.a + +// RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \ +// RUN: --target=aarch64-unknown-linux-android31 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck --check-prefix=CHECK-FILE-NAME-ANDROID29 %s // RUN: %clang -rtlib=compiler-rt -print-file-name=libclang_rt.builtins.a 2>&1 \ // RUN: --target=aarch64-unknown-linux-android \ Index: clang/test/Driver/android-installed-libcxx.cpp =================================================================== --- clang/test/Driver/android-installed-libcxx.cpp +++ clang/test/Driver/android-installed-libcxx.cpp @@ -13,6 +13,7 @@ // RUN: mkdir -p %t2/include/c++/v1 // RUN: mkdir -p %t2/sysroot // RUN: mkdir -p %t2/include/aarch64-none-linux-android/c++/v1 +// RUN: mkdir -p %t2/include/aarch64-none-linux-android23/c++/v1 // RUN: %clang -target aarch64-none-linux-android -ccc-install-dir %/t2/bin \ // RUN: --sysroot=%t2/sysroot -stdlib=libc++ -fsyntax-only \ @@ -24,3 +25,14 @@ // ANDROID-DIR: "-internal-isystem" "[[DIR]][[SEP:/|\\\\]]..[[SEP]]include[[SEP]]aarch64-none-linux-android[[SEP]]c++[[SEP]]v1" // ANDROID-DIR-SAME: "-internal-isystem" "[[DIR]][[SEP]]..[[SEP]]include[[SEP]]c++[[SEP]]v1" + +// RUN: %clang -target aarch64-none-linux-android23 -ccc-install-dir %/t2/bin \ +// RUN: --sysroot=%t2/sysroot -stdlib=libc++ -fsyntax-only \ +// RUN: %s -### 2>&1 | FileCheck --check-prefix=ANDROID23-DIR -DDIR=%/t2/bin %s + +// RUN: %clang -target aarch64-none-linux-android28 -ccc-install-dir %/t2/bin \ +// RUN: --sysroot=%t2/sysroot -stdlib=libc++ -fsyntax-only \ +// RUN: %s -### 2>&1 | FileCheck --check-prefix=ANDROID23-DIR -DDIR=%/t2/bin %s + +// ANDROID23-DIR: "-internal-isystem" "[[DIR]][[SEP:/|\\\\]]..[[SEP]]include[[SEP]]aarch64-none-linux-android23[[SEP]]c++[[SEP]]v1" +// ANDROID23-DIR-SAME: "-internal-isystem" "[[DIR]][[SEP]]..[[SEP]]include[[SEP]]c++[[SEP]]v1" Index: clang/lib/Driver/ToolChain.cpp =================================================================== --- clang/lib/Driver/ToolChain.cpp +++ clang/lib/Driver/ToolChain.cpp @@ -677,6 +677,46 @@ return Args.MakeArgString(getCompilerRT(Args, Component, Type)); } +// Android target triples contain a target version. If we don't have libraries +// for the exact target version, we should fall back to the next newest version +// or a versionless path, if any. +std::optional<std::string> +ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) const { + llvm::Triple TripleWithoutLevel(getTriple()); + TripleWithoutLevel.setEnvironmentName("android"); // remove any version number + const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str(); + unsigned TripleVersion = getTriple().getEnvironmentVersion().getMajor(); + unsigned BestVersion = 0; + + SmallString<32> TripleDir; + std::error_code EC; + for (llvm::vfs::directory_iterator LI = getVFS().dir_begin(BaseDir, EC), LE; + !EC && LI != LE; LI = LI.increment(EC)) { + StringRef DirName = llvm::sys::path::filename(LI->path()); + StringRef DirNameSuffix = DirName; + if (DirNameSuffix.consume_front(TripleWithoutLevelStr)) { + if (DirNameSuffix.empty() && TripleDir.empty()) { + TripleDir = DirName; + } else { + unsigned Version; + if (!DirNameSuffix.getAsInteger(10, Version) && Version > BestVersion && + Version < TripleVersion) { + BestVersion = Version; + TripleDir = DirName; + } + } + } + } + + if (!TripleDir.empty()) { + SmallString<128> P(BaseDir); + llvm::sys::path::append(P, TripleDir); + return std::string(P); + } + + return {}; +} + std::optional<std::string> ToolChain::getTargetSubDirPath(StringRef BaseDir) const { auto getPathForTriple = @@ -713,15 +753,8 @@ return *Path; } - // Android targets may include an API level at the end. We still want to fall - // back on a path without the API level. - if (getTriple().isAndroid() && - getTriple().getEnvironmentName() != "android") { - llvm::Triple TripleWithoutLevel = getTriple(); - TripleWithoutLevel.setEnvironmentName("android"); - if (auto Path = getPathForTriple(TripleWithoutLevel)) - return *Path; - } + if (getTriple().isAndroid()) + return getFallbackAndroidTargetPath(BaseDir); return {}; } Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -182,6 +182,9 @@ EffectiveTriple = std::move(ET); } + std::optional<std::string> + getFallbackAndroidTargetPath(StringRef BaseDir) const; + mutable std::optional<CXXStdlibType> cxxStdlibType; mutable std::optional<RuntimeLibType> runtimeLibType; mutable std::optional<UnwindLibType> unwindLibType;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits