Skip to content

[CMake][Release] Use llvm-bitcode-strip on Darwin for build with -ffat-lto-objects#200764

Merged
c-rhodes merged 1 commit into
llvm:mainfrom
c-rhodes:gh-issue-#176398
Jun 2, 2026
Merged

[CMake][Release] Use llvm-bitcode-strip on Darwin for build with -ffat-lto-objects#200764
c-rhodes merged 1 commit into
llvm:mainfrom
c-rhodes:gh-issue-#176398

Conversation

@c-rhodes

@c-rhodes c-rhodes commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Building with --fat-lto-objects was added in #140381 (cff9ae7). On macOS the tests are failing when building release binaries with many "The file was not recognized as a valid object file" errors, e.g.:

2026-01-16T12:54:26.0928880Z
/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/bin/llvm-strip:
error:
'/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/lib/libLLVMAArch64AsmParser.a(AArch64AsmParser.cpp.o)':
The file was not recognized as a valid object file

It's assuming bitcode is embedded in section .llvm.lto (llvm/lib/Object/ObjectFile.cpp:80) but on MachO it's in __LLVM,__bitcode (llvm/lib/Object/MachOObjectFile.cpp:2184)

llvm-bitcode-strip is a driver for the MachO bitcode_strip utility which handles this. Use this instead.

Fixes #176398.

Assisted-by: codex

…t-lto-objects

Building with --fat-lto-objects was added in llvm#140381 (cff9ae7). On
macOS the tests are failing when building release binaries with many
"The file was not recognized as a valid object file" errors, e.g.:

  2026-01-16T12:54:26.0928880Z
  /Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/bin/llvm-strip:
  error:
  '/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/lib/libLLVMAArch64AsmParser.a(AArch64AsmParser.cpp.o)':
  The file was not recognized as a valid object file

It's assuming bitcode is embedded in section .llvm.lto
(llvm/lib/Object/ObjectFile.cpp:80) but on MachO it's in
__LLVM,__bitcode (llvm/lib/Object/MachOObjectFile.cpp:2184)

llvm-bitcode-strip is a driver for the MachO bitcode_strip utility which
handles this. Use this instead.

Fixes llvm#176398.

Assisted-by: codex
@c-rhodes c-rhodes marked this pull request as ready for review June 1, 2026 10:30
@llvmorg-github-actions llvmorg-github-actions Bot added the clang Clang issues not falling into any other category label Jun 1, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Cullen Rhodes (c-rhodes)

Changes

Building with --fat-lto-objects was added in #140381 (cff9ae7). On macOS the tests are failing when building release binaries with many "The file was not recognized as a valid object file" errors, e.g.:

2026-01-16T12:54:26.0928880Z
/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/bin/llvm-strip:
error:
'/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/lib/libLLVMAArch64AsmParser.a(AArch64AsmParser.cpp.o)':
The file was not recognized as a valid object file

It's assuming bitcode is embedded in section .llvm.lto (llvm/lib/Object/ObjectFile.cpp:80) but on MachO it's in __LLVM,__bitcode (llvm/lib/Object/MachOObjectFile.cpp:2184)

llvm-bitcode-strip is a driver for the MachO bitcode_strip utility which handles this. Use this instead.

Fixes #176398.

Assisted-by: codex


Full diff: https://github.com/llvm/llvm-project/pull/200764.diff

1 Files Affected:

  • (modified) clang/cmake/caches/release_cpack_pre_build_strip_lto.cmake (+10-1)
diff --git a/clang/cmake/caches/release_cpack_pre_build_strip_lto.cmake b/clang/cmake/caches/release_cpack_pre_build_strip_lto.cmake
index 743b64fe00f58..e7d8830515439 100644
--- a/clang/cmake/caches/release_cpack_pre_build_strip_lto.cmake
+++ b/clang/cmake/caches/release_cpack_pre_build_strip_lto.cmake
@@ -1,5 +1,14 @@
 file(GLOB files ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/lib/*.a)
 
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+  set(strip_command
+    ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/bin/llvm-bitcode-strip)
+  set(strip_args -r)
+else()
+  set(strip_command ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/bin/llvm-strip)
+  set(strip_args --no-strip-all -R .llvm.lto)
+endif()
+
 foreach(file ${files})
-  execute_process(COMMAND ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/bin/llvm-strip --no-strip-all -R .llvm.lto ${file})
+  execute_process(COMMAND ${strip_command} ${strip_args} ${file} -o ${file})
 endforeach()

@tru

tru commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

long term it would be neat if llvm-strip could handle both of these instead of having to select the "correct" version of the strip command?

@c-rhodes

c-rhodes commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

long term it would be neat if llvm-strip could handle both of these instead of having to select the "correct" version of the strip command?

I wondered the same and found it came up in https://discourse.llvm.org/t/rfc-contributing-bitcode-strip/56245 but apparently the argument semantics are different enough to warrant independent tools

@boomanaiden154 boomanaiden154 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although a bit weird that llvm-strip can't handle this case. Not exactly sure what is supposed to work and what is not, so even if this is just a workaround, this seems reasonable enough to me.

@c-rhodes c-rhodes merged commit b8e768f into llvm:main Jun 2, 2026
14 checks passed
dyung pushed a commit that referenced this pull request Jun 4, 2026
…t-lto-objects (#200764)

Building with --fat-lto-objects was added in #140381 (cff9ae7). On
macOS the tests are failing when building release binaries with many
"The file was not recognized as a valid object file" errors, e.g.:

  2026-01-16T12:54:26.0928880Z

/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/bin/llvm-strip:
  error:

'/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/lib/libLLVMAArch64AsmParser.a(AArch64AsmParser.cpp.o)':
  The file was not recognized as a valid object file

It's assuming bitcode is embedded in section .llvm.lto
(llvm/lib/Object/ObjectFile.cpp:80) but on MachO it's in
__LLVM,__bitcode (llvm/lib/Object/MachOObjectFile.cpp:2184)

llvm-bitcode-strip is a driver for the MachO bitcode_strip utility which
handles this. Use this instead.

Fixes #176398.

Assisted-by: codex
(cherry picked from commit b8e768f)
yingopq pushed a commit to yingopq/llvm-project that referenced this pull request Jun 5, 2026
…t-lto-objects (llvm#200764)

Building with --fat-lto-objects was added in llvm#140381 (cff9ae7). On
macOS the tests are failing when building release binaries with many
"The file was not recognized as a valid object file" errors, e.g.:

  2026-01-16T12:54:26.0928880Z

/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/bin/llvm-strip:
  error:

'/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/lib/libLLVMAArch64AsmParser.a(AArch64AsmParser.cpp.o)':
  The file was not recognized as a valid object file

It's assuming bitcode is embedded in section .llvm.lto
(llvm/lib/Object/ObjectFile.cpp:80) but on MachO it's in
__LLVM,__bitcode (llvm/lib/Object/MachOObjectFile.cpp:2184)

llvm-bitcode-strip is a driver for the MachO bitcode_strip utility which
handles this. Use this instead.

Fixes llvm#176398.

Assisted-by: codex
daunabomba pushed a commit to daunabomba/llvm-project that referenced this pull request Jun 17, 2026
…t-lto-objects (llvm#200764)

Building with --fat-lto-objects was added in llvm#140381 (cff9ae7). On
macOS the tests are failing when building release binaries with many
"The file was not recognized as a valid object file" errors, e.g.:

  2026-01-16T12:54:26.0928880Z

/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/bin/llvm-strip:
  error:

'/Users/runner/work/llvm-project/llvm-project/build/tools/clang/stage2-instrumented-bins/tools/clang/stage2-bins/_CPack_Packages/Darwin/TXZ/LLVM-22.1.0-rc1-macOS-ARM64/lib/libLLVMAArch64AsmParser.a(AArch64AsmParser.cpp.o)':
  The file was not recognized as a valid object file

It's assuming bitcode is embedded in section .llvm.lto
(llvm/lib/Object/ObjectFile.cpp:80) but on MachO it's in
__LLVM,__bitcode (llvm/lib/Object/MachOObjectFile.cpp:2184)

llvm-bitcode-strip is a driver for the MachO bitcode_strip utility which
handles this. Use this instead.

Fixes llvm#176398.

Assisted-by: codex
(cherry picked from commit b8e768f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS tests are failing when building release binaries

4 participants