Hiya folks! I'm David and I work on rust-analyzer, which is a language server for Rust similar to sourcekit-lsp. I'm using the new Instruments profiling tooling functionality in Xcode 16.3 and Xcode 26 (Processor Trace and CPU Counters) to profile our trait solver/type checker. While I've been able to use the new CPU Counters instrument successfully (the CPU Bottleneck feature is incredible! Props to the team!), I've been unable to make use of the Processor Trace instrument.
Instruments gives me the error message "Processor Trace cannot profile this process without proper permissions". The diagnostic suggests adding the com.apple.security-get-task-allow
entitlement to the code I'm trying to profile, or ensure that the build setting CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES
is enabled in Xcode.
Unfortunately, I don't know how I can add that entitlement to a self-signed binary produced by Cargo and I'm not using Xcode for somewhat obvious reasons.
Here's some information about my setup:
- Instruments Version 26.0 (17A5241e)
- I'm on an 14" MacBook Pro with M4 Pro. It's running macOS Version 26.0 Beta (25A5295e).
- I've enabled the "Processor Trace" feature in "Developer Tools" and even added the Instruments application to "Developer Tools".
- As a last-ditch effort before posting this, I disabled SIP on my Mac. Didn't help.
To reproduce my issue:
- Get Rust via https://rustup.rs/.
- Clone rust-analyzer:
git clone https://github.com/rust-lang/rust-analyzer.git
. cd rust-analyzer
- Run
cargo test --package hir-ty --lib --profile=dev-rel -- tests::incremental::add_struct_invalidates_trait_solve --exact --show-output
. By default, this command will output a bunch of build progress with the output containing something likeRunning unittests src/lib.rs (target/dev-rel/deps/hir_ty-f1dbf1b1d36575fe)
. - I take the absolute path of that
hir_ty-$SOME-HASH
string (in my case, it looks like/Users/dbarsky/Developer/rust-analyzer/target/dev-rel/deps/hir_ty-f1dbf1b1d36575fe
) and add it to the "Launch" profile. To the arguments section, I add--exact tests::incremental::add_struct_invalidates_trait_solve
. - I then try to record/profile via Instruments, but then I get the error message I shared above.
Below is output of codesign -dvvv
:
❯ codesign -dvvv target/dev-rel/deps/hir_ty-f1dbf1b1d36575fe
Executable=/Users/dbarsky/Developer/rust-analyzer/target/dev-rel/deps/hir_ty-f1dbf1b1d36575fe
Identifier=hir_ty-f1dbf1b1d36575fe
Format=Mach-O thin (arm64)
CodeDirectory v=20400 size=140368 flags=0x20002(adhoc,linker-signed) hashes=4383+0 location=embedded
Hash type=sha256 size=32
CandidateCDHash sha256=99e96c8622c7e20518617c66a7d4144dc0daef28
CandidateCDHashFull sha256=99e96c8622c7e20518617c66a7d4144dc0daef28f22fac013c28a784571ce1df
Hash choices=sha256
CMSDigest=99e96c8622c7e20518617c66a7d4144dc0daef28f22fac013c28a784571ce1df
CMSDigestType=2
CDHash=99e96c8622c7e20518617c66a7d4144dc0daef28
Signature=adhoc
Info.plist=not bound
TeamIdentifier=not set
Sealed Resources=none
Internal requirements=none
Any tips would be welcome! Additionally—and perhaps somewhat naively—I think I'd expect the Processor Trace instrument to just work with an adhoc-signed binary, as lldb
and friends largely do—I'm not sure that such a high barrier for CPU perf counters is warranted, especially on an adhoc-signed binary.
I’m not able to help you with third-party tools, so I’m going to base my response on how you would achieve this goal when using Clang directly from Terminal. I’m hoping that you can map this to your third-party tooling.
Also, I’m basing my response on the trivial test case described in Investigating Third-Party IDE Integration Problems. The final point of that is a built executable with no entitlements:
% codesign -d --entitlements - hello
Executable=/Users/quinn/Test/hello
%
To add the get-task-allow entitlement, first create a property list with the right values:
% plutil -create xml1 hello.entitlements
% plutil -insert 'com\.apple\.security\.get-task-allow' -bool true hello.entitlements
% cat hello.entitlements
…
<dict>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>
Note Entitlement files are XML property lists. While you can edit these as text, I generally recommend that you use our tools (plutil
and also PlistBuddy
; both have man pages) because it’s easy to mess things up if you edit them by hand.
Now re-sign the tool:
% codesign -s - -f --entitlements hello.entitlements hello
hello: replacing existing signature
Note that I’m using -s -
, which applies an ad-hoc signature, that is, a signature with no associated certificate [1]. This is standard practice when working with open source tooling [2], but it’s not appropriate for a product that you want to ship to a wide range of users [3].
I’m also using -f
, to tell codesign
to replace the existing signature [4].
Finally, dump its entitlements again, just to be sure:
% codesign -d --entitlements - hello
…
[Dict]
[Key] com.apple.security.get-task-allow
[Value]
[Bool] true
I think this’ll be sufficient to get you up’n’running, but let me know if you hit any snags.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Xcode calls this open Sign to Run Locally.
[2] Apple silicon code must be signed, so the linker automatically applies an ad-hoc signature. You can see this if you dump the hello
tool before re-signing it:
% clang -o hello hello.c
% codesign -d -vvv hello
…
CodeDirectory v=20400 size=382 flags=0x20002(adhoc,linker-signed) hashes=9+0 location=embedded
…
Note the adhoc
and linker-signed
flags.
If you’re going to re-sign the binary anyway, you can disable linker signing with the -no_adhoc_codesign
linker option.
[3] For general advice on how to sign and package Mac products, see:
[4] That is, the signature applied by the linker.