Bug 58210 - "* Assertion at metadata.c:1048, condition `index < meta->heap_strings.size' not met" is output on startup - works fine on Windows
Summary: "* Assertion at metadata.c:1048, condition `index < meta->heap_strings.size' ...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: master
Hardware: PC Linux
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-18 11:54 UTC by ken.krakman
Modified: 2017-07-25 17:18 UTC (History)
5 users (show)

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


Attachments
Compiled with Visual Studio 2015, run under Mono on Ubuntu. (1.60 MB, application/x-msdownload)
2017-07-18 11:54 UTC, ken.krakman
Details

Description ken.krakman 2017-07-18 11:54:56 UTC
Created attachment 23621 [details]
Compiled with Visual Studio 2015, run under Mono on Ubuntu.

When a program with a lot of struct declarations starts, it always gets an assert about heap_strings.

Following is the program, which runs fine on Windows. 
Thanks for the help!


=========================================================================================
namespace exp_tester
{

    public unsafe class Program
    {
        
        static public void Main()
        {
            Console.WriteLine("I am a one line program, that does nothing.");
       
        }
    }
}

It also is compiled with around 9000 declarations like the one below that are NOT referenced currently.

        unsafe public struct UtranMobilityInformation_v690ext_IEs
        {
            [Component(0, "primary-plmn-Identity")]
            public sbyte compmask;
            public PLMN_Identity primary_plmn_Identity;
        }


==========================================================================================
 ./exp_tester.exe
* Assertion at metadata.c:1048, condition `index < meta->heap_strings.size' not met

Stacktrace:

/proc/self/maps:
00400000-007ba000 r-xp 00000000 08:01 4867                               /usr/bin/mono-sgen
009ba000-009bb000 r--p 003ba000 08:01 4867                               /usr/bin/mono-sgen
009bb000-009be000 rw-p 003bb000 08:01 4867                               /usr/bin/mono-sgen
009be000-009f2000 rw-p 00000000 00:00 0 
01f5e000-01fd8000 rw-p 00000000 00:00 0                                  [heap]
40540000-40550000 rwxp 00000000 00:00 0 
40b4e000-40b5e000 rwxp 00000000 00:00 0 
7f4828000000-7f4828021000 rw-p 00000000 00:00 0 
7f4828021000-7f482c000000 ---p 00000000 00:00 0 
7f482e172000-7f482e30c000 r--p 00000000 00:2c 65748                      /home/ken/emil/projects/exp_tester/exp_tester/exp_tester/bin/Release/exp_tester.exe
7f482e30c000-7f482e315000 ---p 00000000 00:00 0 
7f482e315000-7f482e50d000 rw-p 00000000 00:00 0 
7f482e50d000-7f482ea3b000 r-xp 00000000 08:01 158041                     /usr/lib/mono/aot-cache/amd64/mscorlib.dll.so
7f482ea3b000-7f482ec3a000 ---p 0052e000 08:01 158041                     /usr/lib/mono/aot-cache/amd64/mscorlib.dll.so
7f482ec3a000-7f482ec3b000 rw-p 0052d000 08:01 158041                     /usr/lib/mono/aot-cache/amd64/mscorlib.dll.so
7f482ec3b000-7f482ec58000 rw-p 00000000 00:00 0 
7f482ec58000-7f482efff000 r--p 00000000 08:01 158668                     /usr/lib/mono/4.5/mscorlib.dll
7f482efff000-7f482ffff000 rw-p 00000000 00:00 0 
7f482ffff000-7f4830000000 ---p 00000000 00:00 0 
7f4830000000-7f4830c00000 rw-p 00000000 00:00 0 
7f4830d18000-7f4830ff0000 r--p 00000000 08:01 4417                       /usr/lib/locale/locale-archive
7f4830ff0000-7f48311b0000 r-xp 00000000 08:01 655530                     /lib/x86_64-linux-gnu/libc-2.23.so
7f48311b0000-7f48313b0000 ---p 001c0000 08:01 655530                     /lib/x86_64-linux-gnu/libc-2.23.so
7f48313b0000-7f48313b4000 r--p 001c0000 08:01 655530                     /lib/x86_64-linux-gnu/libc-2.23.so
7f48313b4000-7f48313b6000 rw-p 001c4000 08:01 655530                     /lib/x86_64-linux-gnu/libc-2.23.so
7f48313b6000-7f48313ba000 rw-p 00000000 00:00 0 
7f48313ba000-7f48313d0000 r-xp 00000000 08:01 659758                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f48313d0000-7f48315cf000 ---p 00016000 08:01 659758                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f48315cf000-7f48315d0000 rw-p 00015000 08:01 659758                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f48315d0000-7f48315e8000 r-xp 00000000 08:01 655513                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7f48315e8000-7f48317e7000 ---p 00018000 08:01 655513                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7f48317e7000-7f48317e8000 r--p 00017000 08:01 655513                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7f48317e8000-7f48317e9000 rw-p 00018000 08:01 655513                     /lib/x86_64-linux-gnu/libpthread-2.23.so
7f48317e9000-7f48317ed000 rw-p 00000000 00:00 0 
7f48317ed000-7f48317f0000 r-xp 00000000 08:01 655519                     /lib/x86_64-linux-gnu/libdl-2.23.so
7f48317f0000-7f48319ef000 ---p 00003000 08:01 655519                     /lib/x86_64-linux-gnu/libdl-2.23.so
7f48319ef000-7f48319f0000 r--p 00002000 08:01 655519                     /lib/x86_64-linux-gnu/libdl-2.23.so
7f48319f0000-7f48319f1000 rw-p 00003000 08:01 655519                     /lib/x86_64-linux-gnu/libdl-2.23.so
7f48319f1000-7f48319f8000 r-xp 00000000 08:01 655516                     /lib/x86_64-linux-gnu/librt-2.23.so
7f48319f8000-7f4831bf7000 ---p 00007000 08:01 655516                     /lib/x86_64-linux-gnu/librt-2.23.so
7f4831bf7000-7f4831bf8000 r--p 00006000 08:01 655516                     /lib/x86_64-linux-gnu/librt-2.23.so
7f4831bf8000-7f4831bf9000 rw-p 00007000 08:01 655516                     /lib/x86_64-linux-gnu/librt-2.23.so
7f4831bf9000-7f4831d01000 r-xp 00000000 08:01 655525                     /lib/x86_64-linux-gnu/libm-2.23.so
7f4831d01000-7f4831f00000 ---p 00108000 08:01 655525                     /lib/x86_64-linux-gnu/libm-2.23.so
7f4831f00000-7f4831f01000 r--p 00107000 08:01 655525                     /lib/x86_64-linux-gnu/libm-2.23.so
7f4831f01000-7f4831f02000 rw-p 00108000 08:01 655525                     /lib/x86_64-linux-gnu/libm-2.23.so
7f4831f02000-7f4831f28000 r-xp 00000000 08:01 655508                     /lib/x86_64-linux-gnu/ld-2.23.so
7f4831fc3000-7f4832074000 rw-p 00000000 00:00 0 
7f4832077000-7f48320a9000 rw-p 00000000 00:00 0 
7f48320a9000-7f4832108000 ---p 00000000 00:00 0 
7f4832108000-7f483210d000 rw-p 00000000 00:00 0 
7f4832110000-7f4832124000 rw-p 00000000 00:00 0 
7f4832124000-7f4832125000 rw-s 00000000 00:13 11                         /dev/shm/mono.29227
7f4832125000-7f4832127000 rw-p 00000000 00:00 0 
7f4832127000-7f4832128000 r--p 00025000 08:01 655508                     /lib/x86_64-linux-gnu/ld-2.23.so
7f4832128000-7f4832129000 rw-p 00026000 08:01 655508                     /lib/x86_64-linux-gnu/ld-2.23.so
7f4832129000-7f483212a000 rw-p 00000000 00:00 0 
7ffe40a8f000-7ffe40a97000 ---p 00000000 00:00 0 
7ffe4126d000-7ffe4128e000 rw-p 00000000 00:00 0                          [stack]
7ffe4136a000-7ffe4136c000 r--p 00000000 00:00 0                          [vvar]
7ffe4136c000-7ffe4136e000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

Native stacktrace:

	/usr/bin/cli() [0x4ad209]
	/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7f48315e1390]
	/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38) [0x7f4831025428]
	/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a) [0x7f483102702a]
	/usr/bin/cli() [0x67b739]
	/usr/bin/cli() [0x6902dd]
	/usr/bin/cli() [0x690473]
	/usr/bin/cli() [0x5985cf]
	/usr/bin/cli() [0x572cc5]
	/usr/bin/cli() [0x573c04]
	/usr/bin/cli() [0x574567]
	/usr/bin/cli() [0x54138e]
	/usr/bin/cli(mono_main+0xc36) [0x47d006]
	/usr/bin/cli() [0x4208fe]
	/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f4831010830]
	/usr/bin/cli(_start+0x29) [0x420eb9]

Debug info from gdb:
Comment 1 Ludovic Henry 2017-07-20 14:39:51 UTC
I can very easily reproduce on the following configurations:
 - ubuntu 16.04 + mono 5.0
 - macOS 10.12 + mono 5.4

To reproduce download the attachment and run the following command:

> mono exp_tester.exe

It crashes immediately on macOS with following output:

> * Assertion at metadata.c:1052, condition `index < meta->heap_strings.size' not met
> 
> 
> Native stacktrace:
> 
> 	0   mono                                0x00000001095aeeb1 mono_handle_native_crash + 257
> 	1   libsystem_platform.dylib            0x0000000109d2ab3a _sigtramp + 26
> 	2   libsystem_kernel.dylib              0x0000000109bd5430 libsystem_kernel.dylib + 1072
> 	3   libsystem_c.dylib                   0x0000000109b11420 abort + 129
> 	4   mono                                0x00000001097873ca mono_log_write_logfile + 346
> 	5   mono                                0x000000010979f053 monoeg_g_logv + 83
> 	6   mono                                0x000000010979f26f monoeg_assertion_message + 143
> 	7   mono                                0x00000001096986b1 mono_metadata_string_heap + 49
> 	8   mono                                0x000000010966f97a do_mono_image_load + 602
> 	9   mono                                0x000000010966fe77 mono_image_open_a_lot + 359
> 	10  mono                                0x00000001096fae4f mono_init_internal + 783
> 	11  mono                                0x00000001095035e8 mini_init + 1176
> 	12  mono                                0x000000010957245c mono_main + 5548
> 	13  mono                                0x00000001094f5724 main + 1860
> 	14  mono                                0x00000001094f4fd4 start + 52
> 	15  ???                                 0x0000000000000002 0x0 + 2
> 
> Debug info from gdb:
> 
> (lldb) command source -s 0 '/tmp/mono-gdb-commands.pzRETl'
> Executing commands in '/tmp/mono-gdb-commands.pzRETl'.
> (lldb) process attach --pid 54663
> Process 54663 stopped
> * thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>     frame #0: 0x0000000109bef3ee libsystem_kernel.dylib`__wait4 + 10
> libsystem_kernel.dylib`__wait4:
> ->  0x109bef3ee <+10>: jae    0x109bef3f8               ; <+20>
>     0x109bef3f0 <+12>: movq   %rax, %rdi
>     0x109bef3f3 <+15>: jmp    0x109be7cd4               ; cerror
>     0x109bef3f8 <+20>: retq
> 
> Executable module set to "/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono".
> Architecture set to: x86_64h-apple-macosx.
> (lldb) thread list
> Process 54663 stopped
> * thread #1: tid = 0x2e1674b, 0x0000000109bef3ee libsystem_kernel.dylib`__wait4 + 10, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>   thread #2: tid = 0x2e16752, 0x0000000109beebf2 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
>   thread #3: tid = 0x2e16753, 0x0000000109beebf2 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
> (lldb) thread backtrace all
> * thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
>   * frame #0: 0x0000000109bef3ee libsystem_kernel.dylib`__wait4 + 10
>     frame #1: 0x00000001095aef3d mono`mono_handle_native_crash + 397
>     frame #2: 0x0000000109d2ab3a libsystem_platform.dylib`_sigtramp + 26
>     frame #3: 0x0000000109beed43 libsystem_kernel.dylib`__pthread_kill + 11
>     frame #4: 0x0000000109d44457 libsystem_pthread.dylib`pthread_kill + 90
>     frame #5: 0x0000000109b11420 libsystem_c.dylib`abort + 129
>     frame #6: 0x00000001097873ca mono`mono_log_write_logfile + 346
>     frame #7: 0x000000010979f053 mono`monoeg_g_logv + 83
>     frame #8: 0x000000010979f26f mono`monoeg_assertion_message + 143
>     frame #9: 0x00000001096986b1 mono`mono_metadata_string_heap + 49
>     frame #10: 0x000000010966f97a mono`do_mono_image_load + 602
>     frame #11: 0x000000010966fe77 mono`mono_image_open_a_lot + 359
>     frame #12: 0x00000001096fae4f mono`mono_init_internal + 783
>     frame #13: 0x00000001095035e8 mono`mini_init + 1176
>     frame #14: 0x000000010957245c mono`mono_main + 5548
>     frame #15: 0x00000001094f5724 mono`main + 1860
>     frame #16: 0x00000001094f4fd4 mono`start + 52
> 
>   thread #2, name = 'SGen worker'
>     frame #0: 0x0000000109beebf2 libsystem_kernel.dylib`__psynch_cvwait + 10
>     frame #1: 0x0000000109d427fa libsystem_pthread.dylib`_pthread_cond_wait + 712
>     frame #2: 0x000000010977eacb mono`thread_func + 715
>     frame #3: 0x0000000109d4193b libsystem_pthread.dylib`_pthread_body + 180
>     frame #4: 0x0000000109d41887 libsystem_pthread.dylib`_pthread_start + 286
>     frame #5: 0x0000000109d4108d libsystem_pthread.dylib`thread_start + 13
> 
>   thread #3, name = 'SGen worker'
>     frame #0: 0x0000000109beebf2 libsystem_kernel.dylib`__psynch_cvwait + 10
>     frame #1: 0x0000000109d427fa libsystem_pthread.dylib`_pthread_cond_wait + 712
>     frame #2: 0x000000010977eaae mono`thread_func + 686
>     frame #3: 0x0000000109d4193b libsystem_pthread.dylib`_pthread_body + 180
>     frame #4: 0x0000000109d41887 libsystem_pthread.dylib`_pthread_start + 286
>     frame #5: 0x0000000109d4108d libsystem_pthread.dylib`thread_start + 13
> (lldb) detach
> 
> =================================================================
> 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.
> =================================================================
> 
> Process 54663 detached
> (lldb) quit

Thank you very much for the very easy repro!
Comment 2 Zoltan Varga 2017-07-24 02:17:06 UTC
https://github.com/mono/mono/pull/5256

Thanks for the testcase.
Comment 3 ken.krakman 2017-07-24 14:49:48 UTC
This is great news. Thanks!

I would be willing to try it out any time. I assume this would go into a weekly build soon?
Comment 4 Zoltan Varga 2017-07-24 18:22:05 UTC
A workaround would be to split the assembly in question into smaller ones.
Comment 6 Zoltan Varga 2017-07-25 08:38:39 UTC
Err, if you are on ubuntu, try these packages:
http://www.mono-project.com/docs/getting-started/install/linux/ci-packages/#debian-ubuntu-and-derivatives
Comment 7 ken.krakman 2017-07-25 12:43:06 UTC
I believe I followed the directions to install the latest build.
I eventually executed:

 . mono-snapshot mono 

This is what the --version shows:

mono --version
Mono JIT compiler version 5.5.0 (tarball Tue Jul 25 10:20:22 UTC 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen (concurrent by default)


But I still get the assert:

* Assertion at metadata.c:1048, condition `index < meta->heap_strings.size' not met


when executing the test program. :(
Did it not make it in yet?

Thanks again
Comment 8 Zoltan Varga 2017-07-25 16:23:23 UTC
Not sure what is happening, the fix is:
https://github.com/mono/mono/commit/3daaa4d39c84f64b59cd177208978f0467e92610
So its definitely in git, but it might not made it into the snapshot packages yet, not sure how/when does are generated.
Comment 9 ken.krakman 2017-07-25 16:29:10 UTC
My mistake. I didn't realize there are now two different mono installations on my system. I was running the old one. With the new one, it works!
Comment 10 Zoltan Varga 2017-07-25 17:18:18 UTC
-> FIXED.

Note You need to log in before you can comment on or make changes to this bug.