locked
Difficulty using the static registrar RRS feed

  • Question

  • User78604 posted

    Hi all,

    I'm working on a fairly huge app and we're struggling with a very long launch time. To give and idea, the NSApplication.Init() takes around 10 seconds to complete. I've briefly read about the Registrar and to my understanding the static registrar would reduce the launch time at the cost of increased build time (which I am ready to endure since I can set it only on release build).

    So I add --registrar:static in the Additional mmp arguments field of my project. The thing is, it fails to build. More precisely, I get this error in the Build Output: error MM5109: Native linking failed with error code 1. Check build log for details.

    Here are the errors I see just before this line: xcrun -sdk macosx clang -mmacosx-version-min=10.9 -arch i386 -framework AppKit -framework VideoToolbox -framework QuartzCore -framework OpenGL -framework AVFoundation -framework Foundation -framework GameKit -framework WebKit -framework CoreLocation -framework CoreMedia -framework CoreServices -framework CoreText -framework CoreVideo -framework CoreWLAN -framework ImageIO -framework AudioToolbox -framework EventKit -framework Quartz -framework IOBluetooth -framework AudioUnit -framework CoreData -framework MediaAccessibility -framework QTKit -framework AVKit -framework Accounts -framework SceneKit -framework GameController -framework ScriptingBridge -framework QuickLook -framework MapKit -framework MediaToolbox -framework OpenAL -framework Accelerate -framework StoreKit -framework Security -framework SystemConfiguration -framework SpriteKit -framework CoreMIDI -weak_framework CloudKit -weak_framework GameplayKit -weak_framework FinderSync -weak_framework LocalAuthentication -weak_framework NotificationCenter -u _xamarin_float_objc_msgSend -u _xamarin_float_objc_msgSendSuper -u _xamarin_IntPtr_objc_msgSend_IntPtr -u _xamarin_IntPtr_objc_msgSendSuper_IntPtr -u _xamarin_IntPtr_objc_msgSend_IntPtr_IntPtr_int -u _xamarin_IntPtr_objc_msgSendSuper_IntPtr_IntPtr_int -u _xamarin_IntPtr_objc_msgSend_IntPtr_int_int_int_int -u _xamarin_IntPtr_objc_msgSendSuper_IntPtr_int_int_int_int -u _xamarin_IntPtr_objc_msgSend_IntPtr_int_int_int -u _xamarin_IntPtr_objc_msgSendSuper_IntPtr_int_int_int -u _xamarin_localized_string_format -u _xamarin_localized_string_format_1 -u _xamarin_localized_string_format_2 -u _xamarin_localized_string_format_3 -u _xamarin_localized_string_format_4 -u _xamarin_localized_string_format_5 -u _xamarin_localized_string_format_6 -u _xamarin_localized_string_format_7 -u _xamarin_localized_string_format_8 -u _xamarin_localized_string_format_9 -u _xamarin_init_nsthread -u _xamarin_get_block_descriptor /Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.120/lib/libxammac.a -o /Users/Devolutions33/workspace/RDMOXv2/Mac/RemoteDesktopManager/Clients/RemoteDesktopManager/bin/Release/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager -D_THREAD_SAFE -I/Library/Frameworks/Mono.framework/Versions/4.6.2/lib/pkgconfig/../../include/mono-2.0 /Library/Frameworks/Mono.framework/Versions/4.6.2/lib/pkgconfig/../../lib/libmonosgen-2.0.a -framework AppKit -liconv -x objective-c++ -I/Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.120/include /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m -fno-caret-diagnostics -fno-diagnostics-fixit-info -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/main.m /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:8859:99: error: unknown type name 'QTCaptureOutput'; did you mean 'AVCaptureOutput'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureOutput.h:37:12: note: 'AVCaptureOutput' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:8859:121: error: unknown type name 'QTSampleBuffer' /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:8859:142: error: unknown type name 'QTCaptureConnection'; did you mean 'AVCaptureConnection'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureSession.h:674:12: note: 'AVCaptureConnection' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:8924:99: error: unknown type name 'QTCaptureOutput'; did you mean 'AVCaptureOutput'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureOutput.h:37:12: note: 'AVCaptureOutput' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:8924:128: error: unknown type name 'QTSampleBuffer' /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:8924:149: error: unknown type name 'QTCaptureConnection'; did you mean 'AVCaptureConnection'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureSession.h:674:12: note: 'AVCaptureConnection' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:8993:99: error: unknown type name 'QTCaptureFileOutput'; did you mean 'AVCaptureFileOutput'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureOutput.h:479:12: note: 'AVCaptureFileOutput' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:9080:99: error: unknown type name 'QTCaptureFileOutput'; did you mean 'AVCaptureFileOutput'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureOutput.h:479:12: note: 'AVCaptureFileOutput' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:9080:125: error: unknown type name 'QTSampleBuffer' /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:9080:146: error: unknown type name 'QTCaptureConnection'; did you mean 'AVCaptureConnection'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureSession.h:674:12: note: 'AVCaptureConnection' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:9145:99: error: unknown type name 'QTCaptureFileOutput'; did you mean 'AVCaptureFileOutput'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureOutput.h:479:12: note: 'AVCaptureFileOutput' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:9221:99: error: unknown type name 'QTCaptureFileOutput'; did you mean 'AVCaptureFileOutput'? /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureOutput.h:479:12: note: 'AVCaptureFileOutput' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:9312:104: error: unknown type name 'QTCaptureView' /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:38738:17: warning: method 'deviceBrowserView:selectionDidChange:' in protocol 'IKDeviceBrowserViewDelegate' not implemented [-Wprotocol] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Quartz.framework/Frameworks/ImageKit.framework/Headers/IKDeviceBrowserView.h:29:1: note: method 'deviceBrowserView:selectionDidChange:' declared here /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:39947:25: error: expected a type /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:39947:81: error: expected a type /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:39947:117: error: expected a type /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:39948:25: error: expected a type /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:39948:91: error: expected a type /private/var/folders/zy/wp416ggx2kb7x3nk4fz6vz6h0000gn/T/mmp.cache/wsqx6ho1.256/registrar.m:39948:127: error: expected a type fatal error: too many errors emitted, stopping now [-ferror-limit=]

    I investigated a bit, but I'm a bit dumbfounded with this. I did look into the MacOSX10.12.sdk and the header files for the QTKit framework are indeed not there (I suppose it is deprecated). But regardless, I don't use it in my project and therefor, do not care. Is this an issue between my version of Xamarin.Mac (version 2.10.0.120) and the MacOSX 10.12 sdk. If so why isn't it an issue with the dynamic registrar (I was able to create an instance of QTCaptureConnection with no issue, just as a test)?

    I am using the Classic API by the way, not the unified. Just tell me if it's the issue so I can put this behind me.

    Thursday, January 5, 2017 9:39 PM

Answers

  • User35201 posted

    So Apple did something less that kosher and removed the QTKit headers, as you noticed. However, they did not remove the symbols from the libraries (as nm /System/Library/Frameworks/QTKit.framework/QTKit can show).

    The dynamic registrar works just fine, since it uses the objective-c equivalents of reflection to look up the symbols directly. However, since the header is gone, we can't register the types statically.

    This means we had to hack things in like this:

    https://github.com/xamarin/xamarin-macios/blob/master/tools/common/StaticRegistrar.cs#L2276

    The version of Xamarin.Mac in the alpha channel (XM 3.0.x) should have this fix. It at least works for Unified. I honestly have zero idea without testing if it will work for Classic. Classic + Static registrar is not a supported/tested configuration at all. I don't see why it shouldn't work though.

    May I strongly suggest that you migrate to Unified. Is there any particular reason you still are on Classic?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, January 5, 2017 10:16 PM

All replies

  • User35201 posted

    So Apple did something less that kosher and removed the QTKit headers, as you noticed. However, they did not remove the symbols from the libraries (as nm /System/Library/Frameworks/QTKit.framework/QTKit can show).

    The dynamic registrar works just fine, since it uses the objective-c equivalents of reflection to look up the symbols directly. However, since the header is gone, we can't register the types statically.

    This means we had to hack things in like this:

    https://github.com/xamarin/xamarin-macios/blob/master/tools/common/StaticRegistrar.cs#L2276

    The version of Xamarin.Mac in the alpha channel (XM 3.0.x) should have this fix. It at least works for Unified. I honestly have zero idea without testing if it will work for Classic. Classic + Static registrar is not a supported/tested configuration at all. I don't see why it shouldn't work though.

    May I strongly suggest that you migrate to Unified. Is there any particular reason you still are on Classic?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, January 5, 2017 10:16 PM
  • User78604 posted

    Thank you Chris for the quick answer.

    I'll test on the Alpha channel as soon as I can.

    To answer your question, I would love to switch to the Unified API, but alas it is not so easy. My colleague did start working on it some time ago and he encountered a couple of issues of missing features that were in the classic. I don't have specific details, but while it did not make it impossible to do so, it made the time required for switching quite uncertain and therefor pushed this down in our priority list.

    While it is still on our todo list, it has a hard time pushing it's way up.

    Thank you again for your help.

    Friday, January 6, 2017 1:04 PM
  • User35201 posted

    @XavierFortin Fair enough. Just be aware that classic is very much in maintenance mode over here. All new work is Unified only, and that is were our focus is.

    I've been strongly suggesting everyone using classic make time in their schedule to migrate to Unified as soon as reasonably possible. Classic has a number of fundamental flaws that we fixed in Unified.

    If you run into issues during migration, please post them on the forums and feel free to @ me on the post as well.

    Friday, January 6, 2017 3:08 PM
  • User78604 posted

    Hi @ChrisHamons,

    Since I updated recently, I told myself: "Why not try the static registrar now?"

    First thing, my Xamarin.Mac version is 3.0.0.393 and there is currently nothing in the Alpha channel.

    Building gives me the same errors has earlier, but since I have a working Unified API branch, I wanted to give it a try.

    So now building gives me this error:

    [See DebugOutput.txt]

    The thing is I get a completely different output if I just change to Release (still using the static registrar). First thing, I'm getting an error I was also getting in the classic, but while I'm at it, I might as well mention it:

    /Users/Devolutions33/workspace/UnifiedAPI/Mac/RemoteDesktopManager/Clients/RemoteDesktopManager/MMP: Error MM4119: Could not register the selector 'description' of the member 'Devolutions.RemoteDesktopManager.UserInfoRoleGrid.get_Description' because the selector is already registered on the member 'get_Description'. (MM4119) (RemoteDesktopManager)
    

    While it is easy to fix, I was pretty sure we could override Obj-c method that way (I'm doing [Export("description")] in a class deriving from NSObject. The weird thing is that it's not the only place where we're doing this, but I appear to get this error only in this class.

    Regardless, I change Export name to skip this error and I get this:

    [See ReleaseOutput1.txt]

    This is one example of the errors I get:

    /Users/Devolutions33/workspace/UnifiedAPI/Mac/RemoteDesktopManager/Clients/RemoteDesktopManager/obj/Release/mmp-cache/registrar.m:139402:1: error: duplicate interface definition for class 'NSClassDescription'
    

    NSClassDescription being one of the binding class generated via this command:

    /Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/bin/bmac --sourceonly=true --tmpdir=$DIR/Bindings -d="MONOMAC" "$DIR/API.cs" -s="$DIR/enums.cs" --compiler=mcs -baselib=/Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/lib/mono/XamMac.dll
    

    (While I'm at it, what would be the equivalent way to generate bindings for the UnifiedAPI?)

    True to myself, I strip the problematic code and try again (while not ideal, I could work around this issue). I build once again and I get:

    [See ReleaseOutput2.txt]

    An example of an error in this is:

    Undefined symbols for architecture x86_64:
              "_OBJC_CLASS_$_DevOSAScriptView", referenced from:
                  objc-class-ref in registrar-e87da8.o
                  _OBJC_CLASS_$_RDMOSAScriptView in registrar-e87da8.o
    

    DevOSAScriptView is binding to a class in a dylib helper that I swear is built for the x86_64 architecture (I verified).

    This is were I ran out of ideas. Does anyone as any ideas?

    Wednesday, March 1, 2017 4:47 PM
  • User35201 posted

    Ok, let's look at your error messages first:

    The first one:

    System.InvalidOperationException: Operation is not valid due to the current state of the object. at Mono.CompilerServices.SymbolWriter.MonoSymbolFile.GetMethodByToken (System.Int32 token) [0x00032] in /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/external/mono/external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs:537

    is a bug that you are crashing.

    It generally means we crashed somewhere else, are trying to generate the static registrar.

    Ironically enough, we are working on a fix for that "2nd error when reporting an error" now - https://github.com/xamarin/xamarin-macios/pull/1769

    On the second on, if you take a look you'll notice:

    /Users/Devolutions33/workspace/UnifiedAPI/Mac/RemoteDesktopManager/Clients/RemoteDesktopManager/obj/Release/mmp-cache/registrar.m:139402:1: error: duplicate interface definition for class 'NSClassDescription'

    If you open up the filed referenced (registrar.m) and go to line 139402, you can see what class at least is causing the issue.

    The third error:

      Undefined symbols for architecture x86_64:
        "_OBJC_CLASS_$_DevOSAScriptView", referenced from:
            objc-class-ref in registrar-e87da8.o
            _OBJC_CLASS_$_RDMOSAScriptView in registrar-e87da8.o
        "_OBJC_CLASS_$_KeychainCertificate", referenced from:
            objc-class-ref in registrar-e87da8.o
    

    Is what it says it is: We're trying to statically link your stuff, and we see a DevOSAScriptView obj-c class, and we can't find the definition for it anywhere.

    The relevant command line bits from clang include:

    xcrun -sdk macosx clang -arch x86_64 Users/Devolutions33/workspace/UnifiedAPI/Mac/RemoteDesktopManager/Clients/RemoteDesktopManager/bin/Release/RemoteDesktopManager.app/Contents/MonoBundle/libDevolutionsARD.dylib /Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/lib/pkgconfig/../../lib/libmonosgen-2.0.a

    So I assume the lib should be defined in libDevolutionsARD.dylib

    First things first, I'm confused why it's being passed directly to clang. Are you adding it to your additional mmp arguments directly? Or are you using the native reference section of your project?

    Second, I would use lipo -info libDevolutionsARD.dylib to see what arch are inside and then nm --arch x86_64 libDevolutionsARD.dylib | grep DevOSAScriptView to see if it is exporting what you think.

    Wednesday, March 1, 2017 8:43 PM
  • User35201 posted

    Yeah, that bmac call is wrong:

    /Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/bin/bmac --sourceonly=true --tmpdir=$DIR/Bindings -d="MONOMAC" "$DIR/API.cs" -s="$DIR/enums.cs" --compiler=mcs -baselib=/Library/Frameworks/Xamarin.Mac.framework/Versions/3.0.0.393/lib/mono/XamMac.dll

    I'd expect something like:

    /Library/Frameworks/Xamarin.Mac.framework/Commands/bmac --unified-full-profile "$DIR/API.cs" -s="$DIR/enums.cs"

    (or --unified-mobile-profile if you are mobile )

    Often, defining the base lib / compiler isn't needed in unified anymore.

    Or, you could literally just junk all of this and use a binding project:

    https://developer.xamarin.com/guides/mac/advanced_topics/binding/

    (Ignore the line about it being preview, it is not true and a documentation bug was filed).

    Which handles all of this for you, and is the awesome way of doing this.

    Wednesday, March 1, 2017 8:46 PM
  • User78604 posted

    Thank you for your answer,

    1) After fixing some of the other things below, I'm not having this anymore.

    2) What I find at this line is this:

    @interface NSClassDescription : NSObject {
    }
        -(id) init;
        -(id) initWithCoder:(NSCoder *)p0;
    @end
    

    The error makes a lot of sense now that I think of it. NSClassDescription is already a class in the Cocoa framework so of course declaring an interface with the name of an already existing one will fail. I can work around this, though, so it should be fine.

    As for IKImageBrowserItem, it seems to be an issue with Cocoa. If I copy the code in a fresh Cocoa app I get the same errors. I can jump to the definition and it does bring me to it's definition in ImageKit though the Apple reference page says it's a protocol while it's not declared as one. I'm no expert in ObjC, so I might be misunderstanding something.

    3) Now, I was pretty sure that I figured why this happened. We're copying our frameworks in the app bundle directly with build commands and loading them at runtime with Dlfcn.dlopen(). For some reason all our Dylib are in the Native References section except for this specific helper which is also loaded via Dlfcn.dlopen(). So I though of setting them all in the Native References section, but for no avail.

    I don't know why libDevolutionsARD.dylib is passed as an arguments as it was already in the Native References section (it is not the mentioned helper) and except for --registrar:static, I have no mmp arguments. For that matter, DevOSAScriptView (and all other class with this error) is not in the libDevolutionsARD.dylib. It is in a dylib called libNativeHelper.dylib. Others are references in other frameworks, like SUUpdater is in the Sparkle framework. libNativeHelper was indeed not in the Native References, but now it is, and I'm still getting the same errors (see attached). I did confirm the architecture of all dylib and frameworks, all are x8664 except one which is both x8664 and i386 (would that be an issue?).

    Thursday, March 2, 2017 4:19 PM
  • User35201 posted

    Try adding libNativeHelper.dylib as a native reference to the application failing?

    Here's the problem we're running into:

    • Static registrar generates trampolines ahead of time instead of dynamically
    • This means we need to have type information for things referenced in C# code
    • Which means we have to have those symbols to bind to
    • Which means we need to pass those to the native linker.
    Monday, March 6, 2017 6:02 PM
  • User78604 posted

    Hi @ChrisHamons,

    Two years in and I'm resurrecting this issue! I'm a slow worker ;)

    The static registrar does work (though only in release, which I'm perfectly fine with). The reason I've not switched yet is due to the fact that we are actually obfuscating parts of our application (a couple of DLLs and the .exe). Once obfuscated, the application built with the static registrar crash on launch.

    I've added exception to properties and method with ExportAttribute and classes with RegisterAttribute from the obfuscation. But the result stays the same. Here's the crash outputted to the console:

    =================================================================
        Native Crash Reporting
    =================================================================
    Got a SIGABRT while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries 
    used by your application.
    =================================================================
    
    =================================================================
        Basic Fault Adddress Reporting
    =================================================================
    Memory around native instruction pointer (0x7fff72e662c6):0x7fff72e662b6  ff ff c3 90 90 90 b8 48 01 00 02 49 89 ca 0f 05  .......H...I....
    0x7fff72e662c6  73 08 48 89 c7 e9 87 a1 ff ff c3 55 48 89 e5 41  s.H........UH..A
    0x7fff72e662d6  57 41 56 41 55 41 54 53 48 81 ec 88 00 00 00 4d  WAVAUATSH......M
    0x7fff72e662e6  89 cf 49 89 f4 48 8d 05 76 d2 59 36 48 8b 00 48  ..I..H..v.Y6H..H
    
    =================================================================
        Native stacktrace:
    =================================================================
        0x10b54af94 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_dump_native_crash_info
        0x10b53ee45 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_handle_native_crash
        0x7fff72f16b5d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
        0x112d89e78 - Unknown
        0x7fff72dd06a6 - /usr/lib/system/libsystem_c.dylib : abort
        0x10b4629f0 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : _ZL12log_callbackPKcS0_S0_iPv
        0x10b7703ce - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : monoeg_g_logv_nofree
        0x10b77054f - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : monoeg_assertion_message
        0x10b690952 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_type_get_object_checked
        0x10b6906a4 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_type_get_object
        0x10b460d67 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : xamarin_get_nsobject_with_type_for_ptr_created
        0x10b8367f5 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : _ZL32native_to_managed_trampoline_116P11objc_objectP13objc_selectorPP11_MonoMethodP14NSNotificationj
        0x10b9b40d5 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : -[AppDelegate applicationWillFinishLaunching:]
        0x7fff46da837a - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
        0x7fff46da82f4 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : ___CFXRegistrationPost_block_invoke
        0x7fff46da825e - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : _CFXRegistrationPost
        0x7fff46db068d - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : ___CFXNotificationPost_block_invoke
        0x7fff46d1976c - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : -[_CFXNotificationRegistrar find:object:observer:enumerator:]
        0x7fff46d18a17 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : _CFXNotificationPost
        0x7fff48fbc06b - /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation : -[NSNotificationCenter postNotificationName:object:userInfo:]
        0x7fff443b6b27 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication finishLaunching]
        0x7fff443b667b - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication run]
        0x7fff443a5d7c - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : NSApplicationMain
        0x11b61bc00 - Unknown
        0x11b61bab3 - Unknown
        0x1144ae019 - Unknown
        0x10b5550b1 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_jit_runtime_invoke
        0x10b67a638 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_runtime_invoke_checked
        0x10b68180d - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_runtime_exec_main_checked
        0x10b4b0c17 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_jit_exec
        0x10b4b3ea3 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : mono_main
        0x10b46dadf - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : xamarin_main
        0x10b46e994 - /Users/richard/Desktop/Packaging/RemoteDesktopManager/2019.1.9.1574114296/Remote Desktop Manager.app/Contents/MacOS/RemoteDesktopManager : main
        0x7fff72d2b3d5 - /usr/lib/system/libdyld.dylib : start
    
    =================================================================
        Managed Stacktrace:
    =================================================================
          at <unknown> <0xffffffff>
          at AppKit.NSApplication:NSApplicationMain <0x0012f>
          at AppKit.NSApplication:Main <0x000f2>
          at Client.BaseMacClient:cf0dc1cfd9b511309d6fbd24be6ac2187 <0x0003a>
          at Client.BaseMacClient:cf80ac4075cce562eb8254151c47d3e24 <0x0005a>
          at Client.BaseMacClient:cf80ac4075cce562eb8254151c47d3e24 <0x00092>
          at Client.BaseMacClient:Startup <0x00042>
          at RemoteDesktopManager.Client:cd00ca868e3a2e07e1a60509ada71b4d9 <0x0058a>
          at <Module>:runtime_invoke_void_object <0x000e8>
    =================================================================
    

    Would you know why is this happening? The obfuscation renames all private variables, properties, methods, classes and interfaces. Excluding those with the ObfuscationAttribute, ExportAttribute and RegisterAttribute.

    Or is there a more in depth documentation on how the static registrar works so I can better identify what could be the issue?

    Best regards,

    Tuesday, November 19, 2019 3:29 PM
  • User35201 posted

    We've had cases in the past where obfuscation programs produce questionable or flat out invalid IL and it crashes mono when it tries to run it.

    • You could try updating to a newer SDK to see if newer mono better handle that IL
    • If your obfuscation tool has settings, you could try enabling settings one at a time until you figure out which one is causing issues.
    • AOTing your applocaiton might change the behavior as well.
    Tuesday, November 19, 2019 6:04 PM
  • User78604 posted

    Hi Chris,

    Wouldn't invalid IL be an issue regardless of the static registrar?

    I've disabled pretty much all settings at this point, including the symbols renaming, and still receive a crash on launch, though admittedly a different one. Here's the new stack trace:

    =================================================================
        Native Crash Reporting
    =================================================================
    Got a SIGABRT while executing native code. This usually indicates
    a fatal error in the mono runtime or one of the native libraries 
    used by your application.
    =================================================================
    
    =================================================================
        Basic Fault Adddress Reporting
    =================================================================
    Memory around native instruction pointer (0x7fff72e662c6):0x7fff72e662b6  ff ff c3 90 90 90 b8 48 01 00 02 49 89 ca 0f 05  .......H...I....
    0x7fff72e662c6  73 08 48 89 c7 e9 87 a1 ff ff c3 55 48 89 e5 41  s.H........UH..A
    0x7fff72e662d6  57 41 56 41 55 41 54 53 48 81 ec 88 00 00 00 4d  WAVAUATSH......M
    0x7fff72e662e6  89 cf 49 89 f4 48 8d 05 76 d2 59 36 48 8b 00 48  ..I..H..v.Y6H..H
    
    =================================================================
        Native stacktrace:
    =================================================================
        0x10d024ab4 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : mono_dump_native_crash_info
        0x10d018965 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : mono_handle_native_crash
        0x7fff72f16b5d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
        0x7ffee2cedd20 - Unknown
        0x7fff72dd06a6 - /usr/lib/system/libsystem_c.dylib : abort
        0x10cf3c510 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : _ZL12log_callbackPKcS0_S0_iPv
        0x10d249eee - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : monoeg_g_logv_nofree
        0x10d24a06f - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : monoeg_assertion_message
        0x10d16a472 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : mono_type_get_object_checked
        0x10d16a1c4 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : mono_type_get_object
        0x10cf3a887 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : xamarin_get_nsobject_with_type_for_ptr_created
        0x10d25e9f5 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : _ZL31native_to_managed_trampoline_44P11objc_objectP13objc_selectorPP11_MonoMethodP8NSButtonj
        0x10d494f85 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : -[ErrorWindowController setButClose:]
        0x7fff443b4e13 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:]
        0x7fff443b2d14 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : loadNib
        0x7fff443b21f4 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:]
        0x7fff4453a56e - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : +[NSBundle(NSNibLoadingInternal) _loadNibFile:externalNameTable:options:withZone:]
        0x7fff4453a32b - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindowController loadWindow]
        0x7fff4449e13e - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSWindowController window]
        0x117acaec5 - Unknown
        0x11d20e72a - Unknown
        0x10d02ebd1 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : mono_jit_runtime_invoke
        0x10d154158 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : mono_runtime_invoke_checked
        0x10d158a2e - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : mono_runtime_invoke
        0x10d25960d - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : _ZL31native_to_managed_trampoline_24P11objc_objectP13objc_selectorPP11_MonoMethodj
        0x10d3cf6f4 - /Users/richard/Desktop/Obfuscation/RemoteDesktopManager.app/Contents/MacOS/RemoteDesktopManager : -[__MonoMac_NSActionDispatcher xamarinApplySelector]
        0x7fff49054d18 - /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation : -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:]
        0x7fff4905c742 - /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation : -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:]
        0x11b6c9ebe - Unknown
    
    =================================================================
        Managed Stacktrace:
    =================================================================
          at <unknown> <0xffffffff>
          at ObjCRuntime.Messaging:IntPtr_objc_msgSendSuper <0x00064>
          at AppKit.NSWindowController:get_Window <0x000c2>
          at Devolutions.RemoteDesktopManager.ErrorWindowController:get_Window <0x0001a>
          at <>c__DisplayClass12_0:<OnException>b__0 <0x000ba>
          at Foundation.NSActionDispatcher:Apply <0x00019>
          at System.Object:runtime_invoke_void__this__ <0x000e8>
          at <unknown> <0xffffffff>
          at ObjCRuntime.Messaging:void_objc_msgSend_IntPtr_IntPtr_bool <0x0008d>
          at Foundation.NSObject:InvokeOnMainThread <0x000d2>
          at RemoteDesktopManager.Client:OnException <0x00162>
          at <>c:<Main>b__11_0 <0x0004a>
          at <Module>:runtime_invoke_void__this___object_object <0x0008f>
          at <unknown> <0xffffffff>
          at AppKit.NSApplication:NSApplicationMain <0x0012f>
          at AppKit.NSApplication:Main <0x000f2>
          at Client.BaseMacClient:Run <0x0003a>
          at Client.BaseMacClient:Startup <0x0005a>
          at Client.BaseMacClient:Startup <0x00062>
          at Client.BaseMacClient:Startup <0x00042>
          at RemoteDesktopManager.Client:Main <0x0049a>
          at <Module>:runtime_invoke_void_object <0x000e8>
    =================================================================
    

    This is with Crypto Obfuscator. I've tried with Babel and I get similar result. I'll try disabling features in it too.

    Thursday, November 21, 2019 10:04 PM
  • User35201 posted

    The interactions between tools that generate "interesting" IL, the mono runtime engine, and build changes that may change timing/ordering (like the static registrar) can be frighteningly complex.

    I see a few options forward:

    • Try a different tool
    • Try different tool settings
    • Create a sample showing your IL issue and file a mono/mono bug so it can be fixed.
    • Stop using a tool of that nature.
    Friday, November 22, 2019 2:06 PM