[clang] [llvm] Mac release fix (PR #163026)

Tom Stellard via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 15 11:05:50 PDT 2025


https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/163026

>From b2f00eb013f5174b1ab5199bb7cc4cab6d5ed059 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Sat, 11 Oct 2025 17:39:12 -0700
Subject: [PATCH 1/9] [Darwin][Driver] Prefer linking with toolchain's libc++
 instead of system

Fixes #77653
---
 clang/lib/Driver/ToolChains/Darwin.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index d2356ebdfa86c..7e2d62a6bfc94 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -667,6 +667,10 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   Args.addAllArgs(CmdArgs, {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
                             options::OPT_Z_Flag, options::OPT_u_Group});
 
+  // Add local file paths to ensure the toolchain's libc++ is used instead of
+  // the system's.
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
+
   // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
   // members of static archive libraries which implement Objective-C classes or
   // categories.

>From 91ccb95e699b47ceb93c873454685fe180a2f975 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Sat, 11 Oct 2025 17:40:31 -0700
Subject: [PATCH 2/9] XXX: testrelease builds which also hit this bug

---
 .github/workflows/release-binaries.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml
index 83969b5490685..955a31aff9c14 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -1,5 +1,5 @@
 name: Release Binaries
-
+# TEST
 on:
   workflow_dispatch:
     inputs:

>From a0bb37c324b6dcaff28aff35bf39e2ebbf879bb7 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Sat, 11 Oct 2025 21:17:27 -0700
Subject: [PATCH 3/9] Fix build failure

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 7e2d62a6bfc94..2c869d260211d 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -669,7 +669,7 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   // Add local file paths to ensure the toolchain's libc++ is used instead of
   // the system's.
-  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
+  getToolChain().AddFilePathLibArgs(Args, CmdArgs);
 
   // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
   // members of static archive libraries which implement Objective-C classes or

>From 19b27bb6a76188b58f4b1c8420bd04c7040a06e6 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 13 Oct 2025 16:57:08 -0700
Subject: [PATCH 4/9] XX: debug

---
 .github/workflows/release-binaries-all.yml | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/.github/workflows/release-binaries-all.yml b/.github/workflows/release-binaries-all.yml
index 0b52a08202f1a..7e408497d1819 100644
--- a/.github/workflows/release-binaries-all.yml
+++ b/.github/workflows/release-binaries-all.yml
@@ -88,9 +88,6 @@ jobs:
         # We use ubuntu-22.04 rather than the latest version to make the built
         # binaries more portable (eg functional aginast older glibc).
         runs-on:
-          - ubuntu-22.04
-          - ubuntu-22.04-arm
-          - macos-13
           - macos-14
 
     uses: ./.github/workflows/release-binaries.yml

>From ff8bd1fe008a0d05dd61147fcb7a5bed2335ba30 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 13 Oct 2025 17:01:57 -0700
Subject: [PATCH 5/9] Debug

---
 .github/workflows/release-binaries.yml | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml
index 955a31aff9c14..9884027af5dc7 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -239,7 +239,15 @@ jobs:
         ninja -v -C ${{ steps.setup-stage.outputs.build-prefix }}/build stage2-package
         release_dir=`find ${{ steps.setup-stage.outputs.build-prefix }}/build -iname 'stage2-bins'`
         mv $release_dir/${{ needs.prepare.outputs.release-binary-filename }} .
-    
+
+    - name: Debug
+      shell: bash
+      if: always()
+      run: |
+        echo "int main(int argc, char** argv) { return 0; }" >> test.cpp
+        ${{ steps.setup-stage.outputs.build-prefix }}/build/bin/clang++ -### -fuse-ld=lld -stdlib=libc++ -Wl,--verbose test.cpp
+        ls -ltr  ${{ steps.setup-stage.outputs.build-prefix }}/build/lib/*
+
     - uses: actions/upload-artifact at ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
       with:
         name: ${{ runner.os }}-${{ runner.arch }}-release-binary

>From 6d91fcd5583670d5045985976903854fdd68bb88 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Tue, 14 Oct 2025 11:43:08 -0700
Subject: [PATCH 6/9] Fix/Debug

---
 clang/lib/Driver/ToolChain.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 3d5cac62afe01..ac5ec0d1bd9e8 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -954,10 +954,12 @@ llvm::Triple ToolChain::getTripleWithoutOSVersion() const {
 
 std::optional<std::string>
 ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
+  dbgs() << "getTargetSubDirPath: " << BaseDir << "\n";
   auto getPathForTriple =
       [&](const llvm::Triple &Triple) -> std::optional<std::string> {
     SmallString<128> P(BaseDir);
     llvm::sys::path::append(P, Triple.str());
+  dbgs() << "getTargetSubDirPath: " << P << "\n";
     if (getVFS().exists(P))
       return std::string(P);
     return {};
@@ -1032,7 +1034,13 @@ std::optional<std::string> ToolChain::getRuntimePath() const {
 
 std::optional<std::string> ToolChain::getStdlibPath() const {
   SmallString<128> P(D.Dir);
+  if (Triple.isOSDarwin())
+  dbgs() << "getStdlibPath(): " << P << "\n";
   llvm::sys::path::append(P, "..", "lib");
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+    return std::string(P);
+  dbgs() << "getStdlibPath(): " << P << "\n";
   return getTargetSubDirPath(P);
 }
 
@@ -1551,9 +1559,11 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
 
 void ToolChain::AddFilePathLibArgs(const ArgList &Args,
                                    ArgStringList &CmdArgs) const {
-  for (const auto &LibPath : getFilePaths())
+  for (const auto &LibPath : getFilePaths()) {
+	  llvm::dbgs() << "LibPath: " << LibPath << "\n";
     if(LibPath.length() > 0)
       CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
+  }
 }
 
 void ToolChain::AddCCKextLibArgs(const ArgList &Args,

>From fcbd4740b011b1ef7402201ea20ae726f8cf71ee Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Tue, 14 Oct 2025 14:59:18 -0700
Subject: [PATCH 7/9] Update debug

---
 .github/workflows/release-binaries.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml
index 9884027af5dc7..25acfc9ebe52d 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -247,6 +247,7 @@ jobs:
         echo "int main(int argc, char** argv) { return 0; }" >> test.cpp
         ${{ steps.setup-stage.outputs.build-prefix }}/build/bin/clang++ -### -fuse-ld=lld -stdlib=libc++ -Wl,--verbose test.cpp
         ls -ltr  ${{ steps.setup-stage.outputs.build-prefix }}/build/lib/*
+        ${{ steps.setup-stage.outputs.build-prefix }}/build/bin/clang++  -fuse-ld=lld -stdlib=libc++ -Wl,--verbose test.cpp
 
     - uses: actions/upload-artifact at ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
       with:

>From 9b5d6cae0a45076034610ab6ac0198a38bcbda7a Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Tue, 14 Oct 2025 17:38:31 -0700
Subject: [PATCH 8/9] Disable IOS

---
 .github/workflows/release-binaries.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml
index 25acfc9ebe52d..df809000dad12 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -135,7 +135,7 @@ jobs:
         # add extra CMake args to disable them.
         # See https://github.com/llvm/llvm-project/issues/99767
         if [ "$RUNNER_OS" = "macOS" ]; then
-          target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF"
+          target_cmake_flags="$target_cmake_flags -DCOMPILER_RT_ENABLE_IOS=OFF -DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF -DBOOTSTRAP_BOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF"
           if [ "$RUNNER_ARCH" = "ARM64" ]; then
             arches=arm64
           else

>From 2cc4f3a7bc47d12722e07c8214def6df4c98e741 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Wed, 15 Oct 2025 11:04:53 -0700
Subject: [PATCH 9/9] Disable local runtimes

---
 clang/cmake/caches/Release.cmake | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index a523cc561b3f9..c0feecfda1cd4 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -44,6 +44,16 @@ set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
 set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
 set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")
 set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")
+
+if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
+  # Don't link against the just built runtimes due to:
+  # https://github.com/llvm/llvm-project/issues/77653
+  set(DEFAULT_LINK_LOCAL_RUNTIMES OFF)
+else()
+  set(DEFAULT_LINK_LOCAL_RUNTIMES ON)
+endif()
+set(LLVM_RELEASE_LINK_LOCAL_RUNTIMES ${DEFAULT_LINK_LOCAL_RUNTIMES} CACHE BOOL "")
+
 # Note we don't need to add install here, since it is one of the pre-defined
 # steps.
 set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
@@ -55,8 +65,12 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
 
 set(STAGE1_PROJECTS "clang")
 
+# Need to build compiler-rt in order to use PGO for later stages.
+set(STAGE1_RUNTIMES "compiler-rt")
 # Build all runtimes so we can statically link them into the stage2 compiler.
-set(STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind")
+if(DEFAULT_LINK_LOCAL_RUNTIMES)
+  list(APPEND STAGE1_RUNTIMES "libcxx;libcxxabi;libunwind")
+endif()
 
 if (LLVM_RELEASE_ENABLE_PGO)
   list(APPEND STAGE1_PROJECTS "lld")
@@ -118,11 +132,13 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}"
 if (LLVM_RELEASE_ENABLE_LTO)
   set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)
 endif()
-set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)
-set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)
-set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")
-if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
-  set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
+if(DEFAULT_LINK_LOCAL_RUNTIMES)
+  set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)
+  set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)
+  set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")
+  if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
+    set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
+  endif()
 endif()
 
 # Set flags for bolt



More information about the cfe-commits mailing list