Bug 58421 - sre-save.c asserts in fixup_method () if TypeBuilder token is used across assemblies
Summary: sre-save.c asserts in fixup_method () if TypeBuilder token is used across ass...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection (show other bugs)
Version: 5.0 (2017-02)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Aleksey Kliger
URL:
Depends on:
Blocks:
 
Reported: 2017-07-26 21:40 UTC by Aleksey Kliger
Modified: 2017-07-28 16:04 UTC (History)
1 user (show)

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


Attachments
Reproduction example (1.75 KB, text/plain)
2017-07-26 21:40 UTC, Aleksey Kliger
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 GitHub or Developer Community 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 FIXED

Description Aleksey Kliger 2017-07-26 21:40:11 UTC
Created attachment 23827 [details]
Reproduction example

If I have two TypeBuilders in two different AssemblyBuilders, referring to the token of one TypeBuilder from the other causes mono to assert when calling ModuleBuilder.Save().

mono --version
Mono JIT compiler version 5.0.0.36 (2017-02/f342dae Mon Apr  3 15:06:03 EDT 2017)

(Other versions newer than 4.8.0 fail too)

Expected result:
  Asm1.dll and Asm2.dll are created on disk.

Actual results:
got unexpected table 0x01 in fixup
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Reflection.Emit.ModuleBuilder.build_metadata (System.Reflection.Emit.ModuleBuilder) <0x00012>
  at System.Reflection.Emit.ModuleBuilder.Save () [0x001ad] in <164469fa6d844a078126fd8006807335>:0
  at System.Reflection.Emit.AssemblyBuilder.Save (string,System.Reflection.PortableExecutableKinds,System.Reflection.ImageFileMachine) [0x0022b] in <164469fa6d844a078126fd8006807335>:0
  at System.Reflection.Emit.AssemblyBuilder.Save (string) [0x00000] in <164469fa6d844a078126fd8006807335>:0
  at TestILGenerator.Main () [0x000b1] in <e093840c76fd4dd6a6ce4a92703e82fc>:0
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) [0x0004c] in <164469fa6d844a078126fd8006807335>:0

Native stacktrace:

	0   mono                                0x001100f4 mono_handle_native_crash + 324
	1   mono                                0x0016ff33 sigabrt_signal_handler + 147
	2   libsystem_platform.dylib            0xa1733e5b _sigtramp + 43
	3   ???                                 0xffffffff 0x0 + 4294967295
	4   libsystem_c.dylib                   0xa15b9a34 abort + 141
	5   mono                                0x002ef5dc mono_log_write_logfile + 380
	6   mono                                0x002e9e42 structured_log_adapter + 50
	7   mono                                0x00307f3a monoeg_g_log + 106
	8   mono                                0x00288801 fixup_method + 1025
	9   mono                                0x002684f2 mono_g_hash_table_foreach + 114
	10  mono                                0x002875a9 mono_image_build_metadata + 8409
	11  mono                                0x0027fe69 ves_icall_ModuleBuilder_build_metadata + 25
	12  ???                                 0x0054cde4 0x0 + 5557732
	13  mscorlib.dll.dylib                  0x01a78401 System_Reflection_Emit_ModuleBuilder_Save + 1457
	14  mscorlib.dll.dylib                  0x01a5b790 System_Reflection_Emit_AssemblyBuilder_Save_string_System_Reflection_PortableExecutableKinds_System_Reflection_ImageFileMachine + 1552
	15  mscorlib.dll.dylib                  0x01a5b905 System_Reflection_Emit_AssemblyBuilder_Save_string + 53
	16  ???                                 0x005474c8 0x0 + 5534920
	17  ???                                 0x005475e7 0x0 + 5535207
	18  mono                                0x000564b5 mono_jit_runtime_invoke + 1557
	19  mono                                0x0026da80 do_runtime_invoke + 96
	20  mono                                0x00271337 do_exec_main_checked + 151
	21  mono                                0x00270009 mono_runtime_run_main_checked + 73
	22  mono                                0x000d1787 mono_jit_exec + 311
	23  mono                                0x000d40f2 mono_main + 9410
	24  mono                                0x0004585b main + 2011
	25  mono                                0x00045075 start + 53

Debug info from gdb:

(lldb) command source -s 0 '/tmp/mono-gdb-commands.KUHOU8'
Executing commands in '/tmp/mono-gdb-commands.KUHOU8'.
(lldb) process attach --pid 59701
warning: (i386) /Library/Frameworks/Mono.framework/Versions/5.0.0/lib/mono/4.5/mscorlib.dll.dylib empty dSYM file detected, dSYM was created with an executable with no debug info.
Process 59701 stopped
* thread #1, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0xa1659c4a libsystem_kernel.dylib`__wait4 + 10
libsystem_kernel.dylib`__wait4:
->  0xa1659c4a <+10>: jae    0xa1659c5a                ; <+26>
    0xa1659c4c <+12>: calll  0xa1659c51                ; <+17>
    0xa1659c51 <+17>: popl   %edx
    0xa1659c52 <+18>: movl   0x58d53d7(%edx), %edx

Executable module set to "/Library/Frameworks/Mono.framework/Versions/5.0.0/bin/mono".
Architecture set to: i386-apple-macosx.
(lldb) thread list
Process 59701 stopped
* thread #1: tid = 0x1f47b5a, 0xa1659c4a libsystem_kernel.dylib`__wait4 + 10, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  thread #2: tid = 0x1f47b5b, 0xa165930e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
  thread #3: tid = 0x1f47b5c, 0xa165195a libsystem_kernel.dylib`semaphore_wait_trap + 10, name = 'Finalizer'
  thread #4: tid = 0x1f47b5d, 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10
  thread #5: tid = 0x1f47b5e, 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10
  thread #6: tid = 0x1f47b5f, 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10
(lldb) thread backtrace all
* thread #1, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0xa1659c4a libsystem_kernel.dylib`__wait4 + 10
    frame #1: 0xa15d82ef libsystem_c.dylib`waitpid$UNIX2003 + 32
    frame #2: 0x001101c7 mono`mono_handle_native_crash(signal=<unavailable>, ctx=0xbffbcd0c, info=0xbffbcccc) at mini-exceptions.c:2567 [opt]
    frame #3: 0x0016ff33 mono`sigabrt_signal_handler(_dummy=<unavailable>, _info=<unavailable>, context=<unavailable>) at mini-posix.c:208 [opt]

  thread #2, name = 'SGen worker'
    frame #0: 0xa165930e libsystem_kernel.dylib`__psynch_cvwait + 10
    frame #1: 0xa173deb0 libsystem_pthread.dylib`_pthread_cond_wait + 647
    frame #2: 0xa173f844 libsystem_pthread.dylib`pthread_cond_wait$UNIX2003 + 51
    frame #3: 0x002e61f1 mono`thread_func [inlined] mono_os_cond_wait(mutex=0x003dbc94) at mono-os-mutex.h:146 [opt]
    frame #4: 0x002e61df mono`thread_func(thread_data=0x00000000) at sgen-thread-pool.c:129 [opt]
    frame #5: 0xa173d047 libsystem_pthread.dylib`_pthread_body + 184
    frame #6: 0xa173cf8f libsystem_pthread.dylib`_pthread_start + 243
    frame #7: 0xa173c84a libsystem_pthread.dylib`thread_start + 34

  thread #3, name = 'Finalizer'
    frame #0: 0xa165195a libsystem_kernel.dylib`semaphore_wait_trap + 10
    frame #1: 0x00265fe6 mono`finalizer_thread [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_ALERTABLE) at mono-os-semaphore.h:90 [opt]
    frame #2: 0x00265fd8 mono`finalizer_thread [inlined] mono_coop_sem_wait(flags=MONO_SEM_FLAGS_ALERTABLE) at mono-coop-semaphore.h:40 [opt]
    frame #3: 0x00265fce mono`finalizer_thread(unused=0x00000000) at gc.c:907 [opt]
    frame #4: 0x002363b4 mono`start_wrapper [inlined] start_wrapper_internal at threads.c:837 [opt]
    frame #5: 0x00236272 mono`start_wrapper(data=<unavailable>) at threads.c:889 [opt]
    frame #6: 0x002fcce0 mono`inner_start_thread(data=<unavailable>) at mono-threads.c:1170 [opt]
    frame #7: 0xa173d047 libsystem_pthread.dylib`_pthread_body + 184
    frame #8: 0xa173cf8f libsystem_pthread.dylib`_pthread_start + 243
    frame #9: 0xa173c84a libsystem_pthread.dylib`thread_start + 34

  thread #4
    frame #0: 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0xa173cb95 libsystem_pthread.dylib`_pthread_wqthread + 841
    frame #2: 0xa173c826 libsystem_pthread.dylib`start_wqthread + 34

  thread #5
    frame #0: 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0xa173cd06 libsystem_pthread.dylib`_pthread_wqthread + 1210
    frame #2: 0xa173c826 libsystem_pthread.dylib`start_wqthread + 34

  thread #6
    frame #0: 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0xa173cd06 libsystem_pthread.dylib`_pthread_wqthread + 1210
    frame #2: 0xa173c826 libsystem_pthread.dylib`start_wqthread + 34
(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 59701 detached
(lldb) quit
Abort trap: 6