Skip to content

Commit f8c0dc8

Browse files
authored
[mono-runtimes] cross-arm64.exe must be a 64-bit app (#552)
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 dfea975 and a08cd80 so that the `bundle.zip` contents are consistent.
1 parent 3887dc9 commit f8c0dc8

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

build-tools/bundle/bundle-path.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<Target Name="GetBundleFileName"
2525
DependsOnTargets="_GetHashes">
2626
<PropertyGroup>
27-
<XABundleFileName>bundle-v14-$(Configuration)-$(HostOS)-libzip=$(_LibZipHash),llvm=$(_LlvmHash),mono=$(_MonoHash).zip</XABundleFileName>
27+
<XABundleFileName>bundle-v16-$(Configuration)-$(HostOS)-libzip=$(_LibZipHash),llvm=$(_LlvmHash),mono=$(_MonoHash).zip</XABundleFileName>
2828
</PropertyGroup>
2929
</Target>
3030
</Project>

build-tools/mono-runtimes/mono-runtimes.projitems

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -393,23 +393,23 @@
393393

394394
<_MonoCrossRuntime Include="cross-arm64-win" Condition="$(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-arm64:'))">
395395
<JitArch>arm64-v8a</JitArch>
396-
<Ar>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-ar</Ar>
397-
<As>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-as</As>
398-
<Cc>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-gcc</Cc>
396+
<Ar>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-ar</Ar>
397+
<As>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-as</As>
398+
<Cc>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-gcc</Cc>
399399
<CFlags>$(_CrossCFlagsWin) -static -static-libgcc</CFlags>
400-
<Cxx>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-g++</Cxx>
401-
<CxxCpp>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-cpp</CxxCpp>
400+
<Cxx>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-g++</Cxx>
401+
<CxxCpp>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-cpp</CxxCpp>
402402
<CxxFlags>$(_CrossCXXFlagsWin) -static -static-libgcc</CxxFlags>
403-
<Ld>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-ld</Ld>
403+
<Ld>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-ld</Ld>
404404
<LdFlags>-static -static-libgcc -static-libstdc++</LdFlags>
405-
<RanLib>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-ranlib</RanLib>
406-
<Strip>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix32)-strip</Strip>
405+
<RanLib>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-ranlib</RanLib>
406+
<Strip>$(AndroidMxeFullPath)\bin\$(MingwCommandPrefix64)-strip</Strip>
407407
<StripFlags>-S</StripFlags>
408408
<TargetAbi>aarch64-v8a-linux-android</TargetAbi>
409-
<ConfigureFlags>--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)</ConfigureFlags>
409+
<ConfigureFlags>--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)</ConfigureFlags>
410410
<ExeSuffix>.exe</ExeSuffix>
411411
<BuildEnvironment>PATH="$(AndroidMxeFullPath)\bin:$(PATH)"</BuildEnvironment>
412-
<ConfigureEnvironment>$(_LlvmConfigureEnvironmentWin32)</ConfigureEnvironment>
412+
<ConfigureEnvironment>$(_LlvmConfigureEnvironmentWin64)</ConfigureEnvironment>
413413
<InstallPath>lib/mandroid/</InstallPath>
414414
<CrossMonoName>cross-arm64</CrossMonoName>
415415
</_MonoCrossRuntime>

build-tools/mono-runtimes/mono-runtimes.targets

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
DestinationFiles="@(_InstallUnstrippedRuntimeOutput)"
332332
/>
333333
<Exec
334-
Condition=" '$(Configuration)' != 'Debug' And '%(_MonoRuntime.DoBuild)' == 'true' "
334+
Condition=" ('$(Configuration)' != 'Debug' Or '%(_MonoRuntime.NativeLibraryExtension)' == 'dll') And '%(_MonoRuntime.DoBuild)' == 'true' "
335335
Command="&quot;%(_MonoRuntime.Strip)&quot; %(_MonoRuntime.StripFlags) &quot;$(OutputPath)\lib\xbuild\Xamarin\Android\lib\%(_MonoRuntime.Identity)\%(_MonoRuntime.OutputRuntimeFilename).%(_MonoRuntime.NativeLibraryExtension)&quot;"
336336
/>
337337
<Touch Files="@(_InstallRuntimeOutput);@(_InstallUnstrippedRuntimeOutput)" />
@@ -546,6 +546,14 @@
546546
SourceFiles="$(IntermediateOutputPath)\%(_MonoCrossRuntime.Identity)\mono\mini\mono-sgen%(_MonoCrossRuntime.ExeSuffix)"
547547
DestinationFiles="$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)"
548548
/>
549+
<Copy
550+
SourceFiles="$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)"
551+
DestinationFiles="$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName).d%(_MonoCrossRuntime.ExeSuffix)"
552+
/>
553+
<Exec
554+
Condition=" '$(Configuration)' != 'Debug' Or '%(_MonoCrossRuntime.ExeSuffix)' == '.exe' "
555+
Command="&quot;%(_MonoCrossRuntime.Strip)&quot; %(_MonoCrossRuntime.StripFlags) &quot;$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)&quot;"
556+
/>
549557
<Touch
550558
Files="$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)"
551559
/>
@@ -571,6 +579,9 @@
571579
<BundleItem Include="@(_RuntimeEglibHeaderOutput)" />
572580
<BundleItem Include="@(_MonoConstsOutput)" />
573581
<BundleItem Include="@(_LlvmTargetBinary)" />
582+
<BundleItem Include="$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName).d%(_MonoCrossRuntime.ExeSuffix)"
583+
Condition=" '@(_MonoCrossRuntime)' != '' "
584+
/>
574585
<BundleItem Include="$(OutputPath)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)"
575586
Condition=" '@(_MonoCrossRuntime)' != '' "
576587
/>

0 commit comments

Comments
 (0)