M1. Instrument Leaks error "Failed to gain authorization" (C program)

Hi. I'm trying to catch leaks in my C program and I get an error Failed to gain authorization in the Leaks tool on Macbook Pro 13 M1 2020.

Xcode 12.5.1

Likewise, when I run leaks in the terminal, I get a warning Process is not debuggable

I am using the gcc with -g to compile my C code.

Earlier, on Macbook Pro 13 Intel 2014, I have successfully used the tool for similar tasks. Is this possible on the M1?

Accepted Reply

I wonder if I can use leaks with programs that are not compiled in Xcode?

Xcode is not in a privileged position when it comes to building and signing code. Anything it does should be achievable by other development tools.

In the build logs, I see the steps: Sign <appname> Register execution policy exception for <appname>

This is a red herring. Xcode is registering its newly built code with the Execution Policy framework but that is a no-op on current systems [1].

After reading this thread, I'm guessing it's about code signing.

Yes, that’s most likely. Try this:

  1. Create an entitlements file with the com.apple.security.get-task-allow entitlement:

    % /usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" tmp.entitlements
    File Doesn't Exist, Will Create: tmp.entitlements
    
  2. Sign your code with that entitlements:

    % codesign -s - --entitlements tmp.entitlements -f /path/to/tool
    xxst: replacing existing signature
    

Does that help?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] That might change in the future, of course, but I’ve no info to share on that front.

  • Thank you so much! It worked. Hooray! :)

Add a Comment

Replies

This should work. As a diagnostic test, build a small test tool in Xcode and see if leaks works with that. That’ll tell you whether the problem is caused by your compiler or by your leaks setup.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • leaks really works with a project compiled in Xcode. In the build logs, I see the steps: Sign <appname> Register execution policy exception for <appname>

    After reading this thread, I'm guessing it's about code signing. As a result, I wonder if I can use leaks with programs that are not compiled in Xcode?

Add a Comment

I wonder if I can use leaks with programs that are not compiled in Xcode?

Xcode is not in a privileged position when it comes to building and signing code. Anything it does should be achievable by other development tools.

In the build logs, I see the steps: Sign <appname> Register execution policy exception for <appname>

This is a red herring. Xcode is registering its newly built code with the Execution Policy framework but that is a no-op on current systems [1].

After reading this thread, I'm guessing it's about code signing.

Yes, that’s most likely. Try this:

  1. Create an entitlements file with the com.apple.security.get-task-allow entitlement:

    % /usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" tmp.entitlements
    File Doesn't Exist, Will Create: tmp.entitlements
    
  2. Sign your code with that entitlements:

    % codesign -s - --entitlements tmp.entitlements -f /path/to/tool
    xxst: replacing existing signature
    

Does that help?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] That might change in the future, of course, but I’ve no info to share on that front.

  • Thank you so much! It worked. Hooray! :)

Add a Comment

Hello, I have the same problem and could not resolve it. What is "/path/to/tool" ?

I have already reinstall my mac, I use the Xcode version 15, I tried to delete and reinstall Xcode. Nothing is working.

I have already reinstall my mac, I use the Xcode version 15, I tried to delete and reinstall Xcode. Nothing is working.