[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang
Fahad Nayyar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 1 13:37:27 PDT 2023
fahadnayyar updated this revision to Diff 527591.
fahadnayyar added a comment.
Edits in comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148266/new/
https://reviews.llvm.org/D148266
Files:
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-header-search-libcxx.cpp
clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
Index: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
@@ -0,0 +1,28 @@
+// UNSUPPORTED: system-windows
+
+// Tests to check that we pass -L <install>/bin/../lib/ to the linker to prioritize the toolchain's libc++.dylib over system's libc++.tbd in all cases.
+
+// Check that even if stdlib is not passed, on apple platforms we pass the toolchain's dylib path to the linker.
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
+// RUN: --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// Check with -stdlib on both cases of toolchain installations (with and without libcxx).
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
+// RUN: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// RUN: %clang -### %s 2>&1 \
+// RUN: --target=x86_64-apple-darwin \
+// RUN: -stdlib=libc++ \
+// RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
+// RUN: | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
+
+// CHECK-TOOLCHAIN-LIBCXX-LINKING-1: "/usr/bin/ld"
+// CHECK-TOOLCHAIN-LIBCXX-LINKING-1: "-L" "[[TOOLCHAIN]]/usr/bin/../lib"
Index: clang/test/Driver/darwin-header-search-libcxx.cpp
===================================================================
--- clang/test/Driver/darwin-header-search-libcxx.cpp
+++ clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -92,7 +92,7 @@
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
-// Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the toolchain
+// Make sure that using -nostdinc, -nostdinc++ or -nostdlibinc will drop both the toolchain
// C++ include path and the sysroot one.
//
// RUN: %clang -### %s -fsyntax-only 2>&1 \
@@ -116,7 +116,7 @@
// RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
// RUN: -stdlib=platform \
// RUN: -nostdinc++ \
-// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr \
+// RUN: | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
// RUN: -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
// RUN: --check-prefix=CHECK-LIBCXX-NOSTDINCXX %s
// CHECK-LIBCXX-NOSTDINCXX: "-cc1"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -417,6 +417,17 @@
Args.AddAllArgs(CmdArgs, options::OPT_sub__library);
Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella);
+ // Pass -L <toolchain-install>/bin/../lib/ to linker to prioritize toolchain's
+ // libc++.dylib over the sysroot-provided one. This matches what we do for
+ // determining which libc++ headers to use.
+ llvm::SmallString<128> InstallBinPath =
+ llvm::StringRef(D.getInstalledDir()); // <install>/bin
+ llvm::SmallString<128> LibCxxDylibDirPath = InstallBinPath;
+ llvm::sys::path::append(LibCxxDylibDirPath, "..",
+ "lib"); // <install>/bin/../lib
+ CmdArgs.push_back("-L");
+ CmdArgs.push_back(C.getArgs().MakeArgString(LibCxxDylibDirPath));
+
// Give --sysroot= preference, over the Apple specific behavior to also use
// --isysroot as the syslibroot.
StringRef sysroot = C.getSysRoot();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148266.527591.patch
Type: text/x-patch
Size: 3936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230601/6a034f16/attachment.bin>
More information about the cfe-commits
mailing list