From 3f1fbc6d97ad5c361c7f92eb03cd0b377112e86c Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 22 Nov 2024 11:45:17 +0100 Subject: [PATCH] Add architecture info to the 0141 warning Partial fix for https://github.com/dotnet/android/issues/9544 to make the warning more informative. Architecture information is necessary as the nuget in question might have the same library for various architectures. --- .../Properties/Resources.Designer.cs | 4 ++-- src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | 3 ++- src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index d689abddf20..2ac2c675867 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -522,7 +522,7 @@ public static string XA0140 { } /// - /// Looks up a localized string similar to NuGet package '{0}' version '{1}' contains a shared library '{2}' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details. + /// Looks up a localized string similar to NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details. /// public static string XA0141 { get { diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 5703c402b83..8ca40719558 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -1072,11 +1072,12 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS {1} - NuGet package version - NuGet package '{0}' version '{1}' contains a shared library '{2}' which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details + NuGet package '{0}' version '{1}' contains a shared library '{2}' ({3}) which is not correctly aligned. See https://developer.android.com/guide/practices/page-sizes for more details The following is a literal name and should not be translated: NuGet {0} - NuGet package id {1} - NuGet package version {2} - shared library file name +{3} - target architecture name diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs index 9bee404bb7c..fdea6441f8f 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ELFHelper.cs @@ -45,6 +45,12 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s throw new InvalidOperationException ($"Internal error: {elf} is not ELF"); } + string archName = elf.Machine switch { + Machine.AArch64 => "arm64-v8a", + Machine.AMD64 => "x86_64", + _ => throw new NotSupportedException ($"Internal error: ELF architecture {elf.Machine} is not supported") + }; + // We need to find all segments of Load type and make sure their alignment is as expected. foreach (ISegment segment in elf64.Segments) { if (segment.Type != SegmentType.Load) { @@ -66,7 +72,7 @@ static void AssertValidLibraryAlignment (TaskLoggingHelper log, uint pageSize, s log.LogDebugMessage ($" expected segment alignment of 0x{pageSize:x}, found 0x{segment64.Alignment:x}"); (string packageId, string packageVersion) = GetNugetPackageInfo (); - log.LogCodedWarning ("XA0141", Properties.Resources.XA0141, packageId, packageVersion, Path.GetFileName (path)); + log.LogCodedWarning ("XA0141", Properties.Resources.XA0141, packageId, packageVersion, Path.GetFileName (path), archName); break; }