Reputation: 101
I'm trying to run my application as root with Xcode on macOS, but I keep getting this bizarre error..
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
It's literally just a hello world. All I've added was a printf to the default Obj-C application, tried running it as root, aaaand it ends up on a ud2
instruction somehow. I've tried running Xcode with sudo
, editing the scheme, the combination of the two, and nothing works. It seems like just the thought of root shudders causes Xcode to insert some undefined instruction and crash.
edit: I'm on macOS Catalina 10.15.3 and Xcode 11.4, which I just downloaded yesterday, and this is the code I'm trying to run:
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) {
printf("Hello world\n");
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
}
return NSApplicationMain(argc, argv);
}
'My code' doesn't actually do anything. Removing the printf still causes the ud2
instruction crash, so the actual boilerplate developed by Apple doesn't work when run as root..
Upvotes: 2
Views: 1116
Reputation: 3847
I tried your project I downloaded from the GitHub link you provided and I can tell you I'm able to reproduce the bug you reported. Apparently, there is some incompatibility between libsystem_secinit
initialization code and when you turn on the entitlement App Sandbox
to YES
. If you turn it off, the crash goes away.
That reminds me of a bug described by Eskimo, who is a really helpful Apple engineer. He described also some incompatibilities between entitlements and libsystem_secinit
.
I would definitely recommend that you file a bug against this incompatibility with Feedback Assistant. At least, Apple's boiler plate code should work without crashing.
Upvotes: 5