ZSH Won't Run an M1 Command Line Tool Built in Xcode

I have a command line tool that zsh refuses to run when built for Apple Silicon or as a univerisal binary (the specific message is zsh: killed TOOL_NAME). I can only get it to run if I build it exclusively for Intel/Rosetta.

Running/debugging from within Xcode works fine for any architecture.

The tool is a very simple C/C++ unix command-line tool; it doesn't have any external dependencies beyond the C runtime and the C++ STL.

I suspect something in code signing is going awry, but I've tried various team and certificate combinations without any luck. I've also tried enabling/disabling the app sandbox, also without any luck. (The app is not for distribution so it doesn't really need to be code signed at all.)

Any suggestions?

Replies

The app is not for distribution so it doesn't really need to be code signed at all.

That’s not correct. On Apple silicon all code must be signed. If you don’t intend to distribute the code, it’s fine to use ad hoc signing (this is what you get in Xcode when you select the Sign to Run Locally option).

So, what does this report for your tool:

% codesign -d -vvv --entitlements :- /path/to/your/tool

Share and Enjoy

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

When signed with my development cert, codesign prints the following (with identifying information removed). When signed to run locally, it prints similarly appropriate information. In both cases an Intel-only build will run, but an Apple Silicon or Universal Binary build will not.

Executable=/path/to/executable
Identifier=executable
Format=Mach-O universal (x86_64 arm64)
CodeDirectory v=20400 size=1292 flags=0x0(none) hashes=30+7 location=embedded
Hash type=sha256 size=32
CandidateCDHash sha256=d8cfc80142a15236c9fb1c7082746b0f0308685b
CandidateCDHashFull sha256=d8cfc80142a15236c9fb1c7082746b0f0308685b33b47e362df97ebbb28b19f7
Hash choices=sha256
CMSDigest=d8cfc80142a15236c9fb1c7082746b0f0308685b33b47e362df97ebbb28b19f7
CMSDigestType=2
CDHash=d8cfc80142a15236c9fb1c7082746b0f0308685b
Signature size=4779
Authority=Apple Development: My Name (XXXXXXXXXX)
Authority=Apple Worldwide Developer Relations Certification Authority
Authority=Apple Root CA
Signed Time=Jan 11, 2022 at 2:15:25 PM
Info.plist=not bound
TeamIdentifier=XXXXXXXXXX
Sealed Resources=none
Internal requirements count=1 size=168
code-block

I tried building a simple Hello World program from the command line, and it works fine when building for Apple Silicon. So the problem is likely something in the Xcode build settings, but nothing looks unusual to me.

That’s definitely a weird set of symptoms.

I tried building a simple Hello World program from the command line, and it works fine when building for Apple Silicon.

Just to confirm, “works fine” means “you build it on machine A and it works there, then you move it to machine B and it works there too”, right?

When things fail it should generate a crash report. What does that look like? Please post it here, using the instructions from Posting a Crash Report.

Share and Enjoy

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

No, it won't even run on the machine it's built on. And it's not crashing--there's no exception or crash log. Zsh seems to be killing the process before it can even hit main (I can't even get it to print out the usage text).

When I have some free time I'm going to recreate the Xcode project from scratch--it's a few years old and has gone through various Xcode updates so maybe some wires got crossed somewhere. A few other projects I have seem to build and run properly, though they produce app bundles rather than a simple executable.

No, it won't even run on the machine it's built on.

Understood. The zsh: killed TOOL_NAME message you’re reporting indicates that the process died with a SIGKILL, which is commonly associated with a code signing error. That is, the process was created but the trusted execution killed it before it had a chance to run any code.

That scenario should generate a crash report. Run the Console utility and click Crash Reports in the side bar on the left. Do you see a recent crash report for your tool?

Share and Enjoy

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

I tried it a few more times and did manage to get a couple crash reports in the console. It's a bit erratic--it doesn't log a crash every time it's killed.

Anyway, from the crash log it's being killed due to the code signing, as expected: Exception Type: EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid)).

I tried it a few more times and did manage to get a couple crash reports in the console.

OK. Please post that here, using the instructions in Posting a Crash Report.

Share and Enjoy

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

Hello, I'm experiencing this same problem on M1 / Monterey: ZSH killed my simple command line tool which is a basic Swift Package so there's no Xcode project file or Code Signing involved. Btw, this same tool worked before I rebuilt & redeployed it, then it just stopped working.

Any help is welcome, here's the Crash Report:

{"app_name":"ae","timestamp":"2022-06-16 13:11:24.00 +0200","app_version":"","slice_uuid":"1e8b1239-2796-3704-a58b-343506260792","build_version":"","platform":0,"share_with_app_devs":1,"is_first_party":1,"bug_type":"309","os_version":"macOS 12.3.1 (21E258)","incident_id":"C1A590B8-70FA-4780-A849-B9F879CCDCE1","name":"ae"}
{
  "uptime" : 1100000,
  "procLaunch" : "2022-06-16 13:11:19.7482 +0200",
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro18,3",
  "procStartAbsTime" : 27067662201860,
  "coalitionID" : 167059,
  "osVersion" : {
    "train" : "macOS 12.3.1",
    "build" : "21E258",
    "releaseType" : "User"
  },
  "captureTime" : "2022-06-16 13:11:19.7548 +0200",
  "incident" : "C1A590B8-70FA-4780-A849-B9F879CCDCE1",
  "bug_type" : "309",
  "pid" : 86517,
  "procExitAbsTime" : 27067662347253,
  "translated" : false,
  "cpuType" : "ARM-64",
  "procName" : "ae",
  "procPath" : "\/usr\/local\/bin\/ae",
  "parentProc" : "zsh",
  "parentPid" : 85668,
  "coalitionName" : "com.apple.Terminal",
  "crashReporterKey" : "6A3F5130-25F6-E566-AB97-36204E3C3BF1",
  "responsiblePid" : 85664,
  "responsibleProc" : "Terminal",
  "wakeTime" : 10423,
  "sleepWakeUUID" : "1B323A9F-8A6B-4888-B901-AB8203ACCF5A",
  "sip" : "enabled",
  "vmRegionInfo" : "0x104300000 is in 0x104300000-0x10431c000;  bytes after start: 0  bytes before end: 114687\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  mapped file                 104300000-10431c000    [  112K] r-x\/r-x SM=COW  ...t_id=1b04b8bb\n      mapped file                 10431c000-104320000    [   16K] rw-\/rw- SM=COW  ...t_id=1b04b8bb",
  "isCorpse" : 1,
  "exception" : {"codes":"0x0000000000000032, 0x0000000104300000","rawCodes":[50,4365221888],"type":"EXC_BAD_ACCESS","signal":"SIGKILL (Code Signature Invalid)","subtype":"UNKNOWN_0x32 at 0x0000000104300000"},
  "termination" : {"namespace":"CODESIGNING","flags":0,"code":2},
  "vmregioninfo" : "0x104300000 is in 0x104300000-0x10431c000;  bytes after start: 0  bytes before end: 114687\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      UNUSED SPACE AT START\n--->  mapped file                 104300000-10431c000    [  112K] r-x\/r-x SM=COW  ...t_id=1b04b8bb\n      mapped file                 10431c000-104320000    [   16K] rw-\/rw- SM=COW  ...t_id=1b04b8bb",
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":99031,"task_for_pid":584},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "usedImages" : [
  {
    "size" : 0,
    "source" : "A",
    "base" : 0,
    "uuid" : "00000000-0000-0000-0000-000000000000"
  }
],
  "legacyInfo" : {
  "threadHighlighted" : 0
},
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "5fc94383418129005b4e9ae0",
      "factorPackIds" : {

      },
      "deploymentId" : 240000370
    },
    {
      "rolloutId" : "61af99aeda72d16a4beb7756",
      "factorPackIds" : {

      },
      "deploymentId" : 240000213
    }
  ],
  "experiments" : [

  ]
},
  "reportNotes" : [
  "_dyld_process_info_create failed with 6",
  "dyld_process_snapshot_get_shared_cache failed",
  "Failed to create CSSymbolicatorRef - corpse still valid ¯\\_(ツ)_\/¯"
]
}

ZSH killed my simple command line tool

To be clear, zsh didn’t kill your tool. The trusted execution system killed your tool and zsh is reporting that.

which is a basic Swift Package so there's no … Code Signing involved

Code signing is always involved, at least on Apple silicon, where macOS requires that code be at least ad hoc signed.

here's the Crash Report

Thanks.

In future, use a text attachment to post crash reports; that avoids clogging up the timeline. See my Posting a Crash Report post for details.

Looking in your crash report I see this:

Exception Type:        EXC_BAD_ACCESS (SIGKILL (Code Signature Invalid))

The lack of a backtrace suggests that the trusted execution system killed your process before it started running any code. To start, check that your code is signed at all. What does the following print?

% codesign -d -vvv /usr/local/bin/ae

Next, if your code is signed, check that you copied it to /usr/local/bin safely. See Updating Mac Software.

If neither of those pan out, work through the advice in Resolving Trusted Execution Problems

Share and Enjoy

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