From 3d432e41b3c3b261ebf2ac02b9bab18a59cec4c2 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 5 Apr 2017 21:51:32 -0400 Subject: [PATCH] [mono-runtimes] `cross-arm64.exe` must be a 64-bit app Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=54353 When using `mono` as an AOT cross-compiler, mono's "bitness" needs to match the "bitness" of the target ABI. For example, to generate AOT native code for 32-bit armeabi, the "host" `mono` needs to run in a 32-bit process. Similarly, to generate AOT native code for 64-bit aarch64-v8a ("arm64-v8a"), the "host" `mono` needs to run in a 64-bit process. Unfortunately...that wasn't the case: $ file bin/Debug/lib/mandroid/cross-arm64.exe bin/Debug/lib/mandroid/cross-arm64.exe: PE32 executable (console) Intel 80386, for MS Windows The result is that when attempting to generate AOT native libraries for arm64 *on Windows*, it would fail: $ xbuild /p:Configuration=Release /p:AndroidSupportedAbis=arm64-v8a /p:AotAssemblies=True /t:SignAndroidPackage Project.csproj ... [aot-compiler stderr] Can't cross-compile on 32-bit platforms to 64-bit architecture. (It would work on macOS, as `bin/Debug/bin/cross-arm64` is a 64-bit executable, as is required.) The fix is to correct the `@(_MonoCrossRuntime)` value for `cross-arm64-win` so that it used the `$(MingwCommandPrefix64)`-related values, *not* the `$(MingwCommandPrefix32)`-related values. This ensures that we use compiler settings to generate 64-bit binaries, resolving the error: $ file bin/Debug/lib/mandroid/cross-arm64.exe bin/Debug/lib/mandroid/cross-arm64.exe: PE32+ executable (console) x86-64, for MS Windows --- For the d15-2 branch, also apply a subset of commits dfea9756 and a08cd80a so that the `bundle.zip` contents are consistent. --- build-tools/bundle/bundle-path.targets | 2 +- .../mono-runtimes/mono-runtimes.projitems | 20 +++++++++---------- .../mono-runtimes/mono-runtimes.targets | 13 +++++++++++- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/build-tools/bundle/bundle-path.targets b/build-tools/bundle/bundle-path.targets index da7bd24e0fa..4c225c8a28e 100644 --- a/build-tools/bundle/bundle-path.targets +++ b/build-tools/bundle/bundle-path.targets @@ -24,7 +24,7 @@ - bundle-v14-$(Configuration)-$(HostOS)-libzip=$(_LibZipHash),llvm=$(_LlvmHash),mono=$(_MonoHash).zip + bundle-v16-$(Configuration)-$(HostOS)-libzip=$(_LibZipHash),llvm=$(_LlvmHash),mono=$(_MonoHash).zip diff --git a/build-tools/mono-runtimes/mono-runtimes.projitems b/build-tools/mono-runtimes/mono-runtimes.projitems index f74e013c95b..13ebc6e384d 100644 --- a/build-tools/mono-runtimes/mono-runtimes.projitems +++ b/build-tools/mono-runtimes/mono-runtimes.projitems @@ -393,23 +393,23 @@ <_MonoCrossRuntime Include="cross-arm64-win" Condition="$(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-arm64:'))"> arm64-v8a - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-ar - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-as - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-gcc + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-ar + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-as + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-gcc $(_CrossCFlagsWin) -static -static-libgcc - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-g++ - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-cpp + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-g++ + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-cpp $(_CrossCXXFlagsWin) -static -static-libgcc - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-ld + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-ld -static -static-libgcc -static-libstdc++ - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-ranlib - $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-strip + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-ranlib + $(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-strip -S aarch64-v8a-linux-android - --target=aarch64-v8a-linux-android --host="$(_CrossConfigureBuildHostWin32)" --cache-file=$(_CrossConfigureCachePrefix)arm64-win.config.cache --with-cross-offsets=aarch64-v8a-linux-android.h $(_CrossConfigureFlags) --with-llvm=$(_LlvmPrefixWin32) + --target=aarch64-v8a-linux-android --host="$(_CrossConfigureBuildHostWin64)" --cache-file=$(_CrossConfigureCachePrefix)arm64-win.config.cache --with-cross-offsets=aarch64-v8a-linux-android.h $(_CrossConfigureFlags) --with-llvm=$(_LlvmPrefixWin64) .exe PATH="$(AndroidMxeFullPath)\bin:$(PATH)" - $(_LlvmConfigureEnvironmentWin32) + $(_LlvmConfigureEnvironmentWin64) lib/mandroid/ cross-arm64 diff --git a/build-tools/mono-runtimes/mono-runtimes.targets b/build-tools/mono-runtimes/mono-runtimes.targets index 70db99465aa..311c2d9c2fa 100644 --- a/build-tools/mono-runtimes/mono-runtimes.targets +++ b/build-tools/mono-runtimes/mono-runtimes.targets @@ -331,7 +331,7 @@ DestinationFiles="@(_InstallUnstrippedRuntimeOutput)" /> @@ -546,6 +546,14 @@ SourceFiles="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\mono\mini\mono-sgen%(_MonoCrossRuntime.ExeSuffix)" DestinationFiles="$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)" /> + + @@ -571,6 +579,9 @@ +