Bug 59798 - mtouch crashes when passed any gcc_flags parameter
Summary: mtouch crashes when passed any gcc_flags parameter
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 11.0 (xcode9)
Hardware: Macintosh Mac OS
: --- major
Target Milestone: 15.5
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-09-27 19:09 UTC by Ethan Lee
Modified: 2017-11-20 10:19 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
msbuild output, Debug iPhoneSimulator (18.68 KB, text/plain)
2017-09-27 19:09 UTC, Ethan Lee
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Ethan Lee 2017-09-27 19:09:07 UTC
Created attachment 24965 [details]
msbuild output, Debug iPhoneSimulator

When building with Visual Studio for Mac (version 7.1.5 build 2), mtouch will crash when attempting to pass gcc_flags of any kind (for example, when linking against libSDL2.a). Attached is the full msbuild output, including the crash trace.

iOSTest was based on the single-screen template, with all of the code removed in favor of a basic Main() function, calling SDL_Init and SDL_Quit via SDL2# (which is bundled in with the project):

https://github.com/flibitijibibo/SDL2-CS

libSDL2.a was built with SDL's provided build script, and supports i386/x86_64/armv7/armv7s/arm64.

The problem appears to be here, where it fails to find a matching name and proceeds to hit a NullReference:

https://github.com/xamarin/xamarin-macios/blob/master/tools/common/Target.cs#L115

When no gcc_flags are passed (including gcc_flags ""), the build succeeds and throws an Exception at runtime when it can't find the SDL_Init entry point, as it should.

The gcc_flags input was based on the Xamarin.iOS documentation, which does appear to be out of date given that it calls the text box "Extra" as opposed to "Additional mtouch arguments," which is what it's called in the latest version of VSM:

https://developer.xamarin.com/guides/ios/advanced_topics/native_interop/
Comment 1 Rolf Bjarne Kvinge [MSFT] 2017-09-28 10:15:39 UTC
(In reply to Ethan Lee from comment #0)

> iOSTest was based on the single-screen template, with all of the code
> removed in favor of a basic Main() function, calling SDL_Init and SDL_Quit
> via SDL2# (which is bundled in with the project):

If you remove all the code except for a Main function, the main executable won't have a reference to Xamarin.iOS.dll, and that's the reason for the NullReferenceException.

Using any API from Xamarin.iOS.dll will work around this (it can be as simple as "Console.WriteLine (typeof (UIKit.UIWindow));" for instance).

In any case I've added detection for this in our tools, so that we show a proper error instead of an MT0000: https://github.com/xamarin/xamarin-macios/pull/2801
Comment 2 Rolf Bjarne Kvinge [MSFT] 2017-09-28 15:38:24 UTC
Fixed (to show a better error): https://github.com/xamarin/xamarin-macios/commit/eeb62568342c466bb6cb91f9a5cb22e1c4be3f9a
Comment 3 Mohak Barokar 2017-11-20 09:58:55 UTC
@Rolf

Can you please confirm the reproduction steps of this issue?

I have tried with following reproduction steps:
1. Create iOS single view Application 
2. Pass any gcc flag arguments in  "Additional mtouch arguments" such as "--gcc_flags="-framework AVFoundation -framework CoreMedia""
3. Build solution

Following is the build config this is verified on:
https://gist.github.com/raghorteprasad/2a6a24dc25d226b4012ddddb1975a152
Comment 4 Rolf Bjarne Kvinge [MSFT] 2017-11-20 10:01:24 UTC
@Mohak,

The gcc flags is a red herring in this case, to repro the NullReferenceException:

1. Create iOS Single view application.
2. Remove all code, except a single, empty Main function:

    class MyApp {
        static void Main () {}
        {
        }
    }
3. Build solution.
Comment 5 Mohak Barokar 2017-11-20 10:19:37 UTC
This bug is verified on following d15_5 config according to Comment #4 :

 -Visual Studio Professional 2017 for Mac (Preview) Version 7.4 Preview (7.4 build 632)
 -Mono 5.8.0.69 (2017-10/2cc0f9029ae) (64-bit)
 -Xamarin.Android Version: 8.1.99.22
 -Xamarin.Mac Version: 4.1.0.320
 -Xamarin.iOS Version: 11.7.0.32

 Detailed Build Config: https://gist.github.com/raghorteprasad/2a6a24dc25d226b4012ddddb1975a152

 Screencast Link: http://www.screencast.com/t/75bYCKcl9YwM

The issue is fixed and marking it as Verified Fixed.