Bug 42417 - Mono's System.Reflection crash when fsharp compiler is called by fsharpi
Summary: Mono's System.Reflection crash when fsharp compiler is called by fsharpi
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: master
Hardware: PC Linux
: Normal normal
Target Milestone: Future Cycle (TBD)
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2016-07-08 04:10 UTC by Andres G. Aragoneses
Modified: 2017-08-17 20:06 UTC (History)
2 users (show)

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


Attachments
"SomeModule" required to reproduce the bug (minimal testcase) (329 bytes, text/plain)
2016-07-08 04:10 UTC, Andres G. Aragoneses
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 Andres G. Aragoneses 2016-07-08 04:10:41 UTC
Created attachment 16609 [details]
"SomeModule" required to reproduce the bug (minimal testcase)

$ mono --version
Mono JIT compiler version 4.2.1 (Debian 4.2.1.102+dfsg2-7ubuntu4)
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


$ cat mono421bug.fsx
#!/usr/bin/env fsharpi

open System

#load "SomeModule.fs"
open SomeNamespace

SomeModule.LaunchBug()

$ ./mono421bug.fsx
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0xffffffff>
  at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000a1>
  at System.RuntimeType.InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,string[]) <0x00f06>
  at System.Reflection.Emit.TypeBuilder.InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,string[]) <0x00069>
  at System.Type.InvokeMember (string,System.Reflection.BindingFlags,System.Reflection.Binder,object,object[],System.Globalization.CultureInfo) <0x0005e>
  at Microsoft.FSharp.Compiler.AbstractIL.ILRuntimeWriter/execEntryPtFun@1980-1.Invoke (Microsoft.FSharp.Core.Unit) <0x0009e>
  at Microsoft.FSharp.Compiler.Interactive.Shell/clo@890-37.Invoke (Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit, Microsoft.FSharp.Core.FSharpOption`1<System.Exception>>) <0x00022>
  at Microsoft.FSharp.Primitives.Basics.List.iter<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T_REF>) <0x00047>
  at Microsoft.FSharp.Collections.ListModule.Iterate<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, Microsoft.FSharp.Core.Unit>,Microsoft.FSharp.Collections.FSharpList`1<T_REF>) <0x0002f>
  at Microsoft.FSharp.Compiler.Interactive.Shell.arg10@889 (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit, Microsoft.FSharp.Core.FSharpOption`1<System.Exception>>>,Microsoft.FSharp.Core.Unit) <0x0006f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler.ProcessInputs (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/ParsedInput>,bool,bool,bool,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/Ident>) <0x00747>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompiler.EvalParsedDefinitions (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,bool,bool,Microsoft.FSharp.Collections.FSharpList`1<Microsoft.FSharp.Compiler.Ast/SynModuleDecl>) <0x00207>
  at Microsoft.FSharp.Compiler.Interactive.Shell/clo@1607-45.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x0192b>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.InteractiveCatch<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, System.Tuple`2<T_REF, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>,T_REF) <0x00050>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.ExecInteraction (bool,Microsoft.FSharp.Compiler.CompileOps/TcConfig,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction) <0x00073>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.ExecInteractions (bool,Microsoft.FSharp.Compiler.CompileOps/TcConfig,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Core.FSharpOption`1<Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction>) <0x00a6b>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.MainThreadProcessParsedInteraction (bool,Microsoft.FSharp.Core.FSharpOption`1<Microsoft.FSharp.Compiler.Ast/ParsedFsiInteraction>,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x0019f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/res@1820.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x0002f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/run@1837-1.Invoke (Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState, System.Tuple`2<Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x0001d>
  at Microsoft.FSharp.Core.OptimizedClosures/Invoke@3252<T1_REF, T2_REF, TResult_REF>.Invoke (T1_REF) <0x00029>
  at Microsoft.FSharp.Compiler.Interactive.Shell/ParseAndProcessAndEvalOneInteractionFromLexbuf@1809.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x001d8>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.InteractiveCatch<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, System.Tuple`2<T_REF, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>,T_REF) <0x00050>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.ParseAndProcessAndEvalOneInteractionFromLexbuf (bool,Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState, System.Tuple`2<Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>, Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState, System.Tuple`2<Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>>,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Compiler.LexFilter/LexFilter) <0x00173>
  at Microsoft.FSharp.Compiler.Interactive.Shell.run@1836 (Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor,bool,Microsoft.FSharp.Compiler.LexFilter/LexFilter,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x0006f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/EvalIncludedScript@1832.Invoke (Microsoft.FSharp.Core.Unit) <0x00047>
  at Microsoft.FSharp.Compiler.Interactive.Shell.WithImplicitHome<T_REF> (Microsoft.FSharp.Compiler.CompileOps/TcConfigBuilder,string,Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit, T_REF>) <0x0004a>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.EvalIncludedScript (bool,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,string,Microsoft.FSharp.Compiler.Range/range) <0x000bf>
  at Microsoft.FSharp.Compiler.Interactive.Shell/EvalIncludedScripts@1856.Invoke (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x00043>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.InteractiveCatch<T_REF> (Microsoft.FSharp.Core.FSharpFunc`2<T_REF, System.Tuple`2<T_REF, Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionStepStatus>>,T_REF) <0x00050>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.EvalIncludedScripts (Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,bool,Microsoft.FSharp.Collections.FSharpList`1<string>) <0x00093>
  at Microsoft.FSharp.Compiler.Interactive.Shell.consume@1866 (Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor,bool,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState,Microsoft.FSharp.Collections.FSharpList`1<System.Tuple`2<string, bool>>) <0x000fb>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiInteractionProcessor.LoadInitialFiles (bool,Microsoft.FSharp.Compiler.Interactive.Shell/FsiDynamicCompilerState) <0x0002f>
  at Microsoft.FSharp.Compiler.Interactive.Shell/FsiEvaluationSession.Run () <0x00ecb>
  at Microsoft.FSharp.Compiler.Interactive.Shell.evaluateSession@2421 (string[],Microsoft.FSharp.Core.Unit) <0x000cb>
  at Microsoft.FSharp.Compiler.Interactive.Shell.MainMain (string[]) <0x0017f>
  at Microsoft.FSharp.Compiler.Interactive.Main.FsiMain (string[]) <0x0000f>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

	cli() [0x49ff2f]
	cli() [0x4f390e]
	cli() [0x426c19]
	/lib/x86_64-linux-gnu/libpthread.so.0(+0x113d0) [0x7f15683763d0]
	cli(mono_object_isinst+0x26) [0x5afd46]
	cli() [0x4f2ad9]
	[0x41801603]

Debug info from gdb:

[New LWP 5638]
[New LWP 5637]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f1568375fbb in __waitpid (pid=5639, stat_loc=0x7f1568eac00c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
29	../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
  Id   Target Id         Frame 
* 1    Thread 0x7f1568e99780 (LWP 5635) "cli" 0x00007f1568375fbb in __waitpid (pid=5639, stat_loc=0x7f1568eac00c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
  2    Thread 0x7f1564f15700 (LWP 5638) "Finalizer" 0x00007f1568374867 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=0, futex_word=0x956820) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
  3    Thread 0x7f1566fff700 (LWP 5637) "cli" pthread_cond_wait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185

Thread 3 (Thread 0x7f1566fff700 (LWP 5637)):
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00000000005fdcdb in ?? ()
#2  0x00007f156836c6fa in start_thread (arg=0x7f1566fff700) at pthread_create.c:333
#3  0x00007f15680a2b5d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 2 (Thread 0x7f1564f15700 (LWP 5638)):
#0  0x00007f1568374867 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=0, futex_word=0x956820) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
#1  do_futex_wait (sem=sem@entry=0x956820, abstime=0x0) at sem_waitcommon.c:111
#2  0x00007f1568374914 in __new_sem_wait_slow (sem=0x956820, abstime=0x0) at sem_waitcommon.c:181
#3  0x00007f15683749ba in __new_sem_wait (sem=<optimized out>) at sem_wait.c:29
#4  0x0000000000622e06 in mono_sem_wait ()
#5  0x00000000005a5742 in ?? ()
#6  0x0000000000587b2b in ?? ()
#7  0x0000000000629a8c in ?? ()
#8  0x00007f156836c6fa in start_thread (arg=0x7f1564f15700) at pthread_create.c:333
#9  0x00007f15680a2b5d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 1 (Thread 0x7f1568e99780 (LWP 5635)):
#0  0x00007f1568375fbb in __waitpid (pid=5639, stat_loc=0x7f1568eac00c, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00000000004a0006 in ?? ()
#2  0x00000000004f390e in ?? ()
#3  0x0000000000426c19 in ?? ()
#4  <signal handler called>
#5  0x00000000005afd46 in mono_object_isinst ()
#6  0x00000000004f2ad9 in ?? ()
#7  0x0000000041801603 in ?? ()
#8  0x00007ffc9b184f60 in ?? ()
#9  0x0000000000000001 in ?? ()
#10 0x0000000000000000 in ?? ()

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Aborted (core dumped)



(Attached the minimal testcase file SomeModule.fs)
Comment 1 Rodrigo Kumpera 2016-07-21 05:34:00 UTC
This still happens with mono 4.6.0 and I can repro with the OSX desktop package.
Comment 2 Rodrigo Kumpera 2016-07-21 06:52:42 UTC
Looks like we got multiple bugs here.

The hard crash was due the following IL being generated:

ldc_i4_1
throw

Fixing that to properly fail to verify the method was easy, this leaves us to figure out whether the generation of broken IL is a fsharp or mono bug.
Comment 3 Rodrigo Kumpera 2016-07-21 06:59:15 UTC
First part of the fix.

https://github.com/mono/mono/pull/3312
Comment 4 Rodrigo Kumpera 2017-08-17 20:06:56 UTC
This now works as expected. It fails with:

SomeModule.fs(7,19): error FS0039: The value or constructor 'baz' is not defined.