Skip to content

Commit 783dc59

Browse files
[compiler-rt] Check codesign in path before using (llvm#99837)
Fixes an issue discovered with Nix where codesign is executed but Nix cannot use codesign without faults. Use `find_program` in CMake to ensure it is in `$PATH`. Can be tested on macOS and change your path in such a way that `codesign` isn't in it. Related: NixOS/nixpkgs#329058
1 parent 91ab10e commit 783dc59

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ function(add_compiler_rt_runtime name type)
389389
set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
390390
set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
391391
endif()
392-
if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
392+
find_program(CODESIGN codesign)
393+
if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*" AND CODESIGN)
393394
# Apple's linker signs the resulting dylib with an ad-hoc code signature in
394395
# most situations, except:
395396
# 1. Versions of ld64 prior to ld64-609 in Xcode 12 predate this behavior.
@@ -404,7 +405,7 @@ function(add_compiler_rt_runtime name type)
404405
# argument and looking for `invalid argument "linker-signed"` in its output.
405406
# FIXME: Remove this once all supported toolchains support `-o linker-signed`.
406407
execute_process(
407-
COMMAND sh -c "codesign -f -s - -o linker-signed this-does-not-exist 2>&1 | grep -q linker-signed"
408+
COMMAND sh -c "${CODESIGN} -f -s - -o linker-signed this-does-not-exist 2>&1 | grep -q linker-signed"
408409
RESULT_VARIABLE CODESIGN_SUPPORTS_LINKER_SIGNED
409410
)
410411

@@ -415,7 +416,7 @@ function(add_compiler_rt_runtime name type)
415416

416417
add_custom_command(TARGET ${libname}
417418
POST_BUILD
418-
COMMAND codesign --sign - ${EXTRA_CODESIGN_ARGUMENTS} $<TARGET_FILE:${libname}>
419+
COMMAND ${CODESIGN} --sign - ${EXTRA_CODESIGN_ARGUMENTS} $<TARGET_FILE:${libname}>
419420
WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR}
420421
COMMAND_EXPAND_LISTS
421422
)

0 commit comments

Comments
 (0)