llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver Author: Daniel Chen (DanielCChen) <details> <summary>Changes</summary> In the wake of discussion in PR #<!-- -->131200 and internal discussion after, we will add support for `LLVM_ENABLE_PER_TARGET_RUNTIME=ON` for AIX instead of disable it. I already reverted the change in PR #<!-- -->131200. The default value of the option is still OFF on AIX. --- Full diff: https://github.com/llvm/llvm-project/pull/132821.diff 9 Files Affected: - (modified) clang/include/clang/Driver/ToolChain.h (+3) - (modified) clang/lib/Driver/ToolChain.cpp (+22-12) - (added) clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a () - (added) clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a () - (added) clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc-ibm-aix/libclang_rt.builtins.a () - (added) clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc64-ibm-aix/libclang_rt.builtins.a () - (modified) clang/test/Driver/aix-ld.c (+52) - (modified) clang/test/Driver/aix-print-runtime-dir.c (+10) - (modified) clang/test/Driver/aix-rtlib.c (+8) ``````````diff diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 90004c64a694a..f2e8fa306e3a5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -519,6 +519,9 @@ class ToolChain { StringRef Component, FileType Type = ToolChain::FT_Static) const; + // Returns Triple without the OSs version. + llvm::Triple getTripleWithoutOSVersion() const; + // Returns the target specific runtime path if it exists. std::optional<std::string> getRuntimePath() const; diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 5f75d004eede0..8a922b283daf5 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -779,8 +779,6 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, if (Path.empty()) Path = P; } - if (getTriple().isOSAIX()) - Path.clear(); // Check the filename for the old layout if the new one does not exist. CRTBasename = @@ -846,6 +844,16 @@ ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) const { return std::string(P); } +llvm::Triple ToolChain::getTripleWithoutOSVersion() const { + return (Triple.hasEnvironment() + ? llvm::Triple(Triple.getArchName(), Triple.getVendorName(), + llvm::Triple::getOSTypeName(Triple.getOS()), + llvm::Triple::getEnvironmentTypeName( + Triple.getEnvironment())) + : llvm::Triple(Triple.getArchName(), Triple.getVendorName(), + llvm::Triple::getOSTypeName(Triple.getOS()))); +} + std::optional<std::string> ToolChain::getTargetSubDirPath(StringRef BaseDir) const { auto getPathForTriple = @@ -864,14 +872,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const { if (T.isOSzOS() && (!T.getOSVersion().empty() || !T.getEnvironmentVersion().empty())) { // Build the triple without version information - const llvm::Triple &TripleWithoutVersion = - (T.hasEnvironment() - ? llvm::Triple( - T.getArchName(), T.getVendorName(), - llvm::Triple::getOSTypeName(T.getOS()), - llvm::Triple::getEnvironmentTypeName(T.getEnvironment())) - : llvm::Triple(T.getArchName(), T.getVendorName(), - llvm::Triple::getOSTypeName(T.getOS()))); + const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion(); if (auto Path = getPathForTriple(TripleWithoutVersion)) return *Path; } @@ -909,9 +910,18 @@ std::optional<std::string> ToolChain::getRuntimePath() const { llvm::sys::path::append(P, "lib"); if (auto Ret = getTargetSubDirPath(P)) return Ret; - // Darwin and AIX does not use per-target runtime directory. - if (Triple.isOSDarwin() || Triple.isOSAIX()) + // Darwin does not use per-target runtime directory. + if (Triple.isOSDarwin()) + return {}; + + // For AIX, get the triple without the OS version. + if (Triple.isOSAIX()) { + const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion(); + llvm::sys::path::append(P, TripleWithoutVersion.str()); + if (getVFS().exists(P)) + return std::string(P); return {}; + } llvm::sys::path::append(P, Triple.str()); return std::string(P); } diff --git a/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a b/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a b/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc-ibm-aix/libclang_rt.builtins.a b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc-ibm-aix/libclang_rt.builtins.a new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc64-ibm-aix/libclang_rt.builtins.a b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc64-ibm-aix/libclang_rt.builtins.a new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c index 7e0f2bf91e06e..1dae61d91c4e3 100644 --- a/clang/test/Driver/aix-ld.c +++ b/clang/test/Driver/aix-ld.c @@ -1070,6 +1070,58 @@ // CHECK-FOPENMP-GOMP: "-lgomp" // CHECK-FOPENMP: "-lc" +// Check powerpc-ibm-aix7.1.0.0, 32-bit per_target_runtime_dir. +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --target=powerpc-ibm-aix7.1.0.0 \ +// RUN: --sysroot %S/Inputs/aix_ppc_tree \ +// RUN: --unwindlib=libunwind \ +// RUN: | FileCheck --check-prefix=CHECK-LD32-PER-TARGET %s +// CHECK-LD32-PER-TARGET-NOT: warning: +// CHECK-LD32-PER-TARGET: "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0" +// CHECK-LD32-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-LD32-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-LD32-PER-TARGET: "{{.*}}ld{{(.exe)?}}" +// CHECK-LD32-PER-TARGET-NOT: "-bnso" +// CHECK-LD32-PER-TARGET: "-b32" +// CHECK-LD32-PER-TARGET: "-bpT:0x10000000" "-bpD:0x20000000" +// CHECK-LD32-PER-TARGET: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o" +// CHECK-LD32-PER-TARGET: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o" +// CHECK-LD32-PER-TARGET-NOT: "-lc++" +// CHECK-LD32-PER-TARGET-NOT: "-lc++abi" +// CHECK-LD32-PER-TARGET: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc-ibm-aix{{/|\\\\}}libclang_rt.builtins.a" +// CHECK-LD32-PER-TARGET-NOT: "--as-needed" +// CHECK-LD32-PER-TARGET: "-lunwind" +// CHECK-LD32-PER-TARGET-NOT: "--no-as-needed" +// CHECK-LD32-PER-TARGET-NOT: "-lm" +// CHECK-LD32-PER-TARGET: "-lc" + +// Check powerpc64-ibm-aix7.1.0.0, 64-bit. +// RUN: %clang %s -### 2>&1 \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: --target=powerpc64-ibm-aix7.1.0.0 \ +// RUN: --sysroot %S/Inputs/aix_ppc_tree \ +// RUN: --unwindlib=libunwind \ +// RUN: | FileCheck --check-prefix=CHECK-LD64-PER-TARGET %s +// CHECK-LD64-PER-TARGET-NOT: warning: +// CHECK-LD64-PER-TARGET: "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0" +// CHECK-LD64-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-LD64-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-LD64-PER-TARGET: "{{.*}}ld{{(.exe)?}}" +// CHECK-LD64-PER-TARGET-NOT: "-bnso" +// CHECK-LD64-PER-TARGET: "-b64" +// CHECK-LD64-PER-TARGET: "-bpT:0x100000000" "-bpD:0x110000000" +// CHECK-LD64-PER-TARGET: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o" +// CHECK-LD64-PER-TARGET: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o" +// CHECK-LD64-PER-TARGET-NOT: "-lc++" +// CHECK-LD64-PER-TARGET-NOT: "-lc++abi" +// CHECK-LD64-PER-TARGET: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc64-ibm-aix{{/|\\\\}}libclang_rt.builtins.a" +// CHECK-LD64-PER-TARGET-NOT: "--as-needed" +// CHECK-LD64-PER-TARGET: "-lunwind" +// CHECK-LD64-PER-TARGET-NOT: "--no-as-needed" +// CHECK-LD64-PER-TARGET-NOT: "-lm" +// CHECK-LD64-PER-TARGET: "-lc" + // Check powerpc-ibm-aix7.1.0.0, 32-bit. -fopenmp=libfoo results an error. // RUN: not %clang %s 2>&1 -### \ // RUN: --target=powerpc-ibm-aix7.1.0.0 \ diff --git a/clang/test/Driver/aix-print-runtime-dir.c b/clang/test/Driver/aix-print-runtime-dir.c index 0d68ad6fee005..ffa4d15c21208 100644 --- a/clang/test/Driver/aix-print-runtime-dir.c +++ b/clang/test/Driver/aix-print-runtime-dir.c @@ -8,4 +8,14 @@ // RUN: -resource-dir=%S/Inputs/resource_dir \ // RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s +// RUN: %clang -print-runtime-dir --target=powerpc-ibm-aix \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir\ +// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR32-PER-TARGET %s + +// RUN: %clang -print-runtime-dir --target=powerpc64-ibm-aix \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir\ +// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR64-PER-TARGET %s + // PRINT-RUNTIME-DIR: lib{{/|\\}}aix{{$}} +// PRINT-RUNTIME-DIR32-PER-TARGET: lib{{/|\\}}powerpc-ibm-aix{{$}} +// PRINT-RUNTIME-DIR64-PER-TARGET: lib{{/|\\}}powerpc64-ibm-aix{{$}} diff --git a/clang/test/Driver/aix-rtlib.c b/clang/test/Driver/aix-rtlib.c index e0466b166bb78..82ab857984af1 100644 --- a/clang/test/Driver/aix-rtlib.c +++ b/clang/test/Driver/aix-rtlib.c @@ -5,6 +5,14 @@ // RUN: %clang --target=powerpc64-ibm-aix -print-libgcc-file-name \ // RUN: -resource-dir=%S/Inputs/resource_dir \ // RUN: | FileCheck -check-prefix=CHECK64 %s +// RUN: %clang --target=powerpc-ibm-aix -print-libgcc-file-name \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck -check-prefix=CHECK32-PER-TARGET %s +// RUN: %clang --target=powerpc64-ibm-aix -print-libgcc-file-name \ +// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ +// RUN: | FileCheck -check-prefix=CHECK64-PER-TARGET %s // CHECK32: resource_dir{{/|\\}}lib{{/|\\}}aix{{/|\\}}libclang_rt.builtins-powerpc.a // CHECK64: resource_dir{{/|\\}}lib{{/|\\}}aix{{/|\\}}libclang_rt.builtins-powerpc64.a +// CHECK32-PER-TARGET: resource_dir_with_per_target_subdir{{/|\\}}lib{{/|\\}}powerpc-ibm-aix{{/|\\}}libclang_rt.builtins.a +// CHECK64-PER-TARGET: resource_dir_with_per_target_subdir{{/|\\}}lib{{/|\\}}powerpc64-ibm-aix{{/|\\}}libclang_rt.builtins.a `````````` </details> https://github.com/llvm/llvm-project/pull/132821 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits