[compiler-rt] [compiler-rt] Don't rely on automatic codesigning with Apple's linker (PR #91681)
Julian Lettner via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 15:47:45 PDT 2024
================
@@ -387,35 +387,35 @@ function(add_compiler_rt_runtime name type)
set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
endif()
if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
- # Ad-hoc sign the dylibs when using Xcode versions older than 12.
- # Xcode 12 shipped with ld64-609.
- # FIXME: Remove whole conditional block once everything uses Xcode 12+.
- set(LD_V_OUTPUT)
+ # Apple's linker signs the resulting dylib with an ad-hoc code signature in
+ # most situations, except:
+ # 1. Versions of ld64 prior to ld64-609 in Xcode 12 predate this behavior.
+ # 2. Apple's new linker does not when building with `-darwin-target-variant`
+ # to support macOS Catalyst.
+ #
+ # Explicitly re-signing the dylib works around both of these issues. The
+ # signature is marked as `linker-signed` when that is supported so that it
+ # behaves as expected when processed by subsequent tooling.
+ #
+ # Detect whether `codesign` supports `-o linker-signed` by passing it as an
+ # argument and looking for `invalid argument "linker-signed"` in its output.
+ # FIXME: Remove this once all supported toolchains support `-o linker-signed`.
execute_process(
- COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
- RESULT_VARIABLE HAD_ERROR
- OUTPUT_VARIABLE LD_V_OUTPUT
+ COMMAND sh -c "codesign -f -s - -o linker-signed this-does-not-exist 2>&1 | grep -q linker-signed"
----------------
yln wrote:
This is clever! Hopefully not too brittle? Only other thing I can think of is `man codesign | grep linker-signed`, but I like that less because it uses a completely other command (`man`).
https://github.com/llvm/llvm-project/pull/91681
More information about the llvm-commits
mailing list