Skip to content
This repository was archived by the owner on Dec 20, 2019. It is now read-only.

Conversation

@lateralusX
Copy link
Member

32-bit llc.exe build using i686-w64-mingw32-gcc/i686-w64-mingw32-g++ at least on version 5.3.1 and 5.4.0 triggers an optimization bug crashing the process. This was observed by Android team when running cross compiler targeting armv7-linux-gnueabi using LLVM 6.0. The MatchPhiSet call from
findCommon triggered an optimization resulting in incorrect stack pointer adjustment on return. That in turn caused an AV when reading the incorrect pointer from stack as representing NewPhiNodes stack variable.

The fix will reduce optimization around this function not triggering the optimization rules hitting the bug.

The same scenario have been tested on msvc VS 2015 32-bit/64-bit LLVM builds as well as x86_64-w64-mingw32-gcc/x86_64-w64-mingw32-g++ without reproducing so this problem seems to only be reproducing on 32-bit mingw build LLVM tools and that's the only build with identified incorrect stack pointer calculations.

32-bit llc.exe build using i686-w64-mingw32-gcc/i686-w64-mingw32-g++
at least on version 5.3.1 and 5.4.0 triggers an optimization bug crashing
the process. This was observed by Android team when running cross compiler
targeting armv7-linux-gnueabi using LLVM 6.0. The MatchPhiSet call from
findCommon triggered an optimization resulting in incorrect stack pointer
adjustment on return. That in turn caused an AV when reading the incorrect
pointer from stack representing NewPhiNodes stack variable.

The fix will reduce optimization around this function not triggering the
optimization rules hitting the bug.
@luhenry
Copy link

luhenry commented Nov 21, 2018

Could you please bump the version in xamarin-android:master to the tip of the release_60 branch? Thank you very much for fixing this bug! :)

@lateralusX
Copy link
Member Author

dotnet/android#2453

jonpryor pushed a commit to dotnet/android that referenced this pull request Nov 26, 2018
Fixes: #2290

Executing `llc.exe` on Windows would result in a crash:

	> msbuild TodoAzure.Droid.csproj /t:SignAndroidPackage /p:Configuration=Release /p:AotAssemblies=true /p:EnableLlvm=true
	...
	[aot-compiler stdout] Mono Ahead of Time compiler - compiling assembly C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets\PCLCrypto.dll (TaskId:288)
	[aot-compiler stdout] AOTID 5E31DBA6-D7C4-378F-663E-D6E8726A1DF9 (TaskId:288)
	[aot-compiler stdout] Executing opt: "C:\PROGRA~2\MICROS~1\2017\ENTERP~1\MSBuild\Xamarin\Android\opt" -f -O2 -disable-tail-calls -o "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp.opt.bc" "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp.bc" (TaskId:288)
	[AOT] MONO_PATH="C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets" MONO_ENV_OPTIONS="" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\cross-arm" --llvm --aot=outfile=C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\libaot-Xamarin.Android.Support.Animated.Vector.Drawable.dll.so,asmwriter,mtriple=armv7-linux-gnueabi,tool-prefix=C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\TOOLCH~1\ARM-LI~1.9\prebuilt\WINDOW~1\bin\arm-linux-androideabi-,ld-flags=C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\TOOLCH~1\ARM-LI~1.9\prebuilt\WINDOW~1\lib\gcc\ARM-LI~1\49696B~1.X\libgcc.a;C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\PLATFO~1\ANDROI~2\arch-arm\usr\lib\libc.so;C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\PLATFO~1\ANDROI~2\arch-arm\usr\lib\libm.so,llvm-path=C:\PROGRA~2\MICROS~1\2017\ENTERP~1\MSBuild\Xamarin\Android,temp-path=C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\Xamarin.Android.Support.Animated.Vector.Drawable.dll C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets\Xamarin.Android.Support.Animated.Vector.Drawable.dll (TaskId:288)
	[aot-compiler stdout] Executing llc: "C:\PROGRA~2\MICROS~1\2017\ENTERP~1\MSBuild\Xamarin\Android\llc"  -mattr=+vfp2,-neon,+d16 -asm-verbose=false -mtriple=armv7-linux-gnueabi -disable-gnu-eh-frame -enable-mono-eh-frame -mono-eh-frame-symbol=mono_aot_PCLCrypto_eh_frame -disable-tail-calls -relocation-model=pic -o "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp-llvm.s" "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp.opt.bc" (TaskId:288)
	[aot-compiler stderr] Wrote crash dump file "C:\Users\XAMARI~1\AppData\Local\Temp\llc.exe-b94cbe.dmp" (TaskId:288)
	[aot-compiler stderr] AOT of image C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets\PCLCrypto.dll failed. (TaskId:288)

The cause of the crash was due to a [mingw i686 optimization bug][0].

Bump to mono/llvm@349752c4 which *doesn't* optimize
`findCommon()`, thus fixing the crash.

[0]: mono/llvm#19
jonpryor pushed a commit to dotnet/android that referenced this pull request Nov 27, 2018
Fixes: #2290

Executing `llc.exe` on Windows would result in a crash:

	> msbuild TodoAzure.Droid.csproj /t:SignAndroidPackage /p:Configuration=Release /p:AotAssemblies=true /p:EnableLlvm=true
	...
	[aot-compiler stdout] Mono Ahead of Time compiler - compiling assembly C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets\PCLCrypto.dll (TaskId:288)
	[aot-compiler stdout] AOTID 5E31DBA6-D7C4-378F-663E-D6E8726A1DF9 (TaskId:288)
	[aot-compiler stdout] Executing opt: "C:\PROGRA~2\MICROS~1\2017\ENTERP~1\MSBuild\Xamarin\Android\opt" -f -O2 -disable-tail-calls -o "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp.opt.bc" "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp.bc" (TaskId:288)
	[AOT] MONO_PATH="C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets" MONO_ENV_OPTIONS="" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\cross-arm" --llvm --aot=outfile=C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\libaot-Xamarin.Android.Support.Animated.Vector.Drawable.dll.so,asmwriter,mtriple=armv7-linux-gnueabi,tool-prefix=C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\TOOLCH~1\ARM-LI~1.9\prebuilt\WINDOW~1\bin\arm-linux-androideabi-,ld-flags=C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\TOOLCH~1\ARM-LI~1.9\prebuilt\WINDOW~1\lib\gcc\ARM-LI~1\49696B~1.X\libgcc.a;C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\PLATFO~1\ANDROI~2\arch-arm\usr\lib\libc.so;C:\PROGRA~2\Android\ANDROI~2\NDK-BU~1\PLATFO~1\ANDROI~2\arch-arm\usr\lib\libm.so,llvm-path=C:\PROGRA~2\MICROS~1\2017\ENTERP~1\MSBuild\Xamarin\Android,temp-path=C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\Xamarin.Android.Support.Animated.Vector.Drawable.dll C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets\Xamarin.Android.Support.Animated.Vector.Drawable.dll (TaskId:288)
	[aot-compiler stdout] Executing llc: "C:\PROGRA~2\MICROS~1\2017\ENTERP~1\MSBuild\Xamarin\Android\llc"  -mattr=+vfp2,-neon,+d16 -asm-verbose=false -mtriple=armv7-linux-gnueabi -disable-gnu-eh-frame -enable-mono-eh-frame -mono-eh-frame-symbol=mono_aot_PCLCrypto_eh_frame -disable-tail-calls -relocation-model=pic -o "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp-llvm.s" "C:\agent\_work\r8\a\XAMARI~2\WEBSER~1\TO3284~1\Droid\obj\Release\81\aot\ARMEAB~1\PCLCrypto.dll\temp.opt.bc" (TaskId:288)
	[aot-compiler stderr] Wrote crash dump file "C:\Users\XAMARI~1\AppData\Local\Temp\llc.exe-b94cbe.dmp" (TaskId:288)
	[aot-compiler stderr] AOT of image C:\agent\_work\r8\a\xamarin-forms-samples\WebServices\TodoAzurePush\Droid\obj\Release\81\android\assets\PCLCrypto.dll failed. (TaskId:288)

The cause of the crash was due to a [mingw i686 optimization bug][0].

Bump to mono/llvm@349752c4 which *doesn't* optimize
`findCommon()`, thus fixing the crash.

[0]: mono/llvm#19
lambdageek added a commit to lambdageek/mono that referenced this pull request Mar 28, 2019
…90c85c8b7d

Pick up mono/llvm#19 to fix LLVM AOT crashes on
Windows.
marek-safar pushed a commit to mono/mono that referenced this pull request Mar 29, 2019
…90c85c8b7d

Pick up mono/llvm#19 to fix LLVM AOT crashes on
Windows.
vargaz pushed a commit that referenced this pull request Oct 1, 2019
32-bit llc.exe build using i686-w64-mingw32-gcc/i686-w64-mingw32-g++
at least on version 5.3.1 and 5.4.0 triggers an optimization bug crashing
the process. This was observed by Android team when running cross compiler
targeting armv7-linux-gnueabi using LLVM 6.0. The MatchPhiSet call from
findCommon triggered an optimization resulting in incorrect stack pointer
adjustment on return. That in turn caused an AV when reading the incorrect
pointer from stack representing NewPhiNodes stack variable.

The fix will reduce optimization around this function not triggering the
optimization rules hitting the bug.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants