[Mono-dev] Assert error for unaligned access in unwind.c

Henry Margies henry.margies at gmail.com
Fri Jul 15 13:47:48 UTC 2016

Hi all,

I’m running into a strange problem when trying to use Mono on an ARM architecture.

When I try to execute a Mono application or simply run mcs, I get the following output:

# mcs
* Assertion at unwind.c:385, condition `read16 (p) == (guint32)(op->when - loc)' not met


Native stacktrace:

Debug info from gdb:

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.


The same application and mcs work fine with Mono 4.0.2, I used a while ago. Looking at the source code in mono/mini/unwind.c in function mono_unwind_ops_encode_full, I can see that the code tries to cast a pointer to a guint16 or guint32 pointer, which will fail on (my) ARM when the address is not aligned (lines 378 and 384).

} else if (op->when - loc > 256) {
    *p ++ = DW_CFA_advance_loc2;
    *(guint16*)p = (guint16)(op->when - loc);
    g_assert (read16 (p) == (guint32)(op->when - loc));

What is interesting, is that the g_assert is using the read16 macro, which deals with alignment issues and also endianness. But with this, I can’t really see how the code would work successfully with big endianness either. 

The code in question hasn’t changed between 4.0 and 4.4 but the pointer casting is only executed when “op->when - loc > 256” is true. So I wonder why this changed for me between 4.0 and 4.4 and if I’m even supposed to run into these cases on an ARM architecture? When I fix the two problems, everything seems to run fine.

Because I don’t think that I’m the first to try to execute “mcs” or run a Mono application on an ARM architecture, I kind of blame my build system. I use buildroot and run my system on an ARM 926 device. Unfortunately, I have no idea what the code in mono_unwind_ops_encode_full actually does and when op->when - loc would actually be greater than 256.

I hope that someone here could give me some pointers on why the if condition could be true and never was before or in fact is not true for any ARM device, so I can check my build system.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/mono-devel-list/attachments/20160715/eb9e3f4a/attachment.html>

More information about the Mono-devel-list mailing list