Bug 13916 - --full-aot and --aot=full causing stack overflow
Summary: --full-aot and --aot=full causing stack overflow
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-08-12 08:40 UTC by Urs Keller
Modified: 2013-11-01 11:30 UTC (History)
3 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 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 Urs Keller 2013-08-12 08:40:16 UTC
I was playing around with the aot feature. From the doc http://www.mono-project.com/AOT#Supported_Platforms it is unclear to me whether this is supposed to work on Mac.

mcs --version
Mono C# compiler version 3.2.0.0

mono --version
Mono JIT compiler version 3.2.0 ((no/7c7fcc7 Tue Jul 23 19:59:39 EDT 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.3svn-mono)
	GC:            sgen

uname -a
Darwin host.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May  1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64

Steps to reproduce:
- echo 'using System; public class MainClass { public static void Main() { Console.WriteLine("Hello World"); }}' > HW.cs
- mcs HW.cs
- sudo mono --llvm --aot=full /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll
- mono --llvm --aot=full HW.exe 
- mono --full-aot HW.exe 

Note 1: ommitting --llvm causes a similar behaviour.
Note 2: -Oall crashes with: Assertion at mini-x86.c:3182, condition `ins->dreg == MONO_ARCH_GOT_REG' not met

Expected result:
- printed "Hello World" on the console

Actual result:
-with --llvm: Stack overflow: IP: 0x2, fault addr: 0x2
-without --llvm: Stack overflow in unmanaged: IP: 0xbffa5558, fault addr: 0xbffa5558









-----
Output of commands:

sudo mono --llvm --aot=full /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll
Mono Ahead of Time compiler - compiling assembly /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll
Executing opt: opt -f -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -domfrontier -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -iv-users -indvars -loop-deletion -loop-simplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify -o temp.s.opt.bc temp.s.bc
Executing llc: llc  -asm-verbose=false -relocation-model=pic -disable-gnu-eh-frame -enable-mono-eh-frame -o temp.s temp.s.opt.bc
Code: 4399906 Info: 126693 Ex Info: 217853 Unwind Info: 103 Class Info: 79213 PLT: 10102 GOT Info: 143907 GOT: 85936 Offsets: 224763
Compiled: 24962/24970 (99%), LLVM: 0 (0%), No GOT slots: 14714 (58%), Direct calls: 32782 (79%)
8 methods have other problems (0%)
Executing the native assembler: as -arch i386 -W  -o temp.s.o temp.s
Executing the native linker: gcc -m32 -dynamiclib -o /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll.dylib.tmp temp.s.o
Generating debug symbols: dsymutil /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll.dylib
JIT time: 3821 ms, Generation time: 1944 ms, Assembly+Link time: 3729 ms.


sudo mono --llvm --aot=full HW.exe
Mono Ahead of Time compiler - compiling assembly /Users/ukeller/temp/HW.exe
Executing opt: opt -f -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -domfrontier -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -iv-users -indvars -loop-deletion -loop-simplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify -o temp.s.opt.bc temp.s.bc
Executing llc: llc  -asm-verbose=false -relocation-model=pic -disable-gnu-eh-frame -enable-mono-eh-frame -o temp.s temp.s.opt.bc
Code: 370 Info: 13 Ex Info: 46 Unwind Info: 17 Class Info: 22 PLT: 3 GOT Info: 57 GOT: 40 Offsets: 64
Compiled: 4/4 (100%), LLVM: 0 (0%), No GOT slots: 1 (25%), Direct calls: 0 (100%)
Executing the native assembler: as -arch i386 -W  -o temp.s.o temp.s
Executing the native linker: gcc -m32 -dynamiclib -o /Users/ukeller/temp/HW.exe.dylib.tmp temp.s.o
Generating debug symbols: dsymutil /Users/ukeller/temp/HW.exe.dylib
JIT time: 1 ms, Generation time: 27 ms, Assembly+Link time: 31 ms.


mono --full-aot HW.exe 
Stack overflow: IP: 0x2, fault addr: 0x2
Stacktrace:
  at <unknown> <0xffffffff>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) <0xffffffff>
  <...>
  at <unknown> <0xffffffff>
  at MainClass.Main () <0x00021>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>




sudo mono  --aot=full /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll
Mono Ahead of Time compiler - compiling assembly /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll
Code: 4399906 Info: 126686 Ex Info: 217853 Unwind Info: 103 Class Info: 79213 PLT: 6670 GOT Info: 122414 GOT: 72204 Offsets: 224762
Compiled: 24962/24970 (99%), No GOT slots: 14714 (58%), Direct calls: 32782 (79%)
8 methods have other problems (0%)
Executing the native assembler: as -arch i386 -W  -o /tmp/mono_aot_rRYxaq.o /tmp/mono_aot_rRYxaq
Executing the native linker: gcc -m32 -dynamiclib -o /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll.dylib.tmp /tmp/mono_aot_rRYxaq.o
Generating debug symbols: dsymutil /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/mscorlib.dll.dylib
JIT time: 1817 ms, Generation time: 1439 ms, Assembly+Link time: 3445 ms.


sudo mono --aot=full HW.exe
Mono Ahead of Time compiler - compiling assembly /Users/ukeller/temp/HW.exe
Code: 370 Info: 13 Ex Info: 46 Unwind Info: 17 Class Info: 22 PLT: 3 GOT Info: 56 GOT: 36 Offsets: 63
Compiled: 4/4 (100%), No GOT slots: 1 (25%), Direct calls: 0 (100%)
Executing the native assembler: as -arch i386 -W  -o /tmp/mono_aot_PitYR5.o /tmp/mono_aot_PitYR5
Executing the native linker: gcc -m32 -dynamiclib -o /Users/ukeller/temp/HW.exe.dylib.tmp /tmp/mono_aot_PitYR5.o
Generating debug symbols: dsymutil /Users/ukeller/temp/HW.exe.dylib
JIT time: 0 ms, Generation time: 0 ms, Assembly+Link time: 32 ms.


mono --full-aot HW.exe 
Stack overflow in unmanaged: IP: 0xbffa5558, fault addr: 0xbffa5558
Stack overflow in unmanaged: IP: 0xbffa5558, fault addr: 0xbffa5558
Stack overflow in unmanaged: IP: 0xbffa5558, fault addr: 0xbffa5558
....
Comment 1 Zoltan Varga 2013-08-12 14:31:44 UTC
--full-aot is only supported on ios in xamarin products.
Comment 2 Zoltan Varga 2013-08-29 23:17:20 UTC
This is probably caused by the usage of CEE_MONO_TLS in gc allocators which is not aot safe.
Comment 3 Zoltan Varga 2013-11-01 11:30:11 UTC
Fixed in master.