Bug 16975 - Got a SIGSEGV while executing native code
Summary: Got a SIGSEGV while executing native code
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.8.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2013-12-27 11:30 UTC by Alex
Modified: 2014-01-16 06:15 UTC (History)
2 users (show)

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

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:
RESOLVED NOT_REPRODUCIBLE

Description Alex 2013-12-27 11:30:15 UTC
Hi there,

I'm getting this in logcat right after launch of the app:

E/mono-rt (12504): 
E/mono-rt (12504): =================================================================
E/mono-rt (12504): Got a SIGSEGV while executing native code. This usually indicates
E/mono-rt (12504): a fatal error in the mono runtime or one of the native libraries 
E/mono-rt (12504): used by your application.
E/mono-rt (12504): =================================================================
E/mono-rt (12504): 

to be honest I don't know if this issue is related to https://bugzilla.xamarin.com/show_bug.cgi?id=13521,
the problem is that I get this crash only when building in release mode, in debug mode everything works fine,
such that no stacktrace/debug information is provided.

Thank you!
Comment 1 Jonathan Pryor 2013-12-27 12:23:20 UTC
Please try using Xamarin.Android 4.10 or later. The most common cause for a SIGSEGV is invoking a JNI method on a null object handle (e.g. `JNIEnv.CallObjectMethod(IntPtr.Zero, methodHandle)`), and Xamarin.Android 4.10 adds additional argument checking so that an ArgumentException is thrown instead of a SIGSEGV. If you get an ArgumentException, that's an app bug you'll need to investigate.

If it's not due to invoking a JNI method on a null handle, I'll need a repro to examine.
Comment 3 Alex 2014-01-07 08:36:22 UTC
Hi,

this is what the console prints right before the app crashes: 

D/dalvikvm(15495): Added shared lib /data/app-lib/com.schonetech.PingYa-1/libmonodroid.so 0x42a22870
W/libc    (15495): WARNING: generic atexit() called from legacy shared library
F/        (15495): * Assertion: should not be reached at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/mono/mono/mini/mini.c:2632
E/mono-rt (15495): 
E/mono-rt (15495): =================================================================
E/mono-rt (15495): Got a SIGSEGV while executing native code. This usually indicates
E/mono-rt (15495): a fatal error in the mono runtime or one of the native libraries 
E/mono-rt (15495): used by your application.
E/mono-rt (15495): =================================================================
E/mono-rt (15495): 
I/ActivityManager(  696): Process com.schonetech.PingYa (pid 15495) (adj 0) has died.


It seems to me that this crash comes right after loading the mono shared lib. I also added various Console.WriteLine in many parts of my code to see if something on my side is wrong, but no one of those console prints gets ever called. Also very strange is that this issue happens only in release mode. I have no chance to inspect my code for errors this way.

Any chance to get some help on this please?

Thanks,
Alex
Comment 4 Jonathan Pryor 2014-01-07 11:21:20 UTC
> Also very strange is that this issue happens only in release mode.

Sounds like a linker issue then.

Step 1: Disable the linker in Release mode, see if that "fixes" it. (The .apk will be _gigantic_, but at least it'll narrow things down.)

Step 2: Assuming (1) results in a working build, what's your $(AndroidLinkMode) setting? If it's Link All Assemblies...don't do that. ;-)

If it's still breaking with Link SDK Assemblies...

Step 3 (hail marry pass): enable `mono --trace`:

    adb shell setprop debug.mono.trace all

Re-run your app, and write `adb logcat -d` to a file. (It'll be gigantic.) If you're extremely lucky, the trace output will let you know where things are blowing up.
Comment 5 Alex 2014-01-08 09:49:04 UTC
Jonathan,

thank you for your tips. Actually the app works already with step 1 (you were right, linking the assemblies was causing the crash).

$AndroidLinkMode was exactly that, "Link all assemblies" :), only "don't link" seems to work, and yes, the .apk gets bloated (26mb nonetheless).

Step 3 gave some more information, although nothing meaningful to me:

I/mono    (24218): [0x40063ffc: 0.00000 0] 
I/mono    (24218): ENTER: (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___object_object (object,intptr,intptr,intptr)(
I/mono    (24218): ) ip: 0x0
I/mono    (24218): [0x40063ffc: 0.00009 1] 
I/mono    (24218): ENTER: System.TypeLoadException:.ctor (string,string)(
I/mono    (24218): ) ip: 0x0
F/        (24218): * Assertion: should not be reached at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/mono/mono/mini/mini.c:2632

Does this say something to you?
Comment 6 Alex 2014-01-13 04:58:35 UTC
Jonathan, sorry, but I have to bump on this. My app is locked in play store since Dec. 27., I would like to get this issue fixed somehow.
Comment 7 Jonathan Pryor 2014-01-13 16:42:07 UTC
> $AndroidLinkMode was exactly that, "Link all assemblies" :), only "don't link"
> seems to work, and yes, the .apk gets bloated (26mb nonetheless).

Yeah. Don't use "Link all assemblies" unless you really mean it (and usually you don't).

What happens if you use "Link SDK Assemblies"?

> Does this say something to you?

A little; it says that a TypeLoadException is being generated. I don't know _why_ it's being generated; that's probably deducible from the trace output, but that output is huge...

I would again suggest using Link SDK Assemblies and seeing how that works.
Comment 8 Alex 2014-01-15 07:57:57 UTC
Hi Jonathan,

the app actually works on the device ONLY when the linker is disabled i.e. $(AndroidLinkMode) is set to none, both in debug AND in release mode.

This means to me that in my Xamarin Android installation (4.8.3) the linker is broke/bugged/not working.

Can you please provide a working linker? 

Thank you very much!
Comment 9 Jonathan Pryor 2014-01-15 11:04:02 UTC
> Can you please provide a working linker? 

We would very much like to provide a working linker.

Unfortunately to do so we need to know in what ways that it's broken. :-)

Could you please provide a testcase so that the linker team can investigate?

Aside: normally linking is disabled ("None") in Debug builds.
Comment 10 Alex 2014-01-16 06:15:10 UTC
I dont know what exactly made the difference, but I rewrote the project in a clean project folder (only 3 source files) from scratch and now it works. :-/